SPRUJ27C November   2022  – November 2023 TMS320F280033 , TMS320F280034 , TMS320F280034-Q1 , TMS320F280036-Q1 , TMS320F280036C-Q1 , TMS320F280037 , TMS320F280037-Q1 , TMS320F280037C , TMS320F280037C-Q1 , TMS320F280038-Q1 , TMS320F280038C-Q1 , TMS320F280039 , TMS320F280039-Q1 , TMS320F280039C , TMS320F280039C-Q1

 

  1.   1
  2.   Trademarks
  3. 1Introduction
    1. 1.1 Reference Material
    2. 1.2 Function Listing Format
  4. 2TMS320F28003x Flash API Overview
    1. 2.1 Introduction
    2. 2.2 API Overview
    3. 2.3 Using API
      1. 2.3.1 Initialization Flow
        1. 2.3.1.1 After Device Power Up
        2. 2.3.1.2 FMC and Bank Setup
        3. 2.3.1.3 On System Frequency Change
      2. 2.3.2 Building With the API
        1. 2.3.2.1 Object Library Files
        2. 2.3.2.2 Distribution Files
      3. 2.3.3 Key Facts For Flash API Usage
  5. 3API Functions
    1. 3.1 Initialization Functions
      1. 3.1.1 Fapi_initializeAPI()
    2. 3.2 Flash State Machine Functions
      1. 3.2.1 Fapi_setActiveFlashBank()
      2. 3.2.2 Fapi_issueAsyncCommandWithAddress()
      3. 3.2.3 Fapi_issueBankEraseCommand()
      4. 3.2.4 Fapi_issueProgrammingCommand()
      5. 3.2.5 Fapi_issueProgrammingCommandForEccAddresses()
      6. 3.2.6 Fapi_issueFsmSuspendCommand()
      7. 3.2.7 Fapi_issueAsyncCommand()
      8. 3.2.8 Fapi_checkFsmForReady()
      9. 3.2.9 Fapi_getFsmStatus()
    3. 3.3 Read Functions
      1. 3.3.1 Fapi_doBlankCheck()
      2. 3.3.2 Fapi_doVerify()
      3. 3.3.3 Fapi_calculatePsa()
      4. 3.3.4 Fapi_doPsaVerify()
    4. 3.4 Informational Functions
      1. 3.4.1 Fapi_getLibraryInfo()
    5. 3.5 Utility Functions
      1. 3.5.1 Fapi_flushPipeline()
      2. 3.5.2 Fapi_calculateEcc()
      3. 3.5.3 Fapi_isAddressEcc()
      4. 3.5.4 Fapi_remapEccAddress()
      5. 3.5.5 Fapi_calculateFletcherChecksum()
  6. 4Recommended FSM Flows
    1. 4.1 New Devices From Factory
    2. 4.2 Recommended Erase Flow
    3. 4.3 Recommended Bank Erase Flow
    4. 4.4 Recommended Program Flow
  7. 5Software Application Assumptions of Use Related to Safety
  8.   A Flash State Machine Commands
    1.     A.1 Flash State Machine Commands
  9.   B Compiler Version and Build Settings
  10.   C Object Library Function Information
    1.     C.1 TMS320F28003x Flash API Library
  11.   D Typedefs, Defines, Enumerations and Structures
    1.     D.1 Type Definitions
    2.     D.2 Defines
    3.     D.3 Enumerations
      1.      D.3.1 Fapi_FlashProgrammingCommandsType
      2.      D.3.2 Fapi_FlashBankType
      3.      D.3.3 Fapi_FlashStateCommandsType
      4.      D.3.4 Fapi_FlashReadMarginModeType
      5.      D.3.5 Fapi_StatusType
      6.      D.3.6 Fapi_ApiProductionStatusType
    4.     D.4 Structures
      1.      D.4.1 Fapi_FlashStatusWordType
      2.      D.4.2 Fapi_LibraryInfoType
  12.   E Parallel Signature Analysis (PSA) Algorithm
    1.     E.1 Function Details
  13.   F ECC Calculation Algorithm
    1.     F.1 Function Details
  14.   G Errata
  15.   Revision History

Fapi_issueProgrammingCommand()

Sets up data and issues program command to valid Flash or OTP memory addresses

Synopsis

Fapi_StatusType Fapi_issueProgrammingCommand(
         uint32 *pu32StartAddress,
         uint16 *pu16DataBuffer,
         uint16  u16DataBufferSizeInWords,
         uint16 *pu16EccBuffer,
         uint16  u16EccBufferSizeInBytes,
         Fapi_FlashProgrammingCommandType oMode)

Parameters

