embos on stm32 would crash in keil

49 views Asked by At

I have setup a simple project to test embos with stm32f103rbt device, I just used the default settings, after changing the default complier warnings to MISRA compatible and changed the C standard to C99 and C++ to C++11 most of the errors would go away, But still there is two errors

.\Objects\marlin.axf: Error: L6218E: Undefined symbol Stack_Mem (referred from os_initsysstackinfo.o). .\Objects\marlin.axf: Error: L6218E: Undefined symbol __initial_sp (referred from os_initsysstackinfo.o).

So after searching I think I should make these symbols exported in the startup assembly file, So I tried to use these lines in the startup assembly file like this

Stack_Size   EQU   0x00000400

; EXPORT the Stack_Mem and __initial_sp symbols for use in C files

EXPORT Stack_Mem

EXPORT __initial_sp

But it would generate an error like this

.\Objects\marlin.axf: error: L6002U: Could not open file .\objects\startup_stm32f10x_md.o: No such file or directory

another solution would be to comment these lines

OS_SysStackBaseAddr = (unsigned long) &Stack_Mem;
OS_SysStackSize = (unsigned int) ((unsigned long)&__initial_sp - (unsigned long)&Stack_Mem);
OS_SysStackLimit = (unsigned long) &__initial_sp;

in the OS_InitSysStackInfo function, Now the project would be build and when I try to debug it it would crash, so How should I test this os?

1

There are 1 answers

1
Issylin On

I assume your assembly startup file looks like this startup_stm32f10x_md.s file, with both heap and stack addresses defined as such :

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

And with the __initial_sp set in the vector table and exported as you shown using EXPORT.

The linker error (see the Compiler Errors and Warnings Reference Guide) you have can come :

  • Either from a missing file, explicitly. Perhaps you accidentally deleted the file in the Project hierarchy view, or excluded it from build.
  • Or from an invalid file setting within Keil. I believe this might be your issue here : your assembly file is considered by the compiler rather than the assembler, leading to no object file being generated, and consequently, to a linker error. Right click on your assembly startup file, click on "Options for File [...]", and confirm that the file is considered as an Assembly file instead of a Source file. You might also check how the assembly is understood by the assembler by going into the Asm panel of this window, and check that is is set on Auto Select (e.g. if this startup file is for MDK-ADK use only, without multiple asm supported within, like it is done for some STM32 products and the ResetHandler assembly file).

Regarding the crash you got after commenting :

OS_SysStackBaseAddr = (unsigned long) &Stack_Mem;
OS_SysStackSize = (unsigned int) ((unsigned long)&__initial_sp - (unsigned long)&Stack_Mem);
OS_SysStackLimit = (unsigned long) &__initial_sp;

The issue here is that the OS has no memory initialization, resulting in undefined behavior for the value those variables have. Even if you manage to start your OS tasks, at some point in the execution, without valid memory ranges it can work with, it might stackoverflow or lead to an invalid memory access / hardfault depending on the memory you tried to access.