Practical FFT on microcontrollers using CMSIS DSP

Fourier transform is a vast domain of knowledge with many practical applications within signal processing. Virtually all communications protocols use Fourier transform at one step or another (including LTE, GPS and WiFi). Another popular example are the “jumping bars” in music players showing levels of low and high tones in real time. In this post I show the basics of obtaining spectrum of an audio signal on an EFM32 Cortex-M3 microcontroller. No scary math!
Continue reading “Practical FFT on microcontrollers using CMSIS DSP”

EFM32 Cortex-M firmware project from scratch – step by step

Most popular microcontrollers come with IDEs and tools provided by the manufacturer, like NXP, STM, TI or Silicon Labs. IDEs are commonly based on Eclipse and creating a project for almost any chip in those IDEs is usually just a click away, so why would you ever want to make such a project from scratch, gather all header files, libraries and scripts? Read to find out why and how 🙂
Continue reading “EFM32 Cortex-M firmware project from scratch – step by step”

Using the internal EEPROM of STM32L

Most STM32 microcontrollers feature an internal EEPROM. It is useful for storing settings or calibration data. Regular flash (that stores code) can also be used, but the EEPROM can be updated byte-by-byte and is independent from regular flash. This may come handy during application updating, as whole flash can be simply erased without affecting the EEPROM.

I wrote a generic driver for keeping settings in the EEPROM based on the standard peripherals library for STM32L, that is easier to understand than the official demos from ST. It was tested on an STM32L151RC.
Continue reading “Using the internal EEPROM of STM32L”

Open OBD datalogger

This is a fully open-source car datalogger that reads engine data using the OBD2 interface in real time and stores it on an SD card. It also stores GPS data. All communication is done directly by the MCU without a translator chip like ELM327 or STN1110. The datalogger supports all CAN and K-Line OBD2 protocols. All hardware fits into an off-the-shelf OBD2 connector enclosure.

This project is available on Github.

Continue reading “Open OBD datalogger”

Kinetis E – writing to internal flash

While working on a bootloader for a Kinetis KE06 I obviously ran in to the task of having to write the internal flash memory of the microcontroller. Freescale’s driver is over 1500 lines of code, exposes every single bit of the flash controller so the simple operation of erasing a sector and writing to it requires many function calls. I wrote my own driver that is less than 200 lines of code and has everything needed to make a bootloader.
Continue reading “Kinetis E – writing to internal flash”

Hard fault in __libc_init_array

When starting my STM32 makefile project for the first time I encountered a very early hard fault in the startup code. It happened exactly when calling libc function at

The whole startup code came straight from ST, so I did not suspect it to be faulty. Here is what I have found out to fix the problem.
Continue reading “Hard fault in __libc_init_array”

Reading OBD2 data without ELM327, part 2 – K-Line

K-Line is another popular OBD2 interfacing standard, that has been used in European cars before CAN bus became common. There are a couple of physical variations (K-line, K+L, KKL) and slightly different protocols (KWP2000 or Keyword Protocol, and ISO 9141) running on those lines. Basically all you need to talk to an older car is an MCU with a UART and a single transistor. 🙂
Continue reading “Reading OBD2 data without ELM327, part 2 – K-Line”

Reading OBD2 data without ELM327, part 1 – CAN

All modern cars have an OBD2 diagnostic connector that allows reading many engine and drivetrain parameters like RPM, vehicle speed, temperatures etc.

Most of car interfaces use a special protocol translating chip like ELM327 or STN1110 to convert different vehicle protocols (that depend on the age and brand of the car) into an easier to use serial protocol with AT-commands.

I wanted to build a datalogger that would fit into a OBD2 connector. There was no space to fit my microcontroller and another chip to do protocol conversion, so I investigated and reverse-engineered the most common OBD2 protocols to be able to implement them directly on my MCU.
Continue reading “Reading OBD2 data without ELM327, part 1 – CAN”

FreeRTOS on Kinetis E Cortex M0+ : easy porting tutorial

FreeRTOS is a popular, open-source operating system that can run on a variety of microcontrollers. This post shows how to make a minimal working setup with two tasks on a new MCU without starting from a complete demo code or code generators (like Processor Expert) on an inexpensive development board FRDM-KE06Z from NXP. All examples use static memory allocation. Most of the procedures and tips mentioned here apply equally well to all Cortex-M microcontrollers.
Continue reading “FreeRTOS on Kinetis E Cortex M0+ : easy porting tutorial”