Part Number: TMS320F2800137
Tool/software:
i am using f2800137 board , i need to save some of variable values to flash, i am using flash api library functions to save values to flash memory of the device, i took one example code related to flash functions
( flashapi_ex1_programming ), i imported this file from the examples and changed the file as per my requirements. i just added two arrays ram_buffer_16( holds 16 bit ) & ram_buffer_8 ( holds 8 bit ).
in main.c file firstly i called init_eeporm() function [ my own function ], below steps are done in that function.
step 1 : i initialized elements in both arrays to zero.
step 2 : next i used Flash_initModule(FLASH0CTRL_BASE, FLASH0ECC_BASE, 2); api for flash module initialization.
step 3 : then i called eeprom_read_all() function
this function used to read the data's stored in flash, first it copy the datas from flash sectors and stored in ram_buffer_16( holds 16 bit ) array.
and then it copy data from ram_buffer_16( holds 16 bit ) array to ram_buffer_8 ( holds 8 bit ) bit array.
eeprom_read_all()
void eeprom_read_all(void)
{
uint16 *base_pointer = (uint16*) Bzero_Sector120_start;
uint16 count = 0X0, count1 = 0;
for (count = 0; count < 0X200; count++)
{
ram_data_buffer_16[count] = *(base_pointer + count);
}
for (count = 0,count1 = 0; count < (0X200 * 2U); count += 2,count1 += 1)
{
ram_data_buffer_8[count] = ram_data_buffer_16[count1] & 0XFF;
ram_data_buffer_8[count + 1u] = ((ram_data_buffer_16[count1] >> 8U)
& 0XFF);
}
}
after reading operation is complete i erased the flash sector.
erase_sector()
FUNCTION DEFANITION :
void Erase_Sector(void)
{
Fapi_StatusType oReturnCheck;
Fapi_FlashStatusType oFlashStatus;
Fapi_FlashStatusWordType oFlashStatusWord;
ClearFSMStatus();
// Enable program/erase protection for select sectors where this example is
// located
// CMDWEPROTA is applicable for sectors 0-31
// Bits 0-11 of CMDWEPROTB is applicable for sectors 32-127, each bit represents
// a group of 8 sectors, e.g bit 0 represents sectors 32-39, bit 1 represents
// sectors 40-47, etc
Fapi_setupBankSectorEnable(FLASH_WRAPPER_PROGRAM_BASE + FLASH_O_CMDWEPROTA,
0x13FFFF00);
Fapi_setupBankSectorEnable(FLASH_WRAPPER_PROGRAM_BASE + FLASH_O_CMDWEPROTB,
0x00000080);
//
// Erase the sector that is programmed in the above example
// Erase Sector 0
//
oReturnCheck = Fapi_issueAsyncCommandWithAddress(
Fapi_EraseSector, (uint32*) Bzero_Sector120_start);
//
// Wait until FSM is done with erase sector operation
//
while (Fapi_checkFsmForReady() != Fapi_Status_FsmReady)
{
}
if (oReturnCheck != Fapi_Status_Success)
{
//
// Check Flash API documentation for possible errors
//
Example_Error(oReturnCheck);
}
//
// Read FMSTAT register contents to know the status of FSM after
// erase command to see if there are any erase operation related errors
//
oFlashStatus = Fapi_getFsmStatus();
if (oFlashStatus != 3)
{
//
// Check Flash API documentation for FMSTAT and debug accordingly
// Fapi_getFsmStatus() function gives the FMSTAT register contents.
// Check to see if any of the EV bit, ESUSP bit, CSTAT bit or
// VOLTSTAT bit is set (Refer to API documentation for more details).
//
FMSTAT_Fail();
}
//
// Verify that Sector0 is erased
//
oReturnCheck = Fapi_doBlankCheck((uint32*) Bzero_Sector120_start,
Sector2KB_u32length,
&oFlashStatusWord);
if (oReturnCheck != Fapi_Status_Success)
{
//
// Check Flash API documentation for error info
//
Example_Error(oReturnCheck);
}
}
in next step i write some data"s to flash ( to 8bit ram array )

