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.

MSP432P401R: Why does the contoller resets during operation?

Part Number: MSP432P401R

Hello! I'm using MSP432 with ADS131A04 ADC to read some sensors. Until now I was able to read 1000 samples, save them in the MCU memory and plot them in CCS 7.

Now my code does not work. 9/10 times I run the program, when it reads over 100 samples, the CPU resets. Sometimes it can read fine, but most of the times it resets. Sometimes the program hangs in Default_Handler(), but most of the times I can catch it in Reset_Handler().

I placed a breakpoint in Reset_Handler() and saw the RSTCTL register values. Hard reset sources 0, 14, 15 are "1" and soft reset source 0 is "1" (CPU lockup, what does it mean? Also COREDEBUG - DHCSR - S_LOCKUP is "0", suggesting that there is no lockup?).

The program uses SPI to communicate with the ADC and a GPIO interrupt for DRDY. I've tried stripping the program of other code, leaving only what is necessary to communicate with the ADC and read the samples.

Does anybody have an idea what could be causing this problem? I really do not know how to continue investigating this.

  • Hello Cristian

    I have a few questions to ask

    1. Are you using the Launchpad or a custom board?
    2. Are you using the TI Drivers or the DriverLib APIs
    3. Since you are going to the DefaultHandler, my suspicion is there is a bus fault. Can you check the Fault Stat register in the Cortex M4 Private Peripheral address space to see what type of Bus Fault condition it is?
  • Hi,

    1. Custom board.
    2. DriverLib APIs.
    3. If it stops in Reset_Handler(), CFSR is 0. If it stops in Default_Handler(), then BFARVALID and PRECISERR are set, sometimes only IBUSERR is set, and sometimes only IMPRECISERR is set.

    Sometimes it works without error. What does it work sometimes, but most of the times it doesn't?
  • Hello Cristian,

    I believe there are two issues (since I do not have the board nor the software)

    1. Reset occurring. Can you clear the Reset register bits in the code, before the issue occurs so that we can isolate the cause of the Reset Handler being invoked
    2. When the Default Handler is invoked, the issue most likely stems from SRAM stack corruption. Did you check you have provided enough stack and heap for the application program.
  • Hi Amit,

    1. I could not reproduce the situation when it stops in the Reset_Handler(). I tried many times, but it did not happen and I have no idea why, so I didn't clear any of the bits in code. At least it is one problem less to think about.

    2. I've tried increasing the stack and heap sizes (up to 16k and 8k respectively), but it behaves the same (sometimes it works, sometimes it hangs in Default_Handler(). Memory allocation view looks fine and Stack usage view shows mostly green areas, except for _c_int00 - main - ADC sampling function, where it says in a popup "136 out of 136 bytes used". However, I do not know how to interpret these messages or the values shown.

    Do you have any idea on how to investigate this further?

    Thank you!

  • Hello Cristian

    Can you send me a simplified version of your software so that I can try it out on my side?
  • Sure. I have included the project in this message. I suggest running the program at least 10 times successively to catch it in the Default Handler (sometimes it works, sometimes it doesn't).

    I hope we can figure this out.

    8015.test.zip

  • Hello Cristian,

    I ran the test almost 20 times and it was always in the WFI state. I did the following step with SDK 1.60 after loading the program with the debugger connected

    1. DId a CPU reset.
    2. Ran the code for 4 sec
    3. Halted the CPU and checked the program execution. ==> It was always in WFI.
  • Hello Cristian,

    Worth mentioning that I do not have the ADS131A04 with me, so all the lines are effectively floating from the system perspective.
  • Did you place breakpoints in the Default and reset handlers? In my case, after a few tries it hangs in the Default handler. If it has any importance, I'm using SDK 1.50.00.12, because SDK 1.60 has not been released yet.

    I guess you commented out the lines that expected responses from the ADC since you do not have it. I've tried this on a MSP432 Launchpad and I confirm that the program does not hang or restart. However, the commented code hanged sometimes when run on my board suggesting a hardware problem with my board. If the problem is hardware-related, how can we find what is causing it?

  • Hello Cristoan,

    I would try with the break point. Also I did not make any changes to the code.

    I checked the TI.com and 1.60 is released.

    www.ti.com/.../SIMPLELINK-MSP432-SDK

    I will update the web support team that the SDK landing page does not show the correct version of the SDK.
  • Hello Amit,

    I've tested with the new SDK, but the behavior is the same, unfortunately.

    Could the problem be related with my hardware (my board)? What could cause it?
  • Hello Cristian

    Is the ADS131A04 powered from the same supply as the MSP432P401R? Can you try to separate the power supply for the two devices?
  • Hello Amit,

    Yes, it is powered from the same supply as the MCU. However, I did manage to completely separate the power supply by powering the ADC from a laboratory power supply. But the result is the same: sometimes it hangs in Default Handler.

    Do you have any other ideas to find the cause of the problem?
  • Hello Cristian,

    I don't think I have any other ideas other than going through the schematic and layout if you have a custom board. Another thing that might help in running SRAM test of writing and reading patterns to see if there is a supply instability that is causing bits to flip.
  • Hi Amit,

    Do you have a code example for writing/reading patterns to/from SRAM? As I see it, since the variables are stored in SRAM, I am already doing this by running the program I posted here. Or should I write the same predefined values every time and look for something (what)?

    Thanks,
    Cristian
  • Hello Cristian

    You can use the function rand() to generate the values. One of the functions that rand provides is the ability to seed it. Another way of doing it is to 0x55555555 and 0xAAAAAAAA pattern in alternate locations. Is this is a custom board?
  • Hello,

      I am debugging a new bespoke MSP42P401R and reusing code that worked on a previous (older) bespoke 432 board.

      I am just now seeing mysterious vectors to Default_Handler, and googling my problem led me to this post.

      I'll add a breakpoint to the entry statement and let you know what I see....

    bob s.

  • Hi Amit,

    Yes, it is a custom board. I will follow your suggestion, but what should I look for? If it hangs in Default Handler?
  • I recommend, and what I will probably do is to write a handler for every possible interrupt.
    Then I'll at least know which interrupt is misbehaving.
  • I think, at least in my case, is I'm reading a ROM data structure past its end (bad loop termination test) and probably hit an illegal memory read address.
  • That was it, solve my problem. Had a bad indexer into a ROM data structure.
    I'm guessing that's your problem too.
  • I think I found the cause of the problem, but I cannot explain it.

    Firstly, I followed your advice and tested writing to SRAM using this code:

    for (i = 0; i < noSamples; i++)
        {
            if (i % 2 == 0)
            {
                ch1d[i] = 0xAAAAAAAA;
                ch2d[i] = 0xAAAAAAAA;
                ch3d[i] = 0xAAAAAAAA;
                ch4d[i] = 0xAAAAAAAA;
            }
            else
            {
                ch1d[i] = 0x55555555;
                ch2d[i] = 0x55555555;
                ch3d[i] = 0x55555555;
                ch4d[i] = 0x55555555;
            }
        }

    It worked successfully. However, when using my code, it sometimes hanged in the Default_Handler():

    for (i = 0; i < noSamples; i++)
        {
            if (i % 2 == 0)
            {
                ch1d[i] = ADS131A04_LSB*Int24BitTwoComplementToSignedInt(0xAAAAAAAA);
                ch2d[i] = ADS131A04_LSB*Int24BitTwoComplementToSignedInt(0xAAAAAAAA);
                ch3d[i] = ADS131A04_LSB*Int24BitTwoComplementToSignedInt(0xAAAAAAAA);
                ch4d[i] = ADS131A04_LSB*Int24BitTwoComplementToSignedInt(0xAAAAAAAA);
            }
            else
            {
                ch1d[i] = ADS131A04_LSB*Int24BitTwoComplementToSignedInt(0x55555555);
                ch2d[i] = ADS131A04_LSB*Int24BitTwoComplementToSignedInt(0x55555555);
                ch3d[i] = ADS131A04_LSB*Int24BitTwoComplementToSignedInt(0x55555555);
                ch4d[i] = ADS131A04_LSB*Int24BitTwoComplementToSignedInt(0x55555555);
            }
        }
    
    // 24 bit 2's complement to signed int
    int Int24BitTwoComplementToSignedInt(unsigned int val)
    {
        return (0x800000 & val ? (int)(0x7FFFFF & val) - 0x800000 : val);
    }

    #define ADS131A04_LSB                           0.000000298023223876953125 // [V]


    What is wrong in the code that causes this behavior? Can you give me an advice? You can check the test project I uploaded a few messages ago.

  • Hello Cristian

    Is ch1d variable a uint32_t? I am thinking that the issue arises as you are multiplying a float and an integer without performing the correct typecast and some place it is causing a stack corruption.

    As an example I am using the following to do something similar

    adjustedfloatInput[loopCount*4] = (float32_t)((adjustedSampleBuffer[loopCount] & 0xFFFF))/(float32_t)(6553.6f);

    where adjustedfloatInput is a float32_t.

    Secondly instead of using 0xAAAA.AAAA and 0x5555.5555 if you can use 0x00AA.AAAA and 0x0055.5555 does it result in the same issue.

    Lastly what is the noSamples set as?
  • ch1d is float. noSamples is 1000. Trying with 0x00AA.AAAA and 0x0055.5555 gives the same issue. I've tried:

    ch1d[i] = (float)ADS131A04_LSB*(float)Int24BitTwoComplementToSignedInt(readDataCh1[i]);

    but the same.

  • Hello Cristian

    Before I run the code that you sent in your last post, if I run just the above code in a while(1), it should fail?
  • Yes, I think so. I will also test it.
  • I've tested the line in the while loop. This is the entire main():

    #define noSamples   1000
    float ch1d[noSamples];
    
    int main(void)
    {
        // Enabling the FPU with stacking enabled for floating point calculations
        MAP_FPU_enableModule();
        MAP_FPU_enableLazyStacking();
    
        Clock_System_init();
    
        //MAP_Interrupt_enableMaster(); // Enabling MASTER interrupts; with or without it, it hangs
        while(1)
        {
            ch1d[0] = (float)ADS131A04_LSB*(float)Int24BitTwoComplementToSignedInt(0x00AAAAAA);
    //Timer32_sleep_cycles(480000); // 1000 us @ MCLK = 48 MHz } }

    I confirm that it hangs in Default_Handler(). However, I found something very interesting: if I use my Timer32 sleep function in the while loop with 1ms sleep period every iteration it works, but if I use e.g. a 100us sleep period every iteration, it hangs in Default_Handler().

    Could the problem be that it is writing too fast to SRAM (ch1d)?

  • Hello Cristian,

    I tried the code and it seems to work for me on the LaunchPad. One thing that I had to do was to mask out Clock_System_init(); as I do not have the function prototype. The other thing I noticed was different is my code has the following additional line

    /* Stop Watchdog */
    MAP_WDT_A_holdTimer();
  • Hi,

    This is Clock_System_init():

    void Clock_System_init(void)
    {
    	// Stop Watchdog
    	MAP_WDT_A_holdTimer();
    	MAP_Interrupt_disableMaster();
    
    	// Setting the external clock frequency
    	MAP_CS_setExternalClockSourceFrequency(32768, 48000000);
    	MAP_PCM_setCoreVoltageLevel(PCM_VCORE1);
    
    	// Configuring pins for crystal usage
    	MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_PJ, GPIO_PIN0 | GPIO_PIN1, GPIO_PRIMARY_MODULE_FUNCTION); // LFXT
    	MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_PJ, GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION); // HFXT
    
    	//MAP_FlashCtl_setWaitState(FLASH_BANK0, 1);
    	//MAP_FlashCtl_setWaitState(FLASH_BANK1, 1);
    
    	MAP_FlashCtl_setWaitState(FLASH_BANK0, 2); // For 48 MHz
    	MAP_FlashCtl_setWaitState(FLASH_BANK1, 2); // For 48 MHz
    
    	// Starting LFXT in non-bypass mode without a timeout
    	MAP_CS_startLFXT(false);
    	// Starting HFXT in non-bypass mode without a timeout
    	MAP_CS_startHFXT(false);
    
    	// Initializing MCLK, HSMCLK, SMCLK and ACLK
    	MAP_CS_initClockSignal(CS_MCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_1);
    	MAP_CS_initClockSignal(CS_HSMCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_1); // Shares clock source with SMCLK
    	MAP_CS_initClockSignal(CS_SMCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_2); // Maximum HSMCLK / 2; shares clock source with HSMCLK
    	MAP_CS_initClockSignal(CS_ACLK, CS_LFXTCLK_SELECT, CS_CLOCK_DIVIDER_1); // Maximum 128 kHz
    	MAP_CS_initClockSignal(CS_BCLK, CS_LFXTCLK_SELECT, CS_CLOCK_DIVIDER_1); // Maximum 32768 kHz
    }

    I've tested the code on a MSP432 Launchpad and I confirm that it works fine. So the problem is with my board.

    I followed the advice to test every interrupt to see what is causing the problem. So I wrote handlers for all interrupts (with a while loop inside) and tested them one by one. I found that it hangs in:

    HardFault_Handler() (always)

    MemManage_Handler() (sometimes)

    WDT_A_IRQHandler() (sometimes) - Although WDT is put on hold at the start of the program

    EUSCIA3_IRQHandler() (sometimes) - Although nothing is connected to EUSCIA3

    EUSCIB3_IRQHandler() (sometimes) - Although nothing is connected to EUSCIB3

    T32_INT2_IRQHandler() (sometimes) - Why INT2?

    PORT3_IRQHandler() (sometimes) - ?

    I had to run the program many times to catch it hanging in one of the interrupts I marked "sometimes". It is possible that it could hang in other interrupts which I missed, because I haven't run the program enough times.

    Do you have any ideas how to further investigate the issue?

  • Hello Cristian,

    Since the issue is most probably related to your custom board, you would need to check the schematics and layout of your board.
  • I got stuck, because the schematic looks fine and I do not know what to understand from these interrupts in order to find the cause of the problem.

    It is curious that there wasn't any problem until a few weeks ago, and I haven't made any changes to the board.

  • I got stuck, because the schematic looks fine and I do not understand the cause of the interrupts.

    It is curious that the program worked until a few weeks ago and I haven't made changes to the board.

  • Hello Cristian,

    My suspicion is that there is a reset or a bus fault happening . Cause of the bus fault seems to be SRAM corruption may be due to insufficient current to the device. Why it happened now and not earlier is really something that depends on what conditions were being exercised by ypur code.

**Attention** This is a public forum