STM32 and Arduino

STM32 is a family of 32bit microcontrollers manufactured by STMicroelectronics and based on the ARM Cortex M core.

The STM32 family is divided into different lines of microcontrollers (L0-1-4, F0-1-2…) depending on their features and the use they are designed for:

stm32-16

These microcontroller are widely used in the industrial world… for example both Pebble watches and Fitbit bracelets are based on STM32 MCUs.

If you’re interested in quadricopters or drones, you probably have heard or used F1, F3, F4 flight control boards. The board name (“F…”) indicated indeed the STM32 microcontroller they are based on.

Thanks to the work made by the stm32duino community and to the support of ST itself, starting from the past June STM32 microcontrollers can be easily used with the Arduino IDE and it’s also possible to take advantage of most of the libraries available for Arduino.

I decided to buy a minimal development board based on the STM32F103C8T6 microcontroller (these boards are sometimes known as blue pills); let’s see how to use it with Arduino.

Bootloader

Many boards are sold unprogrammed: the first thing to do is therefore to program a bootloader, that is a small program which will allow to upload the “real” program via USB port.

To flash the bootloader, you need an USB -> serial adapter, connected to your dev board as it follows:

  • RX -> A9
  • TX -> A10
  • VCC -> 5V
  • GND -> GND

stm32-18 stm32-19

You have also to enable the programming mode, moving the first jumper (labeled BOOT0) to position 1:

stm32-17

Now you need a software to flash the file with the bootloader into the chip. If you’re under Windows, you can download the Flash Loader from ST’s official website: after having registered (for free) you’ll receive the download link via email.

The bootloader is developed and maintained by Roger Clark and it’s available in his Github repository. For STMF1 boards there are several binary files, depending on the PIN the onboard led is connected to. My board uses P13, so I downloaded the file generic_boot20_pb13.bin.

Run the Demonstrator GUI program and select the serial port your adapter is connected to:

stm32-03

If all the connections are ok, the software should be able to detect the microcontroller:

stm32-04

Now you can select the specific MCU your board uses:

stm32-05

then select the file with the bootloader and program it. To be sure, you can ask the software to perform also a global erase of the memory:

stm32-06

The program will flash the chip and, when complete, will confirm the operation with a message:

stm32-08

If you now move back the BOOT0 jumper to the original position, you should see the led blink: this means that the bootloader is running and can’t find a program to execute… now it’s time to configure the IDE.

Arduino IDE

Open your IDE and select File – Preferences. Type the following address in the Additional Boards Manager URLs field:

https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json

stm32-00

Now open the Boards Manager:

stm32-01

Search STM32F1 and install the corresponding Cores package:

stm32-02

You’re almost ready to compile and run your first program…

Drivers

Connect the dev board to your PC using an USB cable and verify how it is identified.

It may happen that Windows cannot correctly identify the board and displays it as Maple 003, is this case you have to install the correct drivers:

stm32-09

Download the following files from Clark’s repository:

  • install_STM_COM_drivers.bat
  • install_drivers.bat
  • wdi-simple.exe

Run the two .bat:

stm32-10

now Windows should identify the board correctly:

stm32-11

Sometimes Windows cannot see the additional serial port of the board. To solve the problem, you can try to program on the board a simple sketch that uses the Serial object. Open for example the blink sketch and change it as it follows:

stm32-12

Program the sketch choosing BluePill F103C8 as board and STM32duino bootloader as upload method.

Once the sketch is programmed and executed, Windows should detect and install the new COM port:

stm32-14

You’re done, now the board is fully integrated with the Arduino IDE:

stm32-15

Hacking the DPS5005

pics-OpenDPS-600

Johan Kanflo’s OpenDPS project, a free firmware replacement for the DPS5005:

This write up of the OpenDPS project is divided into three parts. Part one (this one) covers reverse engineering the stock firmware and could be of interest for those looking at reverse engineering STM32 devices in general. Part two covers the design of OpenDPS, the name given to the open DPS5005 firmware. Part three covers the upgrade process of stock DPS:es and connecting these to the world. If you only want to upgrade your DPS you may skip directly to part three.

More details at Johan Kanflo’s blog.

BlackMagicProbe SMDprutser style

BlackMagicProbe

Sjaak has published a new build:

When you get started on ARM microcontrollers things are very overwhelming at first… After coping with the first few hurdles like installing a toolchain and IDE, the next part should be getting a tool to program the chip. Many vendors have some kind of bootloader burned in the chip, which can’t be altered. Some manufacturers use serial, some use USB (mass-storage, DFU or HID). Unfortunately every vendor has it own implementation and they aren’t compatible with each other and may require special hardware. This can make it hard(er) for you to change between vendors. Another downside is your code can only be debugged by ‘printf” and not ‘realtime’.

More details at smdprutser.nl.

 

First GD32 tests

gd32f103-1080x675-600

Sjaak has published a new build, the STM32/GD32F103 QFN32 breakout board:

Uptill now I used 0603 sized resistors and capacitors but for this project I switched to 0402 to save a few mm on the board. I have soldered many challenging chip packages so I felt confident. The technique is the same as for bigger sized devices: flux the area generous, hold the device with tweezers, solder one pad with fresh soldered iron and move the device into the molten solder puddle, retract the soldering iron and watch the solder joint cool down. If the solder joint is solid solder the other side too. I suggest using a fine (curved) tweezer and lots of lighting on your workarea. If you are a bit older as I am using a loupe or magnifying glass. Still use flux as much as possible. Never expected but the micro USB connector gave me (several) headaches to get it soldered properly.

Project info at smdprutser.nl

 

Walking the 32bit path to a blinky LED

32bitbling-1080x675

Sjaak writes:

The battle isn’t AVR Atmega vs Microchip PIC anymore.. More and more people are moving to ARM chips. As easy as it sounds but it isn’t. ARM is an company that invented the ARM chips, but doesn’t has a silicon fab, instead they license the design to several silicon manufacturer like ST, NXP, xx and all those manufacturer put their own sauce and peripherals to the basic design. Nice to have such a large diversity, but when unfamiliar with ARM in general it is a bit overwhelming and hard to choose from. An other ‘problem’ is the vendors don’t offer a complete development kit to instantly start with their chips.
After browsing ebay for arm starterkits, STM32 seems to be a reasonable starting point as it appears to me most development boards are using this chip. ST doesn’t offer a development kit as I expected. so i try to find a more ‘generic’ development kit. After googling for a couple of hours I almost give up on this and wanted to stick with Microchip forever. I asked a bit round in my networks of ‘geeks’ and found everyone was struggling with this. Charles of paxinstruments.com pointed me into the direction of Eclipse. Eclipse is a general IDE with support throught plugins for various compilers and platforms. I tried to follow their installation guide found here.

More details at smdprutser.nl blog.

Therm RTD

therm_rtd_full-600x400

Matthew Reed writes:

Therm RTD is an addition to the Therm PID Controller family, with support for RTD temperature sensors. RTDs (or Resistance Temperature Detectors) use a coil of fine wire made from a material (usually platinum, copper or nickel) that has a very predictable temperature coefficient of resistance (or change in resistance as temperature changes). RTDs are generally more accurate and stable than thermocouples, and have a much greater range than thermistors – although they can tend to be more expensive than both.

More details at Protofusion.org.