@ErichStyger
Did you delete a posting? I got notification with:
Yes, maybe back to field 0.
My understanding is this:
- here is PRINTF in your code
- if you run that code with debugger attached it works fine
- if that code runs without debugger it fails with a stack overflow at that printf statement
- you are using semihosting for the printf
Now there are two things:
- printf and its other family members are known to use a lot of stack space and cause all kind of (e.g. reentrancy) problems. Thus I don't use them
- if using semihosting, this throws a debug exception which is handled by the debugger (if attached). If there is no debug session going on it throws a hard fault. So the standard behaviour is 'printf does not work without debugger attached). To overcome this there shall be a special hard fault handler in your project (there is an option in the SDK project generation for it): look for that semihost_hardfault.c
So it would be useful how your stack overflow is detected/triggered. FreeRTOS has two different methods for this: Method 1 just compares the PSP at task context switch time while method 2 checks the pattern on the stack. If it is not a true stack overflow, something else (dangling pointer) might have written something to your stack which is not an overflow but more of a stack corruption. I would check if this is the case. And if I would set a watchpoint on that address to find out who is writing to that address.
I hope this helps,
Erich
I wouldn't characterize the situation the way you have:
- I have been using PRINTFs in MANY of my projects without issues
- I went back and checked the previous versions and the problem behaviour is not present
- I am running a basic FreeRTOS and NXP SDK implementation
- I am running semi-hosting on a FRDM-K22F board for application development
- I have NOT changed any libraries, driver, board code that has been provided by the MCUXpresso new project wizards
- I added:
- The overflow handler we discussed last week
- ADC Interrupt Handler
- Two new tasks were added with two queues each
- configQUEUE_REGISTRY_SIZE is more than large enough for all queue objects
- A mutex was added
- configUSE_MUTEXES is set to 1
- When I run with the MCUXpresso debugger active, no issues during operation
- When I stop the MCUXpresso, the next time a USB packet is received the overflow handler is invoked and the system crashes
- As part of this, some IO values are changed
- I'm pointing this out because maybe it's coincidental that the overflow indicator LEDs light
- If I take the PRINTFs out of the project (which I can do with the SDK_DEBUGCONSOLE build variable) no issues running the application with or without MCUXpresso operational
In terms of your comments back:
- "there shall be a special hard fault handler in your project (there is an option in the SDK project generation for it): look for that semihost_hardfault.c" I just looked at the SDK project builder and can't find it. The only reference I can see in the semihost_hardfault.c code to changing it's operation is "// Allow handler to be removed by setting a define (via command line)". Can you be a bit more specific?
- "how your stack overflow is detected/triggered" I'm using method 2.
- Note the comments above, I'm now not 100% sure that the overflow check
- Regardless, if the problem only occurs when PRINTF is active and debug is disabled, any ideas on how to catch the event?
Again, thank you for your time and comments,
myke