Blink on STM32F030

Stavros Kalapothas
3 min readMay 20, 2020

--

Back to basics

Below is a short write-up on how to upload a basic code example (blink) on a STM32F030 microcontroller.

The specific chip contains an ARM Cortex-M0, a low-power, 32-bit RISC core and it is available in many form factors. There are also a lot of development boards available carrying this mcu. The ‘demo board’ that I have is quite small and it is well seated in the low price range:

actually, it is nothing more than a break-out board with a 3.3v regulator, a reset button, a power led, the gpio pins and a gpio(user) led.

The key features of the STM32F030F4, below:

  • 32-bit ARM Cortex-M0 CPU rated for 48MHz clock (max)
  • 4kB SRAM
  • 16kB Flash
  • 5 Timers
  • 1 SPI
  • 1 I2C
  • 1 USART
  • RTC
  • 15 GPIO pins (4 are 5V tolerant)
  • 1 12-bit SAR ADC with 11 input channels

Firmware upload is done via the available serial connection (e.g. using an FTDI adapter) or via the serial wire debugging (SWD) interface using a ST-Link compatible programmer. Both ports are available in the yellow pins on the one side of the pcb. There is also a micro-usb port that is solely responsible for powering up the board.

Before uploading though, I first need to identify the pin-out and connections on the board. In order to find which pin is connected to the user LED, I looked inside the STM32 Base, a great documentation project for all the STM32 based boards released in the market (cool!).

Now that I have all these details sorted, it’s time to code, well… not quite

Another thing that I need to select and configure is the IDE. More specifically, to enable support for the target board. Thankfully, there are a lot of alternative IDEs (STM32CubeIDE, GNU-MCU-Eclipse, Visual Studio, etc), Keil-MDK Lite edition is chosen and further described below:

Open New Project, choose Target Options and configure:

  • Device (select series STM32F030F4Px)
  • Target (Ram/Rom/Xtal)
  • Debug (ST-lnk debugger)

Before start coding, I need to download the datasheet which will help to identify all the M0 registers need to be programmed and used inside the code to control the i/o ports. GitHub, is also a useful resource, providing a ton code snippets. Therefore, the blink code is ready:

To comment a bit one code the above, the ODR_4 register is responsible for the PA4 (led pin) and triggered inside the loop. A mandatory initialization for the GPIO Port A is also needed by using the corresponding registers (set GPIOA enable, output, low speed, etc) lastly, is the RCC (control clock register) declaration and the use of high speed internal clock (HSI). The specific board is using 8MHz crystal.

code is ready to compile:

connect st-link to the board:

last step to upload firmware:

finally… Blink!

--

--

No responses yet