cancel
Showing results for 
Search instead for 
Did you mean: 

What is stm32fxx_xx.s startup file for?

laojian
Associate II
Posted on March 03, 2016 at 09:22

Hi all,

Thanks in advance for your time spent on this topic.

I have spent several months on STM32 project, fine with software coding, but keep confusion on the startup file, which would appear in

almost every project as below. I think everyone of you also should be very familiar with it.

0690X00000605MfQAI.png  

I have spent time reading this code. It is like, I can understand every part of the code itself from grammar, but know nothing on big picture.

For example, I know it is the first code would be run after power on,it setup the stack, heap, interrupt entry address,

and then load main() function.

However, is there anything that I can play with it? Such as the stack and heap setup code below:

------------------------------------------------------------------------------------------------

; Amount of memory (in bytes) allocated for Stack

; Tailor this value to your application needs

; <h> Stack Configuration

;   <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>

; </h>

Stack_Size      EQU     0x00000400

            AREA    STACK, NOINIT, READWRITE, ALIGN=3

Stack_Mem      SPACE   Stack_Size

__initial_sp

                                                  

; <h> Heap Configuration

;   <o>  Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>

; </h>

Heap_Size       EQU     0x00000200

             AREA    HEAP, NOINIT, READWRITE, ALIGN=3

__heap_base

Heap_Mem        SPACE   Heap_Size

__heap_limit

--------------------------------------------------------------------------------------------------

The code above set stack size to 0x00000400, heap size to 0x00000200, but why? Can I change it? Based on what criteria?

Is this .s code specified to MCU core or board level? Do I need to modify the code if I design a different board with different peripherals but with same MCU?

In other words, When, and how, must I make modifications to this .s startup file? 

 

Thanks~~ 

 

#startup-file
2 REPLIES 2
Amel NASRI
ST Employee
Posted on March 03, 2016 at 17:56

Hi lao.jian,

You may find more explanation on the startup file content in https://www.keil.com/pack/doc/CMSIS/Core/html/startup_s_pg.html.

-Mayla-

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Posted on March 03, 2016 at 19:30

Do your subroutines use local/auto variables? How do those stack up for your deepest call chain? The default stack is often inadequate, especially when used with sscanf/sprintf type functionality. It also often catches PC coders used to huge limitless stacks, and not aware of static or const directives and there appropriate use in subroutines.

Do you malloc any variables or allocations during initialization, or run time? Is the heap provided adequate to support your needs?

If you can answer these questions, then you should be able to determine *your* heap/stack requirements.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..