Compile on Ubuntu Linux
sudo add-apt-repository ppa:team-gcc-arm-embedded/ppa
sudo apt-get update
sudo apt-get install gcc-arm-none-eabi
Test the installation:
arm-none-eabi-gcc --version
Should output something similar to this:
arm-none-eabi-gcc (GNU Tools for Arm Embedded Processors 7-2018-q3-update) 7.3.1 20180622 (release) [ARM/embedded-7-branch revision 261907]
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
cd ~
cd dev
mkdir helloworld
cd helloworld
vi main.c
paste this text:
int
main(void)
{
while (1);
}
Compile the program:
arm-none-eabi-gcc -std=gnu99 -g -O2 -Wall -mlittle-endian -mthumb -mthumb-interwork -mcpu=cortex-m0 -fsingle-precision-constant -Wdouble-promotion --specs=nosys.specs main.c -o main.elf
You will get an .elf file. It is not an .bin file and cannot be flashed.
https://stackoverflow.com/questions/49680382/objcopy-elf-to-bin-file
Check the elf file
arm-none-eabi-readelf -h main.elf
Convert the .elf file to .bin (Removes the .elf metadata and only leaves raw machine code for the microcontroller to execute)
arm-none-eabi-objcopy -O binary main.elf main.bin
You can now flash the bin file using st-link.
Connect the board using usb.
Check that the board is connected:
/home/wbi/dev/stlink/build/Release/st-info --probe
Flash the binary onto the board. Warning: Flashing a binary onto the board will override the previous content of the board without performing any backup! The previous content is lost and cannot be brought back! If you want to safe the content, first read the flash. Reading the flash is described in another article.
st-flash write main.bin 0x08000000