# Setting up and getting started with STM32 on Fedora

After Jetbrains released Clion with native support for embedded programming, I thought it was time to check it out. Apparently they started out with the STM32 platform and providing and well-defined workflow.
So I got myself an STM32F031K6 and started to set the whole thing up on my Fedora laptop.
STM32F031K6 specs

First of all, I installed some basic programs (they're basically the avrdude of the STM world) - including the debugger.

dnf install stlink-gui stlink-devel stlink openocd

Plug your device and run

st-info --probe

which should give you something like

Found 1 stlink programmers
 serial: 303636384646333433333339343135
openocd: "\x30\x36\x36\x38\x46\x46\x33\x34\x33\x33\x33\x39\x34\x31\x35"
  flash: 32768 (pagesize: 1024)
   sram: 4096
 chipid: 0x0444
  descr: F0 small device

Next you'll have to download the STM32CubeMX software. Unfortunately, you'll have to provide your email where you'll get a URL to finally download (seriously STM, this is kinda silly). STM32CubeMX

Of course, you'll need Clion too. It's not free, but it can be if you're a student or a developer working on open source projects! Clion

Next I tried to install the GNU Embedded Toolchain for Arm suite of tools, but the ones available on Fedora were version 7.4.something (Fedora 30 at the time of writing) so I just went ahead and downloaded them directly from their website, where the 8.1.something was the latest available. GNU Embedded Toolchain Simply unpack it wherever you want and add it to your $PATH. After running

arm-none-eabi-gcc --version

you should see something like

arm-none-eabi-gcc (GNU Tools for Arm Embedded Processors 8-2018-q4-major) 8.2.1 20181213 (release) [gcc-8-branch revision 267074]
Copyright (C) 2018 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.

Now on Clion create a new project (selecting STM32CubeMX) and give it a name of your choice.

For the next steps, simply follow the instructions in the links below

Clion + STM32 setup part 1
Clion + STM32 setup part 2

and for debugging keep reading
Clion + STM32 setup part 3

Just to test if it's all working as it should, add something like the following in the while loop of your main.c file (you'll have to set the GPIO A2 (PA3) as output in STM32CubeMX)

HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_3); //Toggle LED
HAL_Delay(3000); //Delay 3 Seconds

Build your project and if it's successful, run

st-flash write project_name.bin 0x8000000

That should be enough to see your beautiful LED toggling every 3 seconds!

PS: this is a small tutorial that I plan to update with fixes and improvements, so come back every now and then 😃