Troubleshooting reset causes using RCC->CSR register
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-08 8:42 AM
I am trying to determine the cause of resets happening in my application. It does not seem like the RCC->CSR register is working properly.
I tested this out by manually grounding the NRST pin and setting a break point in my code before main(). The CSR register has none of the reset bits set when I would expect to see PINRSTF set here. I also tried the same issuing a software reset and that does not seem to set the SFTRSTF bit. The ONLY time I see anything set here is when I do a reset using the debugger. When I do this I see both the PINRSTF and SFTRSTF set and then cleared after Hal_Init().
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-08 12:15 PM
What MCU? It generally works. More than one bit can be set. Usually PINRSTF is set in addition to others. I also see BORRST together with PORRST. Read early (before HAL...) and clear reset flags afterwards for next reset. Think those bits are sampled values of the reset circuit (see "Simplified diagram of reset circuit").
hth
KnarfB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-08 12:18 PM
Which STM32?
Try to read RCC_CSR without having debugger connected, e.g. outputting it to UART or similar.
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-08 12:46 PM
STM32L476. I have an array that holds the last 10 reset values and I can print them out in hex. Each reset is always a 0x600 unless I reset with the debugger and its a 0x1400600. This holds true with and without the debugger connected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-08 12:49 PM
This is exactly what I'm trying to accomplish but none of the bits are ever set no matter what type of reset occurs UNLESS I reset it with my debugger. I do read the register before main does anything.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-08 1:16 PM
I've just tried on an 'L476 DISCO and it behaves as expected - after power on 0x0c00'0600, after pushbutton (NRST) reset 0x0400'0600.
> manually grounding the NRST pin
How exactly do you do this?
Can you write an absolute minimal program, i.e. NO function calls in the startup code, and only RCC_CSR readout in main(), storing to memory and then infinite loop?
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-08 1:31 PM
Also hooked up my board. The following code works, i.e. separates between reconnecting power (BOR) and pressing the reset button (PIN).
int main(void)
{
/* USER CODE BEGIN 1 */
char *reset_cause = "unknown";
if (__HAL_RCC_GET_FLAG(RCC_FLAG_BORRST))
{
reset_cause = "BOR";
}
else if (__HAL_RCC_GET_FLAG(RCC_FLAG_PINRST))
{
reset_cause = "PIN";
}
__HAL_RCC_CLEAR_RESET_FLAGS();
