Nucleo-F429ZI development board with STM32F429 microcontroller

Epic Guide To Bare-Metal STM32 Programming

[Sergey Lyubka] put together this epic guide for bare-metal microcontroller programming.  While the general concepts should be applicable to most any microcontroller, [Sergey]s examples specifically relate to the Nucleo-F429ZI development board featuring the ARM-based STM32F429 microcontroller.

In the realm of computer systems, bare-metal programming most often refers to programming the processor without an intervening operating system. This generally applies to programming BIOS, hardware drivers, communication drivers, elements of the operating system, and so forth. Even in the world of embedded programming, were things are generally quite low-level (close to the metal), we’ve grown accustomed to a good amount of hardware abstraction. For example, we often start projects already standing on the shoulders of various libraries, boot loaders, and integrated development tools.

When we forego these abstractions and program directly on the microprocessor or microcontroller, we’re working on the bare metal. [Sergey] aptly defines this as programming the microcontroller “using just a compiler and a datasheet, nothing else.” His guide starts at the very foundation by examining the processor’s memory map and registers including locations for memory mapped I/O pins and other peripherals.

The guide walks us through writing up a minimal firmware program from boot vector to blinking an LED connected to an I/O pin. The demonstration continues with setup and use of necessary tools such as the compiler, linker, and flasher. We move on to increasingly advanced topics like timers, interrupts, UART output, debuggers, and even configuring an embedded web server to expose a complete device dashboard.

While initially more time consuming, working close to the metal provides a good deal of additional insight into, and control over, hardware operations.  For even more on the subject, you may like our STM32 Bootcamp series on bare-metal STM32 programming.

Hanging Christmas Lights With No Ladder And No Fuss

Getting up on a ladder to hang Christmas lights is a great way to hurt yourself if you’re not careful, and winter conditions only add to the peril. One enterprising hacker has whipped up a neat way to avoid ladders entirely, by hanging their lights while planted safely on the ground.

Result!

The build uses hefty magnets and triangle eye bolts, attached at regular intervals to the string of Christmas lights. The magnets are used to hold the lights to metal roof siding, while the hooks allow the lights to be lifted into place using a hook on a large extendable pole. Washers, spacers, and screws are used to attach the magnets and hooks to the lights.

For a layout that follows the lines of a simple peaked roof, this hack works great. For more complicated installations, you might still have to climb up a ladder. We’ve featured great primers on getting started with advanced Christmas light displays before, if you’re looking to up your game.

Meanwhile, no matter how much you enjoy seasonal decoration brinkmanship, don’t even think about watching Deck the Halls (2006). Danny Devito has saved a lot of films, but he couldn’t save this. Happy holidays!

Bare-Metal STM32: Setting Up And Using SPI

The Serial Peripheral Interface (SPI) interface was initially standardized by Motorola in 1979 for short-distance communication in embedded systems. In its most common four-wire configuration, full-duplex data transfer is possible on the two data (MOSI, MISO) lines with data rates well exceeding 10 Mb/s. This makes SPI suitable for high-bandwidth, full-duplex applications like SD storage cards and large resolution, high-refresh displays.

STM32 devices come with a variable number of SPI peripherals, two in the F042 at 18 Mb/s and five in the F411. Across the STM32 families, the SPI peripheral is relatively similar, with fairly minor differences in the register layout. In this article we’ll look at configuring an SPI peripheral in master mode.

Continue reading “Bare-Metal STM32: Setting Up And Using SPI”

Neodriver Ornament Brightens Up Christmas

Stores will sell you all kinds of gaudy holiday ornaments, but there’s nothing like the style and class achieved by building your own. [w3arycod3r] did just that, whipping up the fun and festive Neodriver Ornament.