from 8 bit array it will store to ram_16_bit array and that 16 bit ram array pass through programusingautoECC()
Defanition of eeprom_write_all() attached below.
void eeprom_write_all(void)
{
Fapi_StatusType oReturnCheck;
//
// Initialize the Flash API by providing the Flash register base address
// and operating frequency(in MHz).
// This function is required to initialize the Flash API based on System
// frequency before any other Flash API operation can be performed.
// This function must also be called whenever System frequency or RWAIT is
// changed.
//
oReturnCheck = Fapi_initializeAPI(FlashTech_CPU0_BASE_ADDRESS,
DEVICE_SYSCLK_FREQ / 1000000U);
if (oReturnCheck != Fapi_Status_Success)
{
//
// Check Flash API documentation for possible errors
//
Example_Error(oReturnCheck);
}
//
// Initialize the Flash banks and FMC for erase and program operations.
// Fapi_setActiveFlashBank() function sets the Flash banks and FMC for
// further Flash operations to be performed on the banks.
//
oReturnCheck = Fapi_setActiveFlashBank(Fapi_FlashBank0);
if (oReturnCheck != Fapi_Status_Success)
{
//
// Check Flash API documentation for possible errors
//
Example_Error(oReturnCheck);
}
// Saving 8 bit array into 16 bit array.
uint16 i = 0u;
for (i = 0u; i < WORDS_IN_FLASH_BUFFER; i++)
{
ram_data_buffer_16[i] = (ram_data_buffer_8[i * 2U] & 0XFF)
| ((ram_data_buffer_8[(i * 2U) + 1U] << 8U) & 0XFF00);
}
//
// Program the sector using AutoECC option
//
// eeprom_write_auto_ecc(ram_data_buffer_16);
ProgramUsingAutoECC(ram_data_buffer_16);
}
from the o/p of the program we can see that flash memory stores data.