pu32StartAddress [in]Start address in Flash for the data and ECC to be programmed
pu16DataBuffer [in]Pointer to the Data buffer address. Data buffer should be 128-bit aligned.
u16DataBufferSizeInWords [in]Number of 16-bit words in the Data buffer
pu16EccBuffer [in]Pointer to the ECC buffer address
u16EccBufferSizeInBytes [in]Number of 8-bit bytes in the ECC buffer
oMode [in]Indicates the programming mode to use:
Fapi_DataOnlyPrograms only the data buffer
Fapi_AutoEccGenerationPrograms the data buffer and auto generates and programs the ECC.
Fapi_DataAndEccPrograms both the data and ECC buffers
Fapi_EccOnlyPrograms only the ECC buffer
Note: The pu16EccBuffer should contain ECC corresponding to the data at the 128-bit aligned main array/OTP address. The LSB of the pu16EccBuffer corresponds to the lower 64 bits of the main array and the MSB of the pu16EccBuffer corresponds to the upper 64 bits of the main array.

Description

This function sets up the programming registers of the Flash State Machine based on the supplied parameters. It offers four different programming modes to the user for use in different scenarios as mentioned in Table 3-1.

Table 3-1 Uses of Different Programming Modes
Programming Mode (oMode)Arguments UsedUsage Purpose
Fapi_DataOnlypu32StartAddress,
pu16DataBuffer,
u16DataBufferSizeInWords
Used when any custom programming utility or an user application (that embed/use Flash API) has to program data and corresponding ECC separately. Data is programmed using Fapi_DataOnly mode and then the ECC is programmed using Fapi_EccOnly mode. Generally most of the programming utilities do not calculate ECC separately and instead use Fapi_AutoEccGeneration mode. However, some Safety applications may require to insert intentional ECC errors in their Flash image (which is not possible when Fapi_AutoEccGeneration mode is used) to check the health of the SECDED (Single Error Correction and Double Error Detection) module at run time. In such case, ECC is calculated separately (using either the ECC calculation algorithm provided in Appendix F or using the Fapi_calculateEcc() function as applicable). Application may want to insert errors in either main array data or in the ECC as needed. In such scenarios, after the error insertion, Fapi_DataOnly mode and Fapi_EccOnly modes can be used to program the data and ECC respectively.
Fapi_AutoEccGenerationpu32StartAddress,
pu16DataBuffer,
u16DataBufferSizeInWords
Used when any custom programming utility or user application (that embed/use Flash API to program Flash at run time to store data or to do a firmware update) has to program data and ECC together without inserting any intentional errors. This is the most prominently used mode.
Fapi_DataAndEccpu32StartAddress,
pu16DataBuffer,
u16DataBufferSizeInWords,
pu16EccBuffer,
u16EccBufferSizeInBytes
Purpose of this mode is not different than that of using Fapi_DataOnly and Fapi_EccOnly modes together. However, this mode is beneficial when both the data and the calculated ECC can be programmed at the same time.
Fapi_EccOnlypu16EccBuffer,
u16EccBufferSizeInBytes
See the usage purpose given for Fapi_DataOnly mode.
Note: Users must always program ECC for their flash image since ECC check is enabled at power up.

Programming modes:

Fapi_DataOnly – This mode will only program the data portion in Flash at the address specified. It can program from 1-bit up to 8 16-bit words. However, review the restrictions provided for this function to know the limitations of flash programming data size. The supplied starting address to program at plus the data buffer length cannot cross the 128-bit aligned address boundary. Arguments 4 and 5 are ignored when using this mode.

Fapi_AutoEccGeneration – This mode will program the supplied data in Flash along with automatically generated ECC. The ECC is calculated for every 64-bit data aligned on a 64-bit memory boundary. Hence, when using this mode, all the 64 bits of the data should be programmed at the same time for a given 64-bit aligned memory address. Data not supplied is treated as all 1s (0xFFFF). Once ECC is calculated and programmed for a 64-bit data, those 64 bits can not be reprogrammed (unless the sector is erased) even if it is programming a bit from 1 to 0 in that 64-bit data, since the new ECC value will collide with the previously programmed ECC value. When using this mode, if the start address is 128-bit aligned, then either 8 or 4 16-bit words can be programmed at the same time as needed. If the start address is 64-bit aligned but not 128-bit aligned, then only 4 16-bit words can be programmed at the same time. The data restrictions for Fapi_DataOnly also exist for this option. Arguments 4 and 5 are ignored

Note: Fapi_AutoEccGeneration mode will program the supplied data portion in Flash along with automatically generated ECC. The ECC is calculated for 64-bit aligned address and the corresponding 64-bit data. Any data not supplied is treated as 0xFFFF. Note that there are practical implications of this when writing a custom programming utility that streams in the output file of a code project and programs the individual sections one at a time into flash. If a 64-bit word spans more than one section (that is, contains the end of one section, and the start of another), values of 0xFFFF cannot be assumed for the missing data in the 64-bit word when programming the first section. When you go to program the second section, you will not be able to program the ECC for the first 64-bit word since it was already (incorrectly) computed and programmed using assumed 0xFFFF for the missing values. One way to avoid this problem is to align all sections linked to flash on a 64-bit boundary in the linker command file for your code project.

