cpq / bare-metal-programming-guide

A bare metal programming guide (ARM microcontrollers)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

build problem for stm32f411re

dimitri1949 opened this issue · comments

Hi!
I have Nucleo-64 stm32f411re and MikroelEktronica+ stm32f407zg boards,
adapting example code to f411re and f407zg worked perfectly with 2023 February version with manually added include directory and startup.c (modified obviously).

Current examples with SOURCES += cmsis_f4/Source/Templates/gcc/startup_stm32f411xe.s do not build
with errors:
in func. LoopFillZerobss in startup_stm32f411xe.s -- undefined reference to SysInit
in __libc_init_array.. -- undefined reference to _init
It seems that some path is now broken since startup_stm32f411xe.s and startup_stm32f429xx.s look very similar.
build error for 411re

Also copying 200MB of files every time when new version of a project is created seems inefficient.
I copied cmsis_core and cmsis_f4 directories (dowdloaded by git clone..) to d:\gcc-arm\Work\ directory, but how to modify Makefile to access them is a mystery for me, pleaser help.

Best regards
dimitri1949

Hello!

A quick fix is to add a blank _init function in the main.c file.
void _init(void) {}

To access to CMSIS from a Makefile:
Create a variable in the Makefile, i.e. CMSIS_CORE_PATH=d:\gcc-arm\Work\cmsis_core, and use it with $(CMSIS_CORE_PATH).

BR
gillesxr.

Hello and thanks for your help!

With void _init(void) {} in main -- compiled without errors, but did not work when flashed, obviously.
Without _init in main -- in function __libc_init_array..init.c (.text.__libc_init_array+0x14) -- undefined reference to '_init' error.
This is a version of a project with local cmsis_core and cmsis_f4 directories downloaded by 'git clone' as in original example for stm32f429 (it compiles without problems).

With another project version (without local cmsis_core and cmsis_f4 directories) i used
CMSIS_CORE_PATH=d:\gcc-arm\Work\cmsis_core
CMSIS_PATH=d:\gcc-arm\Work\cmsis_f4
....
firmware.elf: $(CMSIS_CORE_PATH) $(CMSIS_PATH) hal.h link.ld Makefile $(SOURCES)
arm-none-eabi-gcc $(SOURCES) $(CFLAGS) $(CFLAGS_EXTRA) $(LDFLAGS) -o $@
as you suggested, with exactly the same result. So it seems that PATH setting works, but ld.exe do not see correct '_init' as with stm32f429.
And this is linker error actually. Some h file is broken?
I compared startup_stm32f429xx.s and startup_stm32f411xe.s and only differences i see are interrupt handlers, more for 429.
I have also μe+ stm32f407zg and Wiz550web.stm32f103rb boards, i will try with them.
I am sure problem must be close to startup_stm32f411xe.s, because last winter project version with startup.c works.

BR
Dimitri

Hello!

I modified step-5-cmsis example project for stm32f411 from scratch, essentially changing only:
hal.h:
#include "stm32f429xx.h" -> stm32f411xe.h
UART3 -> UART6

main.c:
led -> LED_PA5

link.ld:
MEMORY
{ /* stm32f411re */
flash(rx) : ORIGIN = 0x08000000, LENGTH = 512K
sram(rwx) : ORIGIN = 0x20000000, LENGTH = 128K
}

MakeFile:
SOURCES += cmsis_f4/Source/Templates/gcc/startup_stm32f429xx.s ->
SOURCES += cmsis_f4/Source/Templates/gcc/startup_stm32f411xe.s

and now it works!
So all problems where my fault!

BR
Dimitri