Generating signals with STM32L4 timer, DMA and DAC

Generating arbitrary signals using an MCU is extremely useful. It can be used for example to play back any audio or make a modulator for a modem. The most needed MCU peripheral is of course a DAC, but it also needs other peripherals to efficiently play back the samples without loading the CPU.

This post shows how to implement a signal generator on an STM32L432 without using HAL libraries.

Continue reading “Generating signals with STM32L4 timer, DMA and DAC”

Cortex-M – Debugging runtime memory corruption

Runtime memory corruption is one of the worst class of bugs a C/C++ application can have. I do not mean design problems like abuse of global variables, but seemingly correct code clobbering memory it should never touch (for example due to runaway pointers). Compared to “regular” crashes that are obvious and much simpler to fix (even if they are rare they leave a stacktrace), memory corruption is often silent. It can go unnoticed for a long period and manifest itself in subtle ways. For example: the application sometimes acts weirdly or a particular variable is sometimes wrong. Fortunately Cortex-M3 and M4 cores are equipped with special hardware that can assist in catching rogue memory accesses.
Continue reading “Cortex-M – Debugging runtime memory corruption”

Preserving debugging breadcrumbs across reboots in Cortex-M

Debugging embedded systems during development even with the best tools can be hard. Certainly a good debug probe makes life easier, but what do you do after the product is shipped? What if the customer complains that something strange is happening sometimes or a bug makes the device reboot, but only once a week? You make the firmware gather diagnostic information for you. This is the first post in series.
Continue reading “Preserving debugging breadcrumbs across reboots in Cortex-M”

Reducing firmware size by removing libc

The C standard library (libc) is a component that gets little attention. It is just there. However for embedded systems it brings some challenges and overhead in terms of code size. As firmware size is often critical, it sometimes makes sense to use a trimmed version of the standard library or to remove it entirely. I will focus on reducing the code size that may be beneficial for a small application like a bootloader.
Continue reading “Reducing firmware size by removing libc”

Fixing Cortex-M startup code for link-time optimization

Link-time optimization is a powerful output size reducing feature. Even though (as of 2018) still regarded as somewhat experimental, LTO is worth trying, if the binary size is very important and the application can be reliably tested afterwards, as link-time optimized code is hard to debug. A bootloader can be an ideal example. LTO is very easy to enable, but there are some small quirks that have to be taken care of. I will use GCC 7.2.1 from GNU Arm Embedded as an example.
Continue reading “Fixing Cortex-M startup code for link-time optimization”

Disk space monitoring & e-mail notifications with Bash

Running out of disk space is a common problem for unattended Linux boxes like database servers or backup storage servers. Usually I would use Zabbix (or Nagios) do to the monitoring, but it would be an overkill for a Raspberry Pi or a single NAS, so I made a small Bash script. This script runs df, checks disk usage and sends mail in case the free space is running low.
Continue reading “Disk space monitoring & e-mail notifications with Bash”

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”

Bell 202 modem for AVR and other MCUs

Bell 202 is a quite old modem standard that is still used today in amateur radio for data transmission over VHF (Packet Radio and APRS) and industrial automation (HART). It is a very simple FSK modem. The speed is limited to 1200 baud, which makes it very easy to implement on any small microcontroller. My implementation is built on top of sinewave generator code for XMEGA described in a previous post.

Continue reading “Bell 202 modem for AVR and other MCUs”

Making sinewaves with XMEGA DAC

The XMEGA is quite a leap from the “classic” AVRs. Some of the interesting features are the DAC and DMA. When combined, they can be used to generate all kinds of useful signals in the audio range.

This example uses the DAC, DMA, timer and event system to generate 1200 Hz and 2200 Hz sinewaves. I’ll show how to make a Bell 202 modem (think: APRS and AX.25) in another post.
Continue reading “Making sinewaves with XMEGA DAC”

Git – checking JavaScript files for debugger statements

We developers, when working on a common codebase, often step on each other’s toes. Recently, while debugging code of a complex application server I have been hit with JavaScript debugger statements placed by another developer all around, that should not get to the common branch. So what is better than complaining to your colleagues to be more careful every time they commit code? Present them with a Git hook that does the checking for them and solves the problem once and for all 🙂 This hook is an expansion of the previous one.
Continue reading “Git – checking JavaScript files for debugger statements”