Here is an example:

SECTIONS
   {  
     .text        : > FLASH, ALIGN(4)
     .cinit       : > FLASH, ALIGN(4)
     .const       : > FLASH, ALIGN(4)
     .init_array  : > FLASH, ALIGN(4)
     .switch      : > FLASH, ALIGN(4)
   }

If you do not align the sections in flash, you would need to track incomplete 64-bit words in a section and combine them with the words in other sections that complete the 64-bit word. This will be difficult to do. So it is recommended to align your sections on 64-bit boundaries.

Some 3rd party Flash programming tools or TI Flash programming kernel examples (C2000Ware) or any custom Flash programming solution may assume that the incoming data stream is all 128-bit aligned and may not expect that a section might start on an unaligned address. Thus it may try to program the maximum possible (128-bits) words at a time assuming that the address provided is 128-bit aligned. This can result in a failure when the address is not aligned. So, it is suggested to align all the sections (mapped to Flash) on a 128-bit boundary using ALIGN(8).

Fapi_DataAndEcc – This mode will program both the supplied data and ECC in Flash at the address specified. The data supplied must be aligned on a 64-bit memory boundary and the length of data must correlate to the supplied ECC. That means, if the data buffer length is 4 16-bit words, the ECC buffer must be 1 byte. If the data buffer length is 8 16-bit words, the ECC buffer must be 2 bytes in length. If the start address is 128-bit aligned, then either 8 or 4 16-bit words should be programmed at the same time as needed. If the start address is 64-bit aligned but not 128-bit aligned, then only 4 16-bit words should be programmed at the same time.

The LSB of pu16EccBuffer corresponds to the lower 64-bits of the main array and the MSB of pu16EccBuffer corresponds to the upper 64-bits of the main array.

The Fapi_calculateEcc() function can be used to calculate ECC for a given 64-bit aligned address and the corresponding data.

Fapi_EccOnly – This mode will only program the ECC portion in Flash ECC memory space at the address (Flash main array address should be provided for this function and not the corresponding ECC address) specified. It can program either 2 bytes (both LSB and MSB at a location in ECC memory) or 1 byte (LSB at a location in ECC memory).

The LSB of pu16EccBuffer corresponds to the lower 64-bits of the main array and the MSB of pu16EccBuffer corresponds to the upper 64-bits of the main array.

Arguments two and three are ignored when using this mode.

Note: The length of pu16DataBuffer and pu16EccBuffer cannot exceed 8 and 2, respectively.
Note: This function does not check FMSTAT after issuing the program command. The user application must check the FMSTAT value when FSM has completed the program operation. FMSTAT indicates if there is any failure occurrence during the program operation. The user application can use the Fapi_getFsmStatus function to obtain the FMSTAT value.

Also, the user application should use the Fapi_doVerify() function to verify that the Flash is programmed correctly.

This function does not wait until the program operation is over; it just issues the command and returns back. Hence, the user application must wait for the FMC to complete the program operation before returning to any kind of Flash accesses. The Fapi_checkFsmForReady() function should be used to monitor the status of an issued command.

Restrictions

  • As described above, this function can program only a max of 128-bits (given the address provided is 128-bit aligned) at a time. If the user wants to program more than that, this function should be called in a loop to program 128-bits (or 64-bits as needed by application) at a time.
  • The Main Array flash programming must be aligned to 64-bit address boundaries and each 64-bit word may only be programmed once per write or erase cycle.
  • It is alright to program the data and ECC separately. However, each 64-bit dataword and the corresponding ECC word may only be programmed once per write or erase cycle.
  • The DCSM OTP programming must be aligned to 128-bit address boundaries and each 128-bit word may only be programmed once. The exceptions are:
    • The DCSM Zx-LINKPOINTER1 and Zx-LINKPOINTER2 values in the DCSM OTP should be programmed together, and may be programmed 1 bit at a time as required by the DCSM operation.
    • The DCSM Zx-LINKPOINTER3 values in the DCSM OTP may be programmed 1 bit at a time as required by the DCSM operation.
  • ECC should not be programmed for linkpointer locations. The API will issue the Fapi_DataOnly command for these locations even if the user chooses Fapi_AutoEccGeneration mode or Fapi_DataAndEcc mode. Fapi_EccOnly mode is not supported for linkpointer locations.
  • Fapi_EccOnly mode should not be used for Bank0 DCSM OTP space. If used, an error will be returned. For the DCSM OTP space, either Fapi_AutoEccGeneration or Fapi_DataAndEcc programming modes should be used.