even after the power off, the flash retains the data.
later i integrated the same code to my application code , the flash reads and write operations works perfectly but the
supply is off , and then turn on the flash not retains the data.
for reference i attached the linker command file of my application code:
MEMORY
{
BEGIN : origin = 0x00080000, length = 0x00000002
BOOT_RSVD : origin = 0x00000002, length = 0x00000126
RAMM0 : origin = 0x00000128, length = 0x000002D8
RAMM1 : origin = 0x00000400, length = 0x000003F8
// RAMM1_RSVD : origin = 0x000007F8, length = 0x00000008 /* Reserve and do not use for code as per the errata advisory "Memory: Prefetching Beyond Valid Memory" */
RAMLS0 : origin = 0x00008000, length = 0x00002000
RAMLS1 : origin = 0x0000A000, length = 0x00001FF8
// RAMLS1_RSVD : origin = 0x0000BFF8, length = 0x00000008 /* Reserve and do not use for code as per the errata advisory "Memory: Prefetching Beyond Valid Memory" */
RESET : origin = 0x003FFFC0, length = 0x00000002
/* Flash sectors */
FLASH_BANK0_SEC_0_7 : origin = 0x080002, length = 0x1FFE /* on-chip Flash */
FLASH_BANK0_SEC_8_15 : origin = 0x082000, length = 0x2000 /* on-chip Flash */
FLASH_BANK0_SEC_16_23 : origin = 0x084000, length = 0x2000 /* on-chip Flash */
FLASH_BANK0_SEC_24_31 : origin = 0x086000, length = 0x2000 /* on-chip Flash */
FLASH_BANK0_SEC_32_39 : origin = 0x088000, length = 0x2000 /* on-chip Flash */
FLASH_BANK0_SEC_40_47 : origin = 0x08A000, length = 0x2000 /* on-chip Flash */
FLASH_BANK0_SEC_48_55 : origin = 0x08C000, length = 0x2000 /* on-chip Flash */
FLASH_BANK0_SEC_56_63 : origin = 0x08E000, length = 0x2000 /* on-chip Flash */
FLASH_BANK0_SEC_64_71 : origin = 0x090000, length = 0x2000 /* on-chip Flash */
FLASH_BANK0_SEC_72_79 : origin = 0x092000, length = 0x2000 /* on-chip Flash */
FLASH_BANK0_SEC_80_87 : origin = 0x094000, length = 0x2000 /* on-chip Flash */
FLASH_BANK0_SEC_88_95 : origin = 0x096000, length = 0x2000 /* on-chip Flash */
FLASH_BANK0_SEC_96_103 : origin = 0x098000, length = 0x2000 /* on-chip Flash */
FLASH_BANK0_SEC_104_111 : origin = 0x09A000, length = 0x2000 /* on-chip Flash */
FLASH_BANK0_SEC_112_119 : origin = 0x09C000, length = 0x2000 /* on-chip Flash */
FLASH_BANK0_SEC_120_127 : origin = 0x09E000, length = 0x1FF0 /* on-chip Flash */
// FLASH_BANK0_SEC_127_RSVD : origin = 0x0A0FF0, length = 0x0010 /* Reserve and do not use for code as per the errata advisory "Memory: Prefetching Beyond Valid Memory" */
}
SECTIONS
{
codestart : > BEGIN
.text : >> FLASH_BANK0_SEC_8_15 | FLASH_BANK0_SEC_16_23 | FLASH_BANK0_SEC_24_31 | FLASH_BANK0_SEC_40_47 | FLASH_BANK0_SEC_48_55, ALIGN(8)
.cinit : > FLASH_BANK0_SEC_0_7, ALIGN(8)
.switch : > FLASH_BANK0_SEC_0_7, ALIGN(8)
.reset : > RESET, TYPE = DSECT /* not used, */
.stack : > RAMM1
#if defined(__TI_EABI__)
.bss : > RAMLS0
.bss:output : > RAMLS0
.init_array : >> FLASH_BANK0_SEC_0_7, ALIGN(8)
.const : >> FLASH_BANK0_SEC_32_39, ALIGN(8)
.data : > RAMLS0 | RAMLS1
.sysmem : > RAMLS0
.bss:cio : > RAMLS0
#else
.pinit : >> FLASH_BANK0_SEC_0_7, ALIGN(8)
.ebss : > RAMLS0
.econst : >> FLASH_BANK0_SEC_32_39, ALIGN(8)
.esysmem : > RAMLS0
.cio : > RAMLS0
#endif
#if defined(__TI_EABI__)
.TI.ramfunc : LOAD = FLASH_BANK0_SEC_0_7,
RUN = RAMLS0,
LOAD_START(RamfuncsLoadStart),
LOAD_SIZE(RamfuncsLoadSize),
LOAD_END(RamfuncsLoadEnd),
RUN_START(RamfuncsRunStart),
RUN_SIZE(RamfuncsRunSize),
RUN_END(RamfuncsRunEnd),
ALIGN(8)
#else
.TI.ramfunc : LOAD = FLASH_BANK0_SEC_0_7,
RUN = RAMLS0,
LOAD_START(_RamfuncsLoadStart),
LOAD_SIZE(_RamfuncsLoadSize),
LOAD_END(_RamfuncsLoadEnd),
RUN_START(_RamfuncsRunStart),
RUN_SIZE(_RamfuncsRunSize),
RUN_END(_RamfuncsRunEnd),
ALIGN(8)
#endif
/* Allocate IQ math areas: */
IQmath : > FLASH_BANK0_SEC_32_39, ALIGN(8)
IQmathTables : > FLASH_BANK0_SEC_32_39, ALIGN(8)
}







