2018-10-25 09:30 AM
hi
i am trying to make a new project on STM32F030K6 but, after i start and pause debug, a message appears : The stack pointer for stack 'CSTACK' (currently 0x20000658) is outside the stack range (0x20000048 to 0x20000448) . and the program stuck somewhere.
if i made reset the debugger program (not a hardware reset) , this message will not appears .and the program will run (toggling an LED)
how to solve this .
iam using STM32CUBEMX HAL library , and IAR IDE
thanks in advance
2018-10-25 09:44 AM
>>how to solve this
Figure out what in your program, or code flow, is causing the stack point to go outside the 1KB (0x400) the linker has assigned to it.
Any routines using more than 1KB of local/auto variables?
Check what startup.s is setting the initial stack pointer too, or if it is changing it.
2018-10-25 09:56 AM
Thank you for you quick reply
>>Any routines using more than 1KB of local/auto variables? i dont think so ,i am just using one function in my code :HAL_GPIO_TogglePin
>>Check what startup.s is setting the initial stack pointer too, or if it is changing it.
actually i am new to STM32 and i dont have experience in startup files but here the part of sp initialization :
MODULE ?cstartup
;; Forward declaration of sections.
SECTION CSTACK:DATA:NOROOT(3)
SECTION .intvec:CODE:NOROOT(2)
EXTERN __iar_program_start
EXTERN SystemInit
PUBLIC __vector_table
DATA
__vector_table
DCD sfe(CSTACK)
DCD Reset_Handler ; Reset Handler
DCD NMI_Handler ; NMI Handler
DCD HardFault_Handler ; Hard Fault Handler
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD SVC_Handler ; SVCall Handler
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD PendSV_Handler ; PendSV Handler
DCD SysTick_Handler ; SysTick Handler
thanks
2018-10-25 10:24 AM
Check in the address assigned for "sfe" in the .MAP file.
Try to bisect the issue to find out when the SP goes out of range. If it is wrong by the time it hits your main() function, check the SystemInit() function.
Turn off the "run to main()" functionality in the debugger, and step the code from the Reset_Handler on in.
>>i am new to STM32
The STM32 is much like any other ARM Cortex-M micro-controller, and similar in operation to many other micro-controllers in the last 40 or so years.
IAR is complaining that the SP is outside the scope of the memory it should reside in. This might occur in an RTOS situation where you're allocating stacks to individual tasks, in memory unrelated to the one described by the linker.
2018-10-25 11:58 AM
HI
i had found the problem , in my pcb design i was pulling the Boot 0 pin to VCC , so the program was booting from the system memory not from the main flash memory .
i had connected the boot 0 to vss and unchecked the boot1 in option bytes , and the problem solved :)
thanks for your help