Return Value

  • Fapi_Status_Success (success)
  • Fapi_Error_InvalidBaseRegCntlAddress (failure: Flash control register base address provided by user does not match the expected address)
  • Fapi_Error_AsyncIncorrectDataBufferLength (failure: Data buffer size specified is incorrect. Also, this error will be returned if Fapi_EccOnly mode is selected when programming the Bank0 DCSM OTP space)
  • Fapi_Error_AsyncIncorrectEccBufferLength (failure: ECC buffer size specified is incorrect)
  • Fapi_Error_AsyncDataEccBufferLengthMismatch (failure: Data buffer size either is not 64-bit aligned or data length crosses the 128-bit aligned memory boundary)
  • Fapi_Error_FlashRegsNotWritable (failure: Flash register writes failed. The user should make sure that the API is executing from the same zone as that of the target address for flash operation OR the user should unlock before the flash operation.
  • Fapi_Error_FeatureNotAvailable (failure: User passed a mode that is not supported)
  • Fapi_Error_InvalidAddress (failure: User provided an invalid address. For the valid address range, see the TMS320F28003x Microcontrollers Data Manual.

Sample Implementation

This example does not show the erase operation. Note that a sector should be erased before it can be reprogrammed.

#include “F021_F28003x_C28x.h”
#define CPUCLK_FREQUENCY   120   /* 120 MHz System frequency */
int main(void)
{
     //     
     // Initialize System Control
     //
     Device_init();
 
     //
     // Call Flash Initialization to setup flash waitstates
     // This function must reside in RAM
     //
     Flash_initModule(FLASH0CTRL_BASE, FLASH0ECC_BASE, DEVICE_FLASH_WAITSTATES);
     
     //
     // Jump to RAM and call the Flash API functions
     //
     Example_CallFlashAPI();
}
#pragma CODE_SECTION(Example_CallFlashAPI, ramFuncSection);
void Example_CallFlashAPI(void)
{
     Fapi_StatusType oReturnCheck;
     Fapi_FlashStatusType oFlashStatus;
     uint16 au16DataBuffer[8] = {0x0001, 0x0203, 0x0405, 0x0607, 0x0809, 0x0A0B, 0x0C0D, 0x0E0F};
     uint32 *DataBuffer32 = (uint32 *)au16DataBuffer;
     uint32 u32Index = 0;
     EALLOW;
     //
     // This function is required to initialize the Flash API based on 
     // System frequency before any other Flash API operation can be performed
     // Note that the FMC register base address and system frequency are passed as the parameters
     //
     oReturnCheck = Fapi_initializeAPI(F021_CPU0_BASE_ADDRESS, CPUCLK_FREQUENCY);
     if(oReturnCheck != Fapi_Status_Success)
     {
          Example_Error(oReturnCheck);
     }
 
     // 
     // Fapi_setActiveFlashBank function initializes Flash banks 
     // and FMC for erase and program operations.
     //
     oReturnCheck = Fapi_setActiveFlashBank(Fapi_FlashBank0);
      
     if(oReturnCheck != Fapi_Status_Success)
     {
          Example_Error(oReturnCheck);
     }
     //
     // Bank0 Program
     //
     
     //
     // Program 0x200 16-bit words in Bank0 Sector 4
     //
    
     for(u32Index = 0x84000; (u32Index < 0x84200) &&
                             (oReturnCheck == Fapi_Status_Success); u32Index+=8) 
     {
          // 
          // Issue program command
          // 
          oReturnCheck = Fapi_issueProgrammingCommand((uint32 *)u32Index, au16DataBuffer, 8,
                                                               0, 0, Fapi_AutoEccGeneration);
          // 
          // Wait until the Flash program operation is over
          // 
          while (Fapi_checkFsmForReady() != Fapi_Status_FsmReady){}
          if(oReturnCheck != Fapi_Status_Success)
          {
               Example_Error (oReturnCheck);
          }
          // 
          // Read FMSTAT register contents to know the status of FSM after
          // program command to see if there are any program operation related errors
          // 
          oFlashStatus = Fapi_getFsmStatus();
          if(oFlashStatus != 0)
          {
               //
               //Check FMSTAT and debug accordingly
               //   
               FMSTAT_Fail();
          }
          
          // 
          // Verify the programmed values
          // 
          oReturnCheck = Fapi_doVerify((uint32 *)u32Index, 4, DataBuffer32, &oFlashStatusWord);
          if(oReturnCheck != Fapi_Status_Success)
          {
               //
               // Check Flash API documentation for possible errors
               //   
               Example_Error(oReturnCheck);
          }
     }
     // 
     // * User code for further Bank0 flash operations *
     //
     .
     .
     .
     .
  
     //
     // Example is done here
     //
     Example_Done();
 
}