Setting up open-source STM32 developing environment on ARM Eclipse

Different from ‘STD’ lib, STM32 ‘HAL’ lib is more compatible to hardware development and is now well-supported by ST company’s Cube IDE.

Prerequisites

ARM gcc compiler

Cross compilers for ARM EABI(bare-metal) target:

arm-none-eabi-gcc
arm-none-eabi-newlib
arm-none-eabi-gdb

Check by arm-none-eabi-gcc -v

Eclipse

eclipse-cpp

Menu > Help > Install new software… > Add
Name: GNU ARM eclipse
Location: http://gnuarmeclipse.sourceforge.net/updates
add-plugin.png

Then select at least ‘GNU ARM C/C++ Cross Compiler’, ‘GNU ARM C/C++ STM32Fx Project Templates’, ‘GNU ARM J-Link Debugging Support’ and ‘GNU ARM C/C++ Packs’. If there emerges any warnings about key checks, install anyway.

In order to select device, go to check packages location at Window > Preferences > C/C++ > Packs

Debugger

jlink-software-and-documentation

1
sudo pacman -S st-link

Run > Run as > External tools setting > new a config called st-linkv2
st-link-v2.png

Note that ${project_loc} is automatically set as a variable of current project location as well as the ${project_name}

Then run.

In the routine, we will get an error from Console like:

1
2
3
4
5
6
7
2019-08-19T18:07:07 INFO common.c: Loading device parameters....
2019-08-19T18:07:07 INFO common.c: Device connected is: F4 device, id 0x100f6413
2019-08-19T18:07:07 INFO common.c: SRAM size: 0x30000 bytes (192 KiB), Flash: 0x100000 bytes (1024 KiB) in pages of 16384 bytes
open(DeFly-STM32F407-board-template.bin) == -1
2019-08-19T18:07:07 ERROR common.c: map_file() == -1
st-flash 1.5.1
stlink_fwrite_flash() == -1

flash-error.png

But don’t worry because we will fix it immediately.

Go to Project > Properties > C/C++ Build > Settings > Cross ARM GNU Create Flash Image > General > Output file format, Choose ‘Raw binary’. Then it’s ok:
flash-ok.png

Note that J-Link is not opensource, so we don’t like it on Linux.

Create new project

Native ARM Eclipse HAL

To enable HAL support, change #if 0 to 1 in _initialize_hardware.c.
New a C project > STM32F4xx C/C++ Project(Toolchains: Cross ARM GCC)

Create a C project

On the next page uncheck ‘Use newlib nano’ because we intend to use HAL library
Uncheck newlib

Folder settings: keep the default.

Select Configurations: both debug and release.

Cross GNU ARM Toolchain: choose arm-none-eabi-gcc
choose toolchain
Finish and wait for creating.

Build setting

Windows > Preferences > General > Workspace > Check ‘Always close unerlated projects without prompt.
close-unrelated-projects.png

Error:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/usr/lib/gcc/arm-none-eabi/9.2.0/../../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.0/../../../../arm-none-eabi/lib/thumb/v7e-m/nofp/libg_nano.a(lib_a-writer.o): in function `_write_r':
writer.c:(.text._write_r+0x10): undefined reference to `_write'
/usr/lib/gcc/arm-none-eabi/9.2.0/../../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.0/../../../../arm-none-eabi/lib/thumb/v7e-m/nofp/libg_nano.a(lib_a-closer.o): in function `_close_r':
closer.c:(.text._close_r+0xc): undefined reference to `_close'
/usr/lib/gcc/arm-none-eabi/9.2.0/../../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.0/../../../../arm-none-eabi/lib/thumb/v7e-m/nofp/libg_nano.a(lib_a-lseekr.o): in function `_lseek_r':
lseekr.c:(.text._lseek_r+0x10): undefined reference to `_lseek'
/usr/lib/gcc/arm-none-eabi/9.2.0/../../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.0/../../../../arm-none-eabi/lib/thumb/v7e-m/nofp/libg_nano.a(lib_a-readr.o): in function `_read_r':
readr.c:(.text._read_r+0x10): undefined reference to `_read'
/usr/lib/gcc/arm-none-eabi/9.2.0/../../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.0/../../../../arm-none-eabi/lib/thumb/v7e-m/nofp/libg_nano.a(lib_a-fstatr.o): in function `_fstat_r':
fstatr.c:(.text._fstat_r+0xe): undefined reference to `_fstat'
/usr/lib/gcc/arm-none-eabi/9.2.0/../../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.0/../../../../arm-none-eabi/lib/thumb/v7e-m/nofp/libg_nano.a(lib_a-isattyr.o): in function `_isatty_r':
isattyr.c:(.text._isatty_r+0xc): undefined reference to `_isatty'
collect2: error: ld returned 1 exit status
make: *** [makefile:64: F4cubeBlinky.elf] Error 1

This happens might because I use HAL lib but not the newlib, I solved it by open Project > Properties > C/C++ Build > Settings > Cross ARM GNU C++ Linker > Miscellaneous, Uncheck ‘Use newlib -nano (–specs=nano.specs)’ and add ‘-specs=nosys.specs’.

Before:
Before change linker option

After:
After change linker option

STD lib

STM32CubeMX generated HAL

We need to install STM32CubeMX for generating HAL fw-lib template codes.

1
2
3
git clone --depth=1 https://aur.archlinux.org/stm32cubemx.git
cd stm32cubemx
makepkg -si

Then config for our microchip

Now we can generate code for it

Now we can use Eclipse to create a template project. And delete the files. Then drag and copy.

drag-and-copy-using-file-manager.png

Don’t forget the link file, also we drag and copy into startup folder.
ld-file-drag-and-copy.png

Or you can use mv commands to manipulate and click ‘Refresh’ under Eclipse project.

Next are modifications of projects.

  1. change .s startup file to .S uppercase one.
  2. Go to project properties > C/C++ BUild > Settings. Delte other proprocessors and then add Preprocessor: STM32407xx and USE_HAL_DRIVER, Add includes files… then linker delete the already existed items and check using startup files, then add our new starup .ld file.

Debug settings

Go to Window > Preferences > Run/Debug > SEGGER J-Link to check the path of J-Link.

By default, the GDB server is defined as ${jlink_path}/${jlink_gdbserver}; these two macros are automatically set by the above preference page; for portability reasons, it is recommended to keep this definition in all your debug configurations.

After successfully built the project and see a .elf file generated, go to Debug Configurations and create a new item for J-Link Debug.

Add breakpoint in a while statement. Then open the server by Menu > Run > External Tools > ST-Link GDB Server (SWD). Console ouput is like:

Then edit debug configuration:

debug-setup1.png

debug-setup2.png

Then click ‘Debug’ and happily to see:
confirm-perspective-switch.png
Click Switch, then we go into debug window:
debug-startup.png

When encounting a dead loop between two statements, it’s because you didn’t press reset button. Yes, in debug mode, pressing reset button is necessary. So click and voila:
go-into-break-point.png

We enter our breakpoint successfully.

Aug-28th-HackRF-SCCE-access-door-system Linux Troubleshooting

Comments

You forgot to set the shortname for Disqus. Please set it in _config.yml.
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×