STM32Cube code initialization for “blue pill”

 Author:   Posted on:    1 comment
Lately I’ve playing around with the STM32F103 development board known as “blue pill”. Developing software for it is not as easy as for Arduino boards. The MCU contains a 32-bit ARM CPU. I have previously tried to write software for this board using HAL library, but I didn’t get the most out of it because I found the programming model rather complicated.

One of the methods to develop software for this MCU is to use ST HAL library (which uses a higher level API than other libraries for this MCU). I chose the Eclipse IDE with a set of plugins for STM32 family. There is an easier way to get the SDK and IDE with the toolchain called System Workbench for STM32 (recommended by ST too). This is the download directory where you can find all releases for the major operating systems. But before creating a blank project in SW4STM32, you should know that there is a tool which can create this project for you. Not quite blank, as you will configure the MCU with a graphical tool in a step-by-step process.

STM32Cube code initialization for “blue pill”

STM32 “blue pill” easy development with Mbed

 Author:   Posted on:    No comments
The "blue pill" is an STM32F103 based development board. Although it is less popular, the board is cheaper than an Arduino Nano. More than that, STM32F103 is a device with Cortex-M3 ARM CPU that runs at 72 MHz, 20 kB of RAM and 64 or 128 kB of flash memory. The microcontroller (MCU) has USB port, two serial ports, 16 bit PWM pins and 12 bit ADC pins. It runs at 3.3V, but some of its pins are 5V tolerant.

I tried to program this development board using both Arduino IDE and STM32 HAL, but I wasn’t quite satisfied. Arduino framework is simplified and does not take advantage of platform’s features, while HAL was quite difficult for me. Using HAL in Eclipse come with another disadvantage: direct uploading of the binary in flash didn’t work, so I had to use ST-Link tools to upload it, outside of Eclipse. Recently I heard of PlatformIO IDE. This is a development environment supplied as Visual Studio Code or Atom plugin. One of its great advantages is the support for more than 500 development boards! Although VS Code and Atom are cross platform software, they are not at all lightweight, so you’ll need rather good hardware to run them smoothly.

Another great feature of PlatformIO is that for a development board you have multiple framework options. You can program the bluepill using Arduino API, just as you would do in Arduino IDE. Or you can program it using STM32Cube API. But, there is also Mbed OS framework, which I found it to be quite easy to develop.

STM32 “blue pill” easy development with Mbed

How to Count Frequency with Arduino

 Author:   Posted on:    No comments
Counting frequency using an Arduino seemed like an easy task. But most people like to do it the easy, but wrong way: using pulseIn to measure width of a pulse. This limits the maximum frequency that can be measured to about 50 kHz. Besides that, the function samples only a cycle of the signal.

A good way of measuring frequency is by counting input signal transitions that happen in a specific amount of time. This requires knowledge of timers and interrupts. The method is more difficult to implement and to do it right you need to set some registers.

This has been done before and although it was hard to find, I discovered code that can count frequencies up to 8 MHz if the input signal has a duty cycle of 50%. The only drawback is that frequency input pin is fixed to digital pin 5. The upper range is however not limited to only a few MHz. With some extra hardware (a prescaler IC) frequencies of hundreds of MHz can be measured with enough accuracy.
How to Count Frequency with Arduino