-
Notifications
You must be signed in to change notification settings - Fork 3k
STM32: Reduce HAL_deepsleep stack usage #7241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM aside for some whitespace indetation nits, but I'll be waiting to start CI until someone else from ST approves.
Kinda surprised that those two structure allocations were overflowing the stack. |
targets/TARGET_STM/sleep.c
Outdated
} | ||
#endif // TARGET_STM32L4 | ||
} | ||
|
||
static void ForceClockOutofDeepSleep(void) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like a comment here to see the reason why this was split up; with some hint to test in debug configuration if anything changes in this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense - will do.
This does not fix my issue on mbed-os-example-wifi... Still runs out of stack space immediately (w/ tickless, cpu stats and memory stats enabled).
|
Just tried on my board (L476 IOT) with all below stats and I could not reproduce the issue To progress in parallel, you can increase MBED_CONF_APP_IDLE_THREAD_STACK_SIZE in your application |
I tested my basic test program fine on DISCO-F413 , with all the enabled STATS flags and TICKLESS and I don't see the stack overflow. Please confirm if the overflow happens from the idle task or not. Maybe this PR solves a first issue, but there may be another one behind. More generally, in case we activate lots of debug and use a non optimized compilation scheme, we should arrange for larger, non-optimized stack sizes ... |
targets/TARGET_STM/sleep.c
Outdated
|
||
/* Get the Oscillators configuration according to the internal RCC registers */ | ||
HAL_RCC_GetOscConfig(&RCC_OscInitStruct); | ||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this now misaligned?
targets/TARGET_STM/sleep.c
Outdated
@@ -97,19 +77,9 @@ static void ForceClockOutofDeepSleep(void) | |||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; | |||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; | |||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, pFLatency) != HAL_OK) { | |||
error("clock issue\r\n"); | |||
error("clock issue\r\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
8 spaces , not 4 here? Same issue is in the code below as well (copy-paste probably?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recently changed my PC and have to reconfigure tools correctly - sorry about that ;-)
Did you test this on https://github.com/armmbed/mbed-os-example-wifi ? It immediately overflows (on idle thread) for me w/ debug profile, even on your branch. |
@janjongboom @0xc0170 The issues is different though - the stack overflows without a call to hal_deepsleep. It seems we only so sleep, at least during the first seconds of application. Then even if I fully empty hal_sleep(), we still hit the stack overflow, so this seems to be related to the mbed core, not to ST HAL layer. @0xc0170 could someone help investigating that or provide ideas ... could that be hat calls to default_idle_hook() or some other place uses more than the default IDLE stack size ? Having MBED_CONF_APP_IDLE_THREAD_STACK_SIZE defined to > 544 (instead of 512) seems to solve the issue. |
There are cases where a call hal_deepsleep would overflow the idle task stack, especially in developper or debug profile. In order to avoid this case, we split ForceClockOutofDeepSleep into two separate functions the two structure RCC_ClkInitStruct and RCC_OscInitStruct are not allocated at the same time.
178d2e4
to
81adafb
Compare
@0xc0170 @janjongboom I still think this PR would help if not resolving everything. I fixed indentation issues and added a comment as suggested. |
/morph build |
Build : SUCCESSBuild number : 2396 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 2032 |
Test : SUCCESSBuild number : 2183 |
Description
There are cases where a call hal_deepsleep would overflow the idle task
stack, especially in developper or debug profile.
In order to avoid this case, we split ForceClockOutofDeepSleep
into two separate functions the two structure RCC_ClkInitStruct and
RCC_OscInitStruct are not allocated at the same time.
Fixes #7235
Pull request type