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.

TMS320F280037C: CPU gets stacked in system_post_cinit()

Part Number: TMS320F280037C

Hello team, 

I have a problem with debugging the device. 

The project is building correctly and the processor probably is programming also correctly but when I click "Play" button CPU gets stacked in Boot ROM:

The problem appears randomly. When I edit code, even if it's just removing or adding one line of code project builds correctly and the CPU can run correctly as I expected. 

Do you know what could trigger this fault behavior? 

  • Hello Mateusz,

    The project is building correctly and the processor probably is programming also correctly but when I click "Play" button CPU gets stacked in Boot ROM

    Can you try stepping through the code to see what exact line the issue is occurring on? Based on your screenshot, it looks like this might be an ITRAP (instruction trap, which occurs when an invalid instruction is run). Please make sure to look at the Disassembly while doing this to verify valid instructions are executing.

    When I edit code, even if it's just removing or adding one line of code project builds correctly and the CPU can run correctly as I expected. 

    Can you elaborate on what you're editing? Is it any line that you're removing or only certain ones? Please test thoroughly so we can narrow down the source of the problem.

    Best regards,

    Omer Amir

  • Hello Omer, 

    I found what triggers ITRAP but I don't exactly know why this function once triggers illegal operation INT and once not. 

    This function is Fapi_setActiveFlashBank(Fapi_FlashBank1) and I execute this function at the end of device initialization process:

    void Device_init(void)
    {
        //
        // Disable the watchdog
        //
        SysCtl_disableWatchdog();
    #ifdef CMDTOOL
        CMD_init();
    #endif
    
    #ifdef _FLASH
    #ifndef CMDTOOL
        //
        // Copy time critical code and flash setup code to RAM. This includes the
        // following functions: InitFlash();
        //
        // The RamfuncsLoadStart, RamfuncsLoadSize, and RamfuncsRunStart symbols
        // are created by the linker. Refer to the device .cmd file.
        //
        memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
    #endif
        //
        // Call Flash Initialization to setup flash waitstates. This function must
        // reside in RAM.
        //
        Flash_initModule(FLASH0CTRL_BASE, FLASH0ECC_BASE, DEVICE_FLASH_WAITSTATES);
    #endif
    
        //
        // Set up PLL control and clock dividers
        //
        SysCtl_setClock(DEVICE_SETCLOCK_CFG);
    
        //
        // Make sure the LSPCLK divider is set to the default (divide by 4)
        //
        SysCtl_setLowSpeedClock(SYSCTL_LSPCLK_PRESCALE_1);
    
        //
        // These asserts will check that the #defines for the clock rates in
        // device.h match the actual rates that have been configured. If they do
        // not match, check that the calculations of DEVICE_SYSCLK_FREQ and
        // DEVICE_LSPCLK_FREQ are accurate. Some examples will not perform as
        // expected if these are not correct.
        //
        ASSERT(SysCtl_getClock(DEVICE_OSCSRC_FREQ) == DEVICE_SYSCLK_FREQ);
        ASSERT(SysCtl_getLowSpeedClock(DEVICE_OSCSRC_FREQ) == DEVICE_LSPCLK_FREQ);
    
    #ifndef _FLASH
        //
        // Call Device_cal function when run using debugger
        // This function is called as part of the Boot code. The function is called
        // in the Device_init function since during debug time resets, the boot code
        // will not be executed and the gel script will reinitialize all the
        // registers and the calibrated values will be lost.
    	// Sysctl_deviceCal is a wrapper function for Device_Cal
        //
        SysCtl_deviceCal();
    #endif
    
        //
        // Turn on all peripherals
        //
        Device_enableAllPeripherals();
    
        //
        // Lock VREGCTL Register
        // The register VREGCTL is not supported in this device. It is locked to
        // prevent any writes to this register
        //
        ASysCtl_lockVREG();
    
        //
        // Configure GPIO20 and GPIO21 as digital pins
        //
        GPIO_setAnalogMode(20U, GPIO_ANALOG_DISABLED);
        GPIO_setAnalogMode(21U, GPIO_ANALOG_DISABLED);
        /*
         * SET MCAN CLOCK PRESCALER
         */
        SysCtl_setMCANClk(SYSCTL_MCANCLK_DIV_1);
        //
        // Jump to RAM and call the Flash API functions
        //
        CallFlashAPI();
    }
    
    
    #pragma CODE_SECTION(CallFlashAPI, ".TI.ramfunc");
    void CallFlashAPI(void)
    {
    
        //
        // 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
        //
        // This function must also be called whenever System frequency or RWAIT is changed.
        //
        oReturnCheck = Fapi_initializeAPI(F021_CPU0_BASE_ADDRESS, CPUCLK_FREQUENCY);
        if(oReturnCheck != Fapi_Status_Success)
        {
            Example_Error(oReturnCheck);
        }
    
        //
        // Fapi_setActiveFlashBank function initializes Flash bank
        // and FMC for erase and program operations.
        //
    #warning triggers post C init
        oReturnCheck = Fapi_setActiveFlashBank(Fapi_FlashBank1);
    
        if(oReturnCheck != Fapi_Status_Success)
        {
            Example_Error(oReturnCheck);
        }
    
    }
    
    

    Illegal operation is detected here. 

  • My whole code is working and flash API is working correctly without setting the flash bank before erasing and program operations. 

    Fapi initialization in this case is enough, but I was sure that I had to set bank1 because I am operating on bank1 sectors. Maybe in this MCU, it is not necessary to set appropriate FLASH bank?

    There is another problem that is not resolved. When I edit code even if it is a duplication of one line of assign a new value to variable for example. 

                        (*data[1]).module1.modulesID.all = 0x0;
                        (*data[1]).module2.modulesID.all = 0x0;
                        (*data[1]).module3.modulesID.all = 0x0;
                        (*data[1]).module4.modulesID.all = 0x0;

    Project with the function Fapi_setActiveFlashBank(Fapi_FlashBank1) is working properly. 

  • I found what triggers ITRAP but I don't exactly know why this function once triggers illegal operation INT and once not. 

    Have you made sure that the Flash API function is not running from the Flash bank being operated on? This is something that is described in the Flash API user's guide:

    Also make sure that nothing is modifying the location of the function which you call (i.e. the RAM is not initialized or the Flash is not erased if that's where the function is located).

    When I edit code even if it is a duplication of one line of assign a new value to variable for example. 

    Can you please re-word this question/statement? I'm not sure I understand what this means, or what the code below is in reference to. Are you saying you can't assign a value to a variable?

  • Have you made sure that the Flash API function is not running from the Flash bank being operated on? This is something that is described in the Flash API user's guide:

    I am sure that flashAPI is located in RAM so I assume that is running from RAM. 

    FlashAPIlib is located in Flash bank 0 and then is transferred to RAM. I am operating on flash bank 1 and that is the one I want to set when I call function Fapi_setActiveFlashBank(Fapi_FlashBank1).

    Also make sure that nothing is modifying the location of the function which you call (i.e. the RAM is not initialized or the Flash is not erased if that's where the function is located).

    RAM and FLASH are initialized before CallFlashAPI() and I am sure that interrupts are enabled after call flash API.

    Can you please re-word this question/statement? I'm not sure I understand what this means, or what the code below is in reference to. Are you saying you can't assign a value to a variable?

    I would say that just a little modification in the code and output file makes that the project with the function Fapi_setActiveFlashBank(Fapi_FlashBank1) is working properly. That's still not clear to me because once project is working and once not with that function before modification. 

    Now, I added EALLOW and EDIS directives every time I use FLASH api, and it seems that resolved the problem. 

  • Now, I added EALLOW and EDIS directives every time I use FLASH api, and it seems that resolved the problem. 

    I'm not sure why this would be necessary to make the code function, I will forward this post to a Flash expert to confirm why this makes your program work correctly. As they are currently out-of-office due to the holidays, please expect a reply sometime around next Wednesday.

  • Hi Mateusz,

    Could you attach an image of the device that you are using?  

    Thanks and regards,
    Vamsi

  • Also, please share the TI-OTP memory dump from the debugger memory window.

    Thanks and regards,

    Vamsi

  • Hi Mateusz,

    Could you provide the requested info?

    Thanks and regards,

    Vamsi

  • Hi Vamis, 

    I apologize for the late answer. Here is the requested information. 

    Could you attach an image of the device that you are using? 

    Also, please share the TI-OTP memory dump from the debugger memory window.

    @70000
    0000 0000 0000 0000 0000 0000 0000 0000
    0000 0000 0000 0000 0000 0000 0000 0000
    0000 0000 0000 0000 0000 0000 0000 0000
    0000 0000 0000 0000 0000 0000 0000 0000
    0000 0000 0000 0000 0000 0000 0000 0000
    0000 0000 0000 0000 0000 0000 0000 0000
    0000 0000 0000 0000 0000 0000 0000 0000
    0000 0000 0000 0000 0000 0000 0000 0000
    E934 BC4A D288 00A4 2F00 0029 0000 A4C8
    0000 0000 0000 0000 0000 0000 0000 0000
    0000 0000 0000 0000 0000 0000 0000 0000
    0000 0000 0000 0000 0000 0000 0000 0000
    0000 0000 0000 0000 0000 0000 0000 0000
    0000 0000 0000 0000 0000 0000 0000 0000
    0000 0000 0000 0000 0000 0000 0000 0000
    0000 0000 0000 0000 0000 0000 0000 0000
    0000 0000 0000 0000 0000 0000 0000 0000
    0000 0000 0000 0000 0000 0000 0000 0000
    0000 0000 0000 0000 0000 0000 0000 0000
    0000 0000 0000 0000 0000 0000 0000 0000
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    01F8 0011 51DC EB8B 0703 0404 FFFF FFFF
    6000 7718 1715 0644 0015 FB6A 0057 0048
    4C64 4C64 20A5 0A0A 0200 02C1 F00A 0200
    0002 FF02 0014 0001 0010 07D0 0FA0 0000
    080E 080B 0801 0808 0808 0A08 0310 EA19
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    FFFF 0007 0009 0007 FFFF FFFF FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    FFFF 1264 FFFF FFFF FFFF 0000 FFFF FFFF
    FFFF 1151 FFFF FFFF FFFF 0000 FFFF FFFF
    FFFF 1226 FFFF FFFF FFFF 0000 FFFF FFFF
    FFFF 1225 FFFF FFFF FFFF 0000 FFFF FFFF
    FFFF 1152 FFFF FFFF FFFF 0000 FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    5D64 3F28 9AA8 3F3C 9371 EE0A 005F FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF F3F0 3F4D
    8A58 3F65 9C27 FFFF 4253 4B1E 8D2D 4B2C
    0241 0023 7880 4B1D 6EB8 4B2B 0239 0023
    0776 4C3E 9CB8 4C4D 022D 0028 1725 3FC7
    0B2E 3FDF 81A5 4017 1401 4029 9BAC 9B6E
    0004 0000 0000 0000 0008 1FC0 F800 0007
    0002 0000 0000 0000 F0F0 E0F0 E0F0 0039
    000C 07BF 07C6 001E 8000 3F40 9772 3F57
    9C28 0087 0000 0000 8EEF 3F71 641F 3F87
    66EA 3F70 A809 3F86 BC25 BC28 0001 0064
    7E02 FFFF FFFF FFFF FFFF FFFF AB7B 90B4
    0000 0000 0000 0000 9371 EE0A 005F FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF 9E90 3F4A
    82F8 3F69 9BAD FFFF 3765 4B1D F593 4B2F
    0252 0027 397D 4B1C 9C85 4B2E 0252 0029
    CC2C 4C3B 1C5E 4C50 0246 002F 4026 3FC4
    6076 3FE2 C5A1 4014 9EC2 402B 9B34 9BAD
    F0F0 E0F0 E0F0 FFFF FFFF 0A1E 0A29 007D
    6633 06FF 66FB 0705 FFFF FFFF FFFF FFFF
    FFFF FFFF 0000 0000 0001 0064 7E01 FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF D2D1 30AA
    5678 1234 DEF1 9ABC 5678 1234 DEF3 9ABC
    586E ACEF 37C8 6E28 F643 CC3D 2F6E C687
    6F36 1B37 5512 5DEC 2C7E 0004 CDB4 180E
    CD6C 39C9 11F2 A6F2 0249 0026 023F 0026
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF 3281 442D
    8DE5 4B19 99C1 442D 9468 4B19 FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF 878A 0FDC
    2280 0006 0500 05FD 5A07 FFFF FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    FFFF FFFF FFFF FFFF B56C 3775 0001 FFFF
    5A5A 5A5A 5A5A 5A5A FFFF FFFF 5A5A 5A5A
    FFFF 5A5A 0134 0007 0135 0007 0136 0007
    01A2 0007 0214 0007 0216 0007 01D0 0007
    01D1 0007 01BE 0007 016F 0007 0170 0007
    019C 0007 0001 FFFF FFFF FFFF FFFF FFFF
    0001 0000 FE12 0200 1E48 0202 1E4A 0204
    1E4C 02AE 1E4E 0216 1E50 0218 1E52 8F3F
    B6F2 A8A9 7647 032E 88A9 8F00 FFFF A8A9
    0FA6 6003 D400 6F7F 8A4C BE08 06C4 9B00
    900F 0FA6 6077 7622 8F05 D232 18C4 FFFE
    F62D 7700 18C4 FFFD 8F05 D230 06C4 5101
    1EC4 28A9 07FF 54C4 6117 8F01 01D0 A8A9
    0F48 6709 8F05 D232 1AC4 0001 761A 8F00
    A5A5 6F59 0201 0748 1E48 8F05 D230 28A9
    07FF 54C4 60EB 8F05 D20E 18C4 FFFD F678
    7700 8F05 D208 18C4 FFFC F62D 7700 1AC4
    0001 F63C 7700 8F05 D20E 18C4 FFFE F642
    7700 8F05 D214 06C4 18A9 FF00 18A8 FFE0
    5018 5103 1EC4 8F05 D20E 1AC4 0001 8A50
    0230 1EC4 8A52 0203 1EC4 FF69 767F CD72
    5200 6106 7625 FF69 767F D9AB 6F00 7622
    0200 8F05 D222 1EC4 8A4A 1AC4 000A BE00
    C242 1E44 2B45 8A4C D505 06C4 D478 767F
    B929 8A4E 1EC4 761A 28A9 B8AE 9B3F 1EBD
    0007 D400 FE92 FF69 A8A9 0006 FE02 1E42
    0F44 6105 28A9 FFFF FE82 0006 28A9 AAAA
    FE82 0006 9A00 FF69 FE82 0006 FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    FFFF FFFF FFFF FFFF FFFF FFFF 0292 0007
    FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
    0000 0000 0000 0000 0000 0000 0000 0000
    0000 0000 0000 0000 0000 0000 0000 0000
    q

    Thanks and regards,

    Mateusz Stasiak

  • Hi Mateusz,

    Thank you for the details.  Will review and get back to you on December 4th.

    Thanks and regards,
    Vamsi 

  • Hi Mateusz,

    Can you share your linker command file and map file?  You can remove any proprietary information from it.

    From the snapshot that you shared, I see that the flash driverlib is copied to RAM.  I would like to confirm whether the flash API itself is copied to RAM or not. Thank you. 

    Best regards,

    Vamsi

  • Hi Vamsi,

    Can you share your linker command file and map file?  You can remove any proprietary information from it.

    From the snapshot that you shared, I see that the flash driverlib is copied to RAM.  I would like to confirm whether the flash API itself is copied to RAM or not. Thank you. 

    In my source file, I use #pragma CODE_SECTION directives to add FlashAPI functions to ".TI.ramfunc" program block. 

    For example:

    #pragma CODE_SECTION(CallFlashAPI, ".TI.ramfunc");
    void CallFlashAPI(void)
    {
        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
        //
        // This function must also be called whenever System frequency or RWAIT is changed.
        //
        oReturnCheck = Fapi_initializeAPI(F021_CPU0_BASE_ADDRESS, CPUCLK_FREQUENCY);
        if(oReturnCheck != Fapi_Status_Success)
        {
            Example_Error(oReturnCheck);
        }
        //
        // Fapi_setActiveFlashBank function initializes Flash bank
        // and FMC for erase and program operations.
        //
        oReturnCheck = Fapi_setActiveFlashBank(Fapi_FlashBank1);
    
        if(oReturnCheck != Fapi_Status_Success)
        {
            Example_Error(oReturnCheck);
        }
        EDIS;
    }

    That directive allocates all my functions from my custom flashAPI source file. 

    Every flashAPI driver lib function which is inside my function is allocated in FLASH_BANK_0.

    Here is the part of the .map file from the project.

    .TI.ramfunc 
    *          0    00081000    000001c5     RUN ADDR = 00008000
                      00081000    00000049     driverlib.lib : flash.obj (.TI.ramfunc:Flash_initModule)
                      00081049    0000003c     Fapi_UserDefinedFunctions.obj (.TI.ramfunc:writeVector)
                      00081085    00000031     Fapi_UserDefinedFunctions.obj (.TI.ramfunc:FlashAPIEraseSectorIDVector)
                      000810b6    0000002c     driverlib.lib : flash.obj (.TI.ramfunc:Flash_setBankPowerMode)
                      000810e2    00000023                   : flash.obj (.TI.ramfunc:Flash_setWaitstates)
                      00081105    0000001d                   : flash.obj (.TI.ramfunc:Flash_setPumpPowerMode)
                      00081122    00000019     Fapi_UserDefinedFunctions.obj (.TI.ramfunc:CallFlashAPI)
                      0008113b    00000018     driverlib.lib : flash.obj (.TI.ramfunc:Flash_disableCache)
                      00081153    00000018                   : flash.obj (.TI.ramfunc:Flash_disablePrefetch)
                      0008116b    00000017                   : flash.obj (.TI.ramfunc:Flash_enableCache)
                      00081182    00000017                   : flash.obj (.TI.ramfunc:Flash_enablePrefetch)
                      00081199    00000016                   : flash.obj (.TI.ramfunc:Flash_enableECC)
    
                      000811b7    00000006     Fapi_UserDefinedFunctions.obj (.TI.ramfunc:Example_Error)
                      000811bd    00000004     driverlib.lib : sysctl.obj (.TI.ramfunc)
                      000811c1    00000004     f28003x_usdelay.obj (.TI.ramfunc)
    
    ########################################################################################                  
    ######################   The rest of the Fapi functions                  
    ########################################################################################                  
    0     0000f9b8  Fapi_GlobalInit                  
    0     0008bffe  Fapi_WriteReadBack               
    0     0008b9cf  Fapi_calculateFletcherChecksum   
    0     0008c6ac  Fapi_calculateOtpChecksum        
    0     0008c630  Fapi_checkFsmForReady            
    0     0008a86c  Fapi_checkRegionForValueBy16bits 
    0     0008af85  Fapi_configureFMAC               
    0     0008b9fb  Fapi_divideUnsignedLong          
    0     0008a7f0  Fapi_doBlankCheck                
    0     0008c5d6  Fapi_doVerifyBy16bits            
    0     0008be78  Fapi_flushPipeline               
    0     0008c99a  Fapi_getFsmStatus                
    0     0008b7ec  Fapi_initializeAPI               
    0     0008bca9  Fapi_isAddressEcc                
    0     0008b526  Fapi_isAddressValid              
    0     0008a770  Fapi_issueAsyncCommandWithAddress
    0     0008b047  Fapi_issueFsmCommand             
    0     00087b56  Fapi_issueProgrammingCommand     
    0     0008a8e7  Fapi_loopRegionForValue          
    0     0008b784  Fapi_loopRegionForValueBy16bits  
    0     0008c81b  Fapi_scaleCycleValues            
    0     0008b59b  Fapi_setActiveFlashBank          
    0     0008b8b3  Fapi_setupBankSectorEnable       
    0     0008bf07  Fapi_setupSectorsForWrite        
    0     00008085  FlashAPIEraseSectorIDVector      
    0     00008000  Flash_initModule                          
                      

    I don't know if it could be a problem. I didn't operate on the FLASH_BANK_0 just on BANK_1 where there is no FLASH api function.

    Best regards, 

    Mateusz

  • Hi Mateusz,

    We identified an issue with this use case.

    Can you send me a friendship request (hover over my name and click on "Request Friendship")?

    I will send you a workaround that you can use. 

    Thanks and regards,
    Vamsi

  • Hi Vamsi, 

    I have sent you a request. 

    Thanks for the rapid replay. 

    Best regards,

    Mateusz 

  • Hi Mateusz,

    I provided a simple workaround for you.

    Let me know how it goes.  

    Once your implementation is closed and verified, we can update it here.

    Thanks and regards, 
    Vamsi 

  • Hi Mateusz,

    I am closing this post since we aligned on the fix offline.

    FYI for others that may refer to this post: We suggested the customer to disable the prefetch mechanism before calling Fapi_setActiveFlashBank().  Prefetch can be enabled after the execution of the Fapi_setActiveFlashBank().  Code that disables and enables the prefetch mechanism should be executed from RAM.  

    We will update the documentation accordingly in the next revision.

    Thanks and regards,
    Vamsi