This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28069M: Flash API drops Motorware proj_lab09a to PIE_illegalIsr()

Part Number: TMS320F28069M
Other Parts Discussed in Thread: MOTORWARE

I am trying to use the flash API to emulate EEPROM on a board that runs the Motorware proj_lab09a. To do this I used code from Example_Flash2806x_API from c2000 ware.

For testing purposes I inserted the following code right before the for(;;) loop in main():

  EALLOW;
  Flash_CPUScaleFactor = SCALE_FACTOR;
  Flash_CallbackPtr = NULL;
  EDIS;

  FLASH_ST FlashStatus;
  static uint16_t status = 1;

  flashVersion = Flash_APIVersionHex();

  Flash_Erase((SECTORG|SECTORH),&FlashStatus);

  uint16_t buffer[0x100];

  int i = 0;
  for(i=0;i<0x100;i++)
  {
      buffer[i] = 0x100+i;
  }

  uint16_t *Flash_ptr = Sector[0].StartAddr;

  Flash_Program(Flash_ptr,buffer,0x100,&FlashStatus);

  status = Flash_Verify(Flash_ptr,buffer,0x100,&FlashStatus);

When I run the code, the program drops to PIE_illegalIsr() when it reaches Flash_Erase(). And if I comment out the erase function, it does the same at Flash_Program(). When I run the lab09 and the flash api example separately, there is no problem in either.

