Y
Y
Yu Yu2016-05-04 22:53:10
ARM
Yu Yu, 2016-05-04 22:53:10

Where does the STM32 stack start from?

I am studying the article. Seemed pretty interesting.
habrahabr.ru/post/274541/
As I got to parsing the binary, I got stuck. Help unravel.
I am projecting Vitaly's article onto my processor. STM32F100C4T6B
Memory in it 4kB (RAM).
In the article, the memory is calculated as 2020000, then for STM32F100C4T6B it should be 20001000 right?
But it turns out I got out of bounds. Isn't it necessary to subtract 1 from the result? those. 20000FFF
If you create a project in IAR, then after disassembling it turned out to be 20000408. Where do these numbers come from?
Does the stack start at the end of memory (i.e. 20000FFF for 4 kB)?
Please don't pass by.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mirn, 2016-05-05
@xztau

in modern and sane development environments, everything is set explicitly right in the source codes and you can immediately see where, for example, the stack lies and how it is connected at startup through the interrupt table.
for example, see my minimal program on normal C in a normal development environment, which did all the perversions on asme that were in the article.
https://habrahabr.ru/post/274901/#comment_8738493
I decode
__attribute__ ((section(".co_stack"))) - this attribute forces to put the array for the stack in the section named .co_stack, and then in the LD file (sets the order layout of sections in the firmware and manages the addresses of what to put where) it is indicated that this section should come after the data section
__attribute__ ((section(".min_isr_vector"))) - in the same way gives the name min_isr_vector, and in the ld file it is indicated that this section is the first in the firmware and always comes from the address 0x08000000.
the stack does not need to decrease the value by X, if the memory ends at 2020000, then 2020000 can be pushed into SP. Because when the push command AT THE BEGINNING, the value of SP is reduced and then the stored data is put according to this reduced value.
Yes, and SP points to memory and must be a multiple of 4 (machine word, 20000FFF is unacceptable!)
Sorry, but Iar and Keil are not very good environments (but the compilers in them are good, yes), and therefore it is necessary to use tools that are sane and not outdated in the 90s. Then there will be no questions. here in eclipse with the CDT plugin for C and C ++, stack allocation is done normally in all examples. And the last one is perfect. In Attolic and all sorts of RED from NXP, for example, everything was just as well done, so choosing the environment you like is not a problem, you just need to want it ;)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question