Tool/software: Code Composer Studio
Hi
I wrote a simple program to calculate size, number of blocks and to write a pattern in 6KB of EEPROM memory.
I started with address 0x0. and go up to 96 blocks (0 to 05) and assume this will take care of writing to whole EEPROM. Printing to UART after reading back is too hard and makes the putty hang sometimes,
I want to view what has been written in EEPROM. How may I?
I am attaching the program
/******************************************************************************************************
* *********Basic Program for reading and writing to EEPROM*************************************
*/
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "inc/hw_ints.h"
#include "driverlib/gpio.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/eeprom.h"
#include "utils/uartstdio.h"
#include "drivers/pinout.h"
/**************************************************************************************
*
* Variables
*
* ************************************************************************************
*/
#define E2PROM_TEST_ADDRESS 0x0000
/*************************************************************************************************************
* main.c
**************************************************************************************************/
int main(void) {
uint32_t e2size,e2block;
uint32_t ui32SysClock;
uint32_t ui32EEPROMInit, ui32EEPROMStatus;
// Data Variables and address
uint32_t pui32Data[2];
uint32_t pui32Read[2];
//******************************SET CPU CLOCK AT 120 MHZ***********************************************************************************************//
// Run from the PLL at 120 MHz.
//
ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
SYSCTL_OSC_MAIN |
SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480), 120000000);
//******************************ENABLE SYSTEM CLOCK FOR ON BOARD LED***********************************************************************************************//
// Enable the GPIO port that is used for the on-board LED.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
// Check if the peripheral access is enabled.
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPION))
{
}
//
// Turn off the LED.
//
GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0x0);
// Enable the GPIO pin for the LED (PN0). Set the direction as output, and
// enable the GPIO pin for digital function.
GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0);
SysCtlDelay(20000);
// Turn on board LED
GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, GPIO_PIN_0);
//******************************INITIALIZE UART***********************************************************************************************//
/* EEPROM SETTINGS */
SysCtlPeripheralEnable(SYSCTL_PERIPH_EEPROM0); // EEPROM activate
//
// Wait for the EEPROM module to be ready.
//
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_EEPROM0))
{
}
// Wait for the EEPROM Initialization to complete
ui32EEPROMInit = EEPROMInit();
//
// Check if the EEPROM Initialization returned an error
// and inform the application
//
if(ui32EEPROMInit != EEPROM_INIT_OK)
{
while(1)
{
}
}
/* UART SETTINGS */
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
UARTStdioConfig(0, 115200, ui32SysClock);
/***************Main Action ****************/
UARTprintf("EEPROM Test Program \r\n");
e2size = EEPROMSizeGet(); // Get EEPROM Size
UARTprintf("EEPROM Size %d bytes\n", e2size);
e2block = EEPROMBlockCountGet(); // Get EEPROM Block Count
UARTprintf("EEPROM Block Count: %d\n", e2block);
//*** Test Section***********************************************/
// Program some data into the EEPROM at address 0x0000.
// Calculate size of EEPROM and number of Blocks in that size
pui32Data[0] = 0xFFFFFFFF;
pui32Data[1] = 0x00000000;
// wait for programming to be over
ui32EEPROMStatus = EEPROMProgram(pui32Data, 0x400, sizeof(pui32Data));
while (ui32EEPROMStatus == EEPROM_RC_WORKING){
}
UARTprintf("Data Written to EEPROM: %d\n", pui32Data);
//
// Read it back.
//Do not attempt to read if a write is in progress
if (ui32EEPROMStatus != EEPROM_RC_WRBUSY)
EEPROMRead(pui32Read, 0x400, sizeof(pui32Read));
UARTprintf("Data read from EEPROM: %d\n", pui32Read);
int i =0,j=0;
/********************************************************************************************************
// For whole EEPROM: Number of iterations = EEPROMSIZE/NUMBER OF EEPROMBLOCKS :j<(e2size/e2block)
// Calculation is as follows:
// inner loop always traverses each block
// Outer loop is responsible for correct offset into each block from start address
// First block: j=0l; so inner loop goes from 0 to 95 location
// Second iteration of inner loop :j is 1(outer loop) and so we traverse locations 96 onwards to 192..
**********************************************************************************************************/
for (j=0;j<(e2size/e2block);j++) {
for (i=0;i<e2block;i++) {
// One Block
// wait for write to complete
ui32EEPROMStatus = EEPROMProgram(pui32Data,(E2PROM_TEST_ADDRESS+i+j*e2block)
, sizeof(pui32Data));
while (ui32EEPROMStatus == EEPROM_RC_WORKING){
} // wait for current program to complete
//Do not attempt to read if a write is in progress
ui32EEPROMStatus = EEPROMStatusGet();
if (!ui32EEPROMStatus) // the EEDONE register is all zeroes if EEPROM is idle
EEPROMRead(pui32Read, (E2PROM_TEST_ADDRESS+i+j*e2block), sizeof(pui32Read));
// UARTprintf(" Block %d : Location:,%d", j,i);
// UARTprintf("Data read from EEPROM: %d\n", pui32Read);
// UARTFlushTx(1); // wait for data to be flushed
} // end inner loop for
UARTprintf("Done Block EEPROM: %d\n", j);
} // end out loop for
UARTprintf("Done Whole EEPROM:\n");
while (1)
{
}
return 0;
}