It’s a battery-powered build, and runs off an rechargeable 18650 cell which provides several days of operation at a low duty cycle. An ATtiny85 is charged with sending out commands to various NeoPixel devices, from rings to rectangular arrays. [w3arycod3r] then designed various PCBs that could carry the hardware and battery in a well-balanced package that would hang nicely when suspended from a ribbon on a Christmas tree.

As is always the fun part with addressable LEDs, [w3arycod3r] whipped up some fun animations to suit. The 5×5 rectangular arrays of NeoPixels are able to deliver scrolling text, while another animation blips out the RNA sequence of everyone’s least favorite coronavirus, SARS-CoV-2. Getting everything to fit into a ATtiny85’s 8 KB of code space and 512 byte EEPROM was a challenge, but slimming down the Adafruit NeoPixel library and using direct AVR register manipulation in place of regular Arduino functions helped.

Overall, it’s a fun holiday build that looks great on the tree. Alternatively, consider making yourself some rheoscopic ornaments this holiday season. And, if you’ve whipped up your own fun holiday build, throw it on the tipsline!

Bare-Metal STM32: Adding An Analog Touch With ADCs

An Analogue to Digital Converter (ADC) is at its core a straight-forward device: by measuring an analog voltage within a set range and converting the measured level to a digital value we can use this measurement value in our code. Through the use of embedded ADCs in microcontrollers we can address many essential use cases, ranging from measuring the setting on a potentiometer, to reading an analog output line on sensors, including the MCU’s internal temperature and voltage sensors.

The ADCs found in STM32 MCUs have a resolution between 12 to 16 bits, with the former being the most common type. An ADC can be configured to reduce this resolution, set a specific sampling speed, and set up a multi-mode configuration depending on the exact ADC peripheral. STM32 MCUs feature at least a single ADC peripheral, while some have multiple. In this article we will take a look at how to configure and use the basic features of the ADCs in STM32 MCUs, specifically the ADCs found in F0 and the ADC5_V1_1 type as found in most F3-family MCUs.

Continue reading “Bare-Metal STM32: Adding An Analog Touch With ADCs”

The STM32 Makes For A Cheap DIY USB Soundcard

Soundcards used to be giant long 8-bit ISA things that would take up a huge amount of real estate inside a desktop computer. These days, for most of us, they’re baked into the motherboard and we barely give them a second thought. [Samsonov Dima] decided to whip up a cheap little sound card of their own, however, built around the STM32.

The soundcard is based specifically on the STM32F401. readily available on the “Green Pill” devboards. A digital-to-analog converter is implemented on the board based on two PWM timers providing high-quality output. There’s also a simulated software sigma delta ADC implemented between the audio streaming in via USB and the actual PWM output, with some fancy tricks used to improve the sound output. [Samsonov] even found time to add a display with twin VU meters that shows the audio pumping through the left and right channels.

Without test gear on hand, we can’t readily quantify the performance of the sound card. However, as per the Youtube videos posted, it appears more than capable of recreating music with good fidelity and plenty of fine detail.

If you need a cheap, simple USB sound card that you can hack away on, this might be the one for you. If you need something more suitable for a vintage PC, however, consider this instead. Video after the break.

Continue reading “The STM32 Makes For A Cheap DIY USB Soundcard”

Bare-Metal STM32: Using The I2C Bus In Master-Transceiver Mode

As one of the most popular buses today for on- and inter-board communication within systems, there’s a good chance you’ll end up using it with an embedded system. I2C offers a variety of speeds while requiring only two wires (clock and data), which makes it significantly easier to handle than alternatives, such as SPI. Within the STM32 family of MCUs, you will find at least one I2C peripheral on each device.

As a shared, half-duplex medium, I2C uses a rather straightforward call-and-response design, where one device controls the clock, and other devices simply wait and listen until their fixed address is sent on the I2C bus. While configuring an STM32 I2C peripheral entails a few steps, it is quite painless to use afterwards, as we will see in this article. Continue reading “Bare-Metal STM32: Using The I2C Bus In Master-Transceiver Mode”