Currently I try to use the STM32L0 microcontroller series. I found that ST offers a low-level C program collection called STM32SnippetsL0 too, parallel with their complex STM32CubeMX based HAL API. Unfortunately I can not use the codes under GNU/Linux because it supports only EWARM and MDK-ARM toolchains. Are there any possibilities to run this code with the GCC ARM Embedded toolchain?
-
\$\begingroup\$ sounds like a stackoverflow question. why cant you use ewarm? what libraries are not working? can you link in the other libraries? ewarm is a gnu compiler toolchain as well yes? so you should be able to link them in. \$\endgroup\$– old_timerCommented Dec 25, 2015 at 22:35
-
\$\begingroup\$ Thank you for your hints @dwelch. AFAIK EWARM is based on the C compiler of IAR Systems. It runs only under Windows and I want to find a GNU/Linux based solution. \$\endgroup\$– kaliczpCommented Dec 26, 2015 at 7:38
-
\$\begingroup\$ ahh sorry I was thinking of a different compiler, a gnu based cross compiler for windows, nevermind...you might still be able to link, and/or if they have the source code to the library you can re-compile. I cant imagine that st delivers the board/chip support package without sources somewere and/or without a gnu based set of libraries. If they dont offer that then I wouldnt bother with it and find another solution \$\endgroup\$– old_timerCommented Dec 26, 2015 at 14:13
1 Answer
After long experiment I can say it is possible to compile the STM32Snippets with the GCC ARM Embedded toolchain. The Snippets contains itself the necessary files except the linker file. I used a linker file copied from STM32CubeMX (SW4STM32 template) but I think other scripts are also usable.
It is necessary to copy two files from the Snippets template folder (Drivers/CMSIS/Device/ST/STM32L0xx/Source/Templates). The first is system_stm32l0xx.c and the second the appropriate startup assembly file from gcc sub-folder. (Yes it seems to partial support for gcc.) I used startup_stm32l053xx.s because I use Nucleo board. If the downloaded Snippets is extracted to the folder snippets and arm-none-eabi-gcc is in your path you can use the following code:
arm-none-eabi-gcc -DSTM32L053xx -Wall -g -mthumb -mcpu=cortex-m0plus -march=armv6-m -mlittle-endian -Isnippets/Drivers/CMSIS/Include -Isnippets/Drivers/CMSIS/Device/ST/STM32L0xx/Include -Wl,--gc-sections,-Map=main.map -Tstm32l053xx.ld -L. system_stm32l0xx.c startup_stm32l053xx.s main.c -o main.elf
Finally bin is produced to upload to Nucleo.
arm-none-eabi-objcopy -O binary main.elf main.bin