What am I missing?

  • Dmitri,

    Are you running these functions from RAM?  They should be run from RAM.  You might have loaded them to flash in linker cmd file and might have allocated a RAM address for run.  Please make sure you use memcopy() to copy the .TI.ramfunc (ramfuncs) section contents from flash to RAM before calling these functions.  

    Thanks and regards,
    Vamsi

  • Are you talking about this?

    In main():

    memCopy((uint16_t *)&RamfuncsLoadStart,(uint16_t *)&RamfuncsLoadEnd,(uint16_t *)&RamfuncsRunStart);

    In F28069M.cmd:

       ramfuncs            : LOAD = FLASHD,
                             RUN = RAML0_1,
                             LOAD_START(_RamfuncsLoadStart),
                             LOAD_END(_RamfuncsLoadEnd),
                             RUN_START(_RamfuncsRunStart),
                             PAGE = 0

    These things are unchanged from the examples. Do I need to change anything here?

  • Dmitri,

    Yes, could you check whether the flash API is mapped to ramfuncs section or not in your linker cmd?

    You can check the map file to know where they are allocated for run and make sure the code got copied before you execute erase and program functions.

    Thanks and regards,

    Vamsi

  • The only place where I see flash api mentioned is in a .cmd file that is excluded from the build in the flash api example (Example_Flash2806x_SW_API.cmd):

       Flash28_API: // Applicable only when API is not in BootROM
       {
       		-lFlash2806x_API_V100.lib(.econst)
            -lFlash2806x_API_V100.lib(.text)
       }                   LOAD = FLASHD, 
                           RUN = PRAML0,  
                           LOAD_START(_Flash28_API_LoadStart),
                           LOAD_END(_Flash28_API_LoadEnd),
                           RUN_START(_Flash28_API_RunStart),
                           PAGE = 0

    If I try to adjust this section and copy it to the linker file that I am using in my project, I get the same behavior. Here is the adjusted code, in case I made a mistake:

       Flash28_API: // Applicable only when API is not in BootROM
       {
          -lFlash2806x_API_wFPU_Library.lib(.econst)
            -lFlash2806x_API_wFPU_Library.lib(.text)
       }                   LOAD = FLASHE,
                           RUN = RAML0_1,
                           LOAD_START(_Flash28_API_LoadStart),
                           LOAD_END(_Flash28_API_LoadEnd),
                           RUN_START(_Flash28_API_RunStart),
                           PAGE = 0

    Here is the content of the .map file for the sections in question:

     output                                  attributes/
    section   page    origin      length       input sections
    --------  ----  ----------  ----------   ----------------
    Flash28_API 
    *          0    003e4000    00000598     RUN ADDR = 00008000
                      003e4000    00000020     Flash2806x_API_wFPU_Library.lib : Flash28_Erase.obj (.econst:_Sector$1)
                      003e4020    00000008                                     : Flash28_Erase.obj (.econst:_SecKey$2)
                      003e4028    000000e8                                     : Flash28_Prog.obj (.text)
                      003e4110    000000c8                                     : Flash28_Erase.obj (.text)
                      003e41d8    0000009a                                     : Flash28_Erase_Pulse.obj (.text)
                      003e4272    00000084                                     : Flash28_Internals.obj (.text)
                      003e42f6    00000080                                     : Flash28_Prog_Pulse.obj (.text)
                      003e4376    0000007d                                     : Flash28_Compact_Pulse.obj (.text)
                      003e43f3    00000063                                     : Flash28_EraseSector.obj (.text)
                      003e4456    00000054                                     : Flash28_CompactSector.obj (.text)
                      003e44aa    00000041                                     : Flash28_ClearLoop.obj (.text)
                      003e44eb    00000039                                     : Flash28_Verify.obj (.text)
                      003e4524    00000034                                     : Flash28_ClearSector.obj (.text)
                      003e4558    00000015                                     : Flash28_Init.obj (.text)
                      003e456d    00000014                                     : Flash28_Utils.obj (.text)
                      003e4581    0000000d                                     : Flash28_Delay.obj (.text)
                      003e458e    00000007                                     : Flash28_DisInt.obj (.text)
                      003e4595    00000003                                     : Flash28_Version_Hex.obj (.text)
    
    ramfuncs   0    003e8000    000001a2     RUN ADDR = 00008598
                      003e8000    0000009f     proj_lab09a.obj (ramfuncs:retain)
                      003e809f    00000070     ctrl.obj (ramfuncs)
                      003e810f    0000006a     flash.obj (ramfuncs)
                      003e8179    00000025     hal.obj (ramfuncs)
                      003e819e    00000004     usDelay.obj (ramfuncs)

  • Dmitri,

    Along with that change, you also need to call memcopy() with Flash28_API_LoadStart, Flash28_API_LoadEnd, Flash28_API_RunStart parameters (just like how you called it with RamfuncsLoadStart, RamfuncsLoadEnd, RamfuncsRunStart).

    Thanks and regards,

    Vamsi

  • I added it now right after the memcopy that was already present, still the same behavior.

    memCopy((uint16_t *)&RamfuncsLoadStart,(uint16_t *)&RamfuncsLoadEnd,(uint16_t *)&RamfuncsRunStart);
    memCopy((uint16_t *)&Flash28_API_LoadStart,(uint16_t *)&Flash28_API_LoadEnd,(uint16_t *)&Flash28_API_RunStart);

    Do I maybe need to do some system configuration that would be different from the default settings in proj_lab09a? I skipped the InitSysCtrl() in the example because I assumed everything is already set up by the project. Was it a mistake?

  • Dmitri,

    InitSysCtrl() is needed.  

    Do you service watchdog in your application?  If not, watchdog needs to be disbaled.  InitSysCtrl() disables watchdog.

    It also configures PLL, peripheral clocks etc.  

    Thanks and regards,
    Vamsi

  • I discovered that the crash actually happens earlier now. When I add the 2nd memCopy(), the program drops to PIE_illegalIsr() when it reaches HAL_enableGlobalInts(halHandle). It doesn't even reach the flash functions. So the things set by InitSysCtl() should not yet be relevant at this stage. Could it be caused by some conflicts in the .cmd file?

    The file in its entirety, with some of the comments removed:

    MEMORY
    {
    PAGE 0 :   /* Program Memory */
               /* Memory (RAM/FLASH/OTP) blocks can be moved to PAGE1 for data allocation */
       RAML0_1     : origin = 0x008000, length = 0x000C00     /* on-chip RAM block L0 and L1 */
       OTP         : origin = 0x3D7800, length = 0x000400     /* on-chip OTP */
    
       FLASHH      : origin = 0x3D8000, length = 0x004000     /* on-chip FLASH */
       FLASHG      : origin = 0x3DC000, length = 0x004000     /* on-chip FLASH */
       FLASHF      : origin = 0x3E0000, length = 0x004000     /* on-chip FLASH */
       FLASHE      : origin = 0x3E4000, length = 0x004000     /* on-chip FLASH */   
       FLASHD      : origin = 0x3E8000, length = 0x004000     /* on-chip FLASH */
       FLASHC      : origin = 0x3EC000, length = 0x004000     /* on-chip FLASH */
       FLASHA_B    : origin = 0x3F0000, length = 0x007F80     /* on-chip FLASH */
       CSM_RSVD    : origin = 0x3F7F80, length = 0x000076     /* Part of FLASHA.  Program with all 0x0000 when CSM is in use. */
       BEGIN       : origin = 0x3F7FF6, length = 0x000002     /* Part of FLASHA.  Used for "boot to Flash" bootloader mode. */
       CSM_PWL_P0  : origin = 0x3F7FF8, length = 0x000008     /* Part of FLASHA.  CSM password locations in FLASHA */
    
       FPUTABLES   : origin = 0x3FD590, length = 0x0006A0	 /* FPU Tables in Boot ROM */
       IQTABLES    : origin = 0x3FDC30, length = 0x000B50    /* IQ Math Tables in Boot ROM */
       IQTABLES2   : origin = 0x3FE780, length = 0x00008C    /* IQ Math Tables in Boot ROM */
       IQTABLES3   : origin = 0x3FE80C, length = 0x0000AA	 /* IQ Math Tables in Boot ROM */
    
       ROM         : origin = 0x3FF3B0, length = 0x000C10     /* Boot ROM */
       RESET       : origin = 0x3FFFC0, length = 0x000002     /* part of boot ROM  */
       VECTORS     : origin = 0x3FFFC2, length = 0x00003E     /* part of boot ROM  */
    
    PAGE 1 :   /* Data Memory */
               /* Memory (RAM/FLASH/OTP) blocks can be moved to PAGE0 for program allocation */
               /* Registers remain on PAGE1                                                  */
    
       BOOT_RSVD   : origin = 0x000000, length = 0x000050     /* Part of M0, BOOT rom will use this for stack */
       RAMM0       : origin = 0x000050, length = 0x0003B0     /* on-chip RAM block M0 */
       RAMM1       : origin = 0x000400, length = 0x000400     /* on-chip RAM block M1 */
       RAML2_3     : origin = 0x008C00, length = 0x001400     /* on-chip RAM block L2 */
       RAML4       : origin = 0x00A000, length = 0x002000     /* on-chip RAM block L4 */
       RAML5       : origin = 0x00C000, length = 0x002000     /* on-chip RAM block L5 */
       RAML6       : origin = 0x00E000, length = 0x002000     /* on-chip RAM block L6 */
       RAML7       : origin = 0x010000, length = 0x002000     /* on-chip RAM block L7 */
       RAML8       : origin = 0x012000, length = 0x001800     /* on-chip RAM block L8. From 0x13800 to 0x14000 is reserved for InstaSPIN */
       USB_RAM     : origin = 0x040000, length = 0x000800     /* USB RAM		  */   
    }
    
    
    SECTIONS
    {
       Flash28_API: // Applicable only when API is not in BootROM
       {
          -lFlash2806x_API_wFPU_Library.lib(.econst)
            -lFlash2806x_API_wFPU_Library.lib(.text)
       }                   LOAD = FLASHE,
                           RUN = RAML0_1,
                           LOAD_START(_Flash28_API_LoadStart),
                           LOAD_END(_Flash28_API_LoadEnd),
                           RUN_START(_Flash28_API_RunStart),
                           PAGE = 0
    
       /* Allocate program areas: */
       .cinit              : > FLASHA_B,   PAGE = 0
       .pinit              : > FLASHA_B,   PAGE = 0
       .text               : > FLASHA_B,   PAGE = 0
       codestart           : > BEGIN,      PAGE = 0
       ramfuncs            : LOAD = FLASHD,
                             RUN = RAML0_1,
                             LOAD_START(_RamfuncsLoadStart),
                             LOAD_END(_RamfuncsLoadEnd),
                             RUN_START(_RamfuncsRunStart),
                             PAGE = 0
    
       csmpasswds          : > CSM_PWL_P0, PAGE = 0
       csm_rsvd            : > CSM_RSVD,   PAGE = 0
    
       /* Allocate uninitalized data sections: */
       .stack              : > RAMM0,      PAGE = 1
       .ebss               : > RAML2_3,    PAGE = 1
       .esysmem            : > RAML2_3,    PAGE = 1
    
       /* Initalized sections to go in Flash */
       /* For SDFlash to program these, they must be allocated to page 0 */
       .econst             : > FLASHA_B,   PAGE = 0
       .switch             : > FLASHA_B,   PAGE = 0
    
       /* Allocate IQ math areas: */
       IQmath              : > FLASHA_B,   PAGE = 0            /* Math Code */
       IQmathTables        : > IQTABLES,   PAGE = 0, TYPE = NOLOAD
       
       /* Allocate FPU math areas: */
       FPUmathTables       : > FPUTABLES,  PAGE = 0, TYPE = NOLOAD
       
       DMARAML5	           : > RAML5,      PAGE = 1
       DMARAML6	           : > RAML6,      PAGE = 1
       DMARAML7	           : > RAML7,      PAGE = 1
       DMARAML8	           : > RAML8,      PAGE = 1   
    
       .reset              : > RESET,      PAGE = 0, TYPE = DSECT
       vectors             : > VECTORS,    PAGE = 0, TYPE = DSECT
    
    }
    

  • Dmitri,

    Do you have any interrupts enabled?

    If so do you have a valid interrupt handler loaded in the vector table?

    Please note that the table entries are initialized to  PIE_illegalIsr on startup. So make sure you attach your own handler for any enabled interrupts.

    Another issue, you may need to disable interrupts before you call the FlashAPI routines or make sure the ISR is located/loaded in RAM.

  • I moved the flash related code in front of the HAL_enableGlobalInts(halHandle); line, and now it worked.

  • Correction: the flash operations now work, but the program still crashes on the HAL_enableGlobalInts(halHandle) line.

    As I said before, I'm using proj_lab09a from motorware 18, so yes, there are interrupts, but they should all be configured correctly, because aside from the modifications in regards to flash I did not change anything.

  • Dmitri,

    Now that the flash operations are working, could you open a new post for this later issue?  We will assign the new post to corresponding expert to help you further.

    Thanks and regards,
    Vamsi