r/stm32

60% less flash, 46% less RAM on the same ATmega328P menu code — just by changing the composition engine underneath
▲ 0 r/stm32+1 crossposts

60% less flash, 46% less RAM on the same ATmega328P menu code — just by changing the composition engine underneath

Been working on a compile-time composition framework (HAPI) for C++17 — built with embedded in mind. Just confirmed the first real hardware validation of an AM4-to-OneMenu compat layer, on an ATmega328P/Uno via an existing port (Fielduino):

Flash RAM
AM4 original 15,958 B (49.5%) 593 B (29.0%)
OneMenu/HAPI compat port 6,384 B (19.8%) 322 B (15.7%)
Delta 60.0% less 45.7% less

Same unmodified driver, same menu shape, same Serial I/O — the only thing that changed is the composition engine underneath. No vtables, no dynamic allocation, no heap fragmentation — composition resolves entirely at compile time.

Also validated across CH32V003, ESP32, ESP8266, native Linux, SAMD, and STM32 (F030/F103/F407) — same header-only C++17 code, no per-target rewrites needed.

Compile-time composition example (check the generated assembly): https://godbolt.org/z/6srTzdTY7

u/neurah — 5 hours ago
▲ 5 r/stm32+1 crossposts

STM Blackpill doesnt work with external power supply

Hi, I know this might be a basic question, but I'm facing an issue while building my soldering station.

My setup consists of an STM32 Black Pill board connected to an SPI TFT display based on the ILI9341 controller.

The problem is that when I power the Black Pill through its USB port, the TFT initializes correctly and the UI is displayed every single time. However, when I power the board externally by supplying 5 V to the Black Pill's 5 V pin from a linear regulator, the display does not initialize. The TFT remains completely white with only the backlight turned on.

To verify that the STM32 is actually booting, I added a simple LED blink routine to the same firmware. Even when powered externally, the onboard LED blinks as expected, confirming that the MCU is running the code. The only issue is that the display never initializes and remains a blank white screen.

I'm trying to understand why the exact same firmware works perfectly when powered over USB but fails to initialize the ILI9341 when the board is powered through the external 5 V supply.

post regulator - 7805

preregualtor- a switching PSU.

essesntially the 5v regulator poweres the onboard LDO on the stm blackpill so I dont know where the problem arises from.

reddit.com
u/sillyconductor09 — 23 hours ago
▲ 34 r/stm32+1 crossposts

Approaches for MCUs with ≤16KB Flash / ≤2KB RAM – Superloop vs lightweight schedulers?

For microcontrollers constrained to 16 KB ROM and 2 KB RAM or less, I have always implemented firmware using a classic superloop (super main loop).

I’d like to switch to a simple task scheduler for better code organization and maintainability.
The Arduino TaskScheduler library looks promising, however I’m concerned that C++ support can be spotty or problematic on many bare-metal embedded platforms.

I’m curious to hear how the community handles this resource class of MCU:

  1. Do you use simple cooperative schedulers written in pure C to avoid C++ overhead?

  2. What lightweight, low-memory cooperative task schedulers would you recommend for this tight memory budget?

  3. Any pitfalls to watch out for when porting Arduino-style task scheduling onto non-Arduino MCUs with limited Flash/RAM?

  4. Do you generally avoid preemptive RTOS entirely at this memory level?

Thanks in advance for sharing your real-world workflows!

reddit.com
▲ 13 r/stm32

Which STM32 board should I purchase?

Hey everyone.

I browsed through the different STM32 boards and found the Blue Pill and Black Pill boards to be cheaper than the Nucleo board.

This would be my first time purchasing and using an STM32.

Which one should I buy?

Any suggestions would be helpful.

Thanks in advance.

reddit.com
u/StrangeDonkey1134 — 2 days ago
▲ 5 r/stm32+2 crossposts

Designing an STM32F407 USB audio interface (8–32 channels) – architecture review

I’m designing a multi-channel USB audio interface PCB as a learning project and I’d like some feedback before I start routing.
Current plan:
STM32F407
USB3300 (USB High-Speed ULPI PHY)
TDM/I²S audio
Initially 8 channels
Future expansion to 32 channels
Up to four PCM1681 DACs (I’ll probably only populate one for the first prototype)
I’m mainly looking for feedback on the architecture.
Am I missing any important components?
Is the STM32F407 + USB3300 + PCM1681 combination a reasonable approach?
Are there any common mistakes I should avoid before designing the PCB?
If you’ve built a similar project, I’d appreciate any advice.
I’m doing this mainly to learn, so any pointers are welcome.

reddit.com
u/Soulreaper71 — 5 days ago
▲ 2 r/stm32

Chud beginner wondering what's needed to make PCB with standalone chip and not Nucleo carrier

Hey guys, I've finished my prototype of a project (thank you claude code) for a simple telemetry system, and now I am moving on to the PCB prototyping. I'm using a Nucleo board for F446RE for development, but I dont want my board to just be a nucleo carrier, and I'm gonna design it with the chip by itself and build the other things up.

With that, I'm still confused on all the thing's ill have to add to make that chip work alone, and specifically finding a datasheet which points me in the right direction .

I know I need a few things connected

  1. Oscillator crystal
  2. FRAM
  3. Power filtering for microcontroller
  4. STM32 Prog/Debug
  5. Power regulators (i hvae a 12v DC input, so some bucks to step down to +5v and +3.3v respecitvely.

Is there anything else I need? And i can't find a datasheet showing PCB setup, but i found one like 1300 pages long explaining all the registers and stuff. The photo I have is something I got from copying a similar project which im kind of basing mine off of but i need to go past it.

reddit.com
u/ChairGodIsGreat — 3 days ago
▲ 2 r/stm32

Designing an STM32F407 USB audio interface (8–32 channels) – architecture review

I’m designing a multi-channel USB audio interface PCB as a learning project and I’d like some feedback before I start routing.
Current plan:
STM32F407
USB3300 (USB High-Speed ULPI PHY)
TDM/I²S audio
Initially 8 channels
Future expansion to 32 channels
Up to four PCM1681 DACs (I’ll probably only populate one for the first prototype)
I’m mainly looking for feedback on the architecture.
Am I missing any important components?
Is the STM32F407 + USB3300 + PCM1681 combination a reasonable approach?
Are there any common mistakes I should avoid before designing the PCB?
If you’ve built a similar project, I’d appreciate any advice.
I’m doing this mainly to learn, so any pointers are welcome.

reddit.com
u/Soulreaper71 — 3 days ago
▲ 5 r/stm32+1 crossposts

Confusion while reversing stm32f103 binary: weird vector table

I was curious about the content of an STM32F103RFT6 firmware binary. It uses CAN communication and it is being updated via CAN bootloader, thats how the firmware is being updated.

So I opened it in a hex editor and had a look. But that was not what I expected.

reverse engineering binary

Right in the beginning, there seems to be a 0x200 long header. The first four bytes are the size of the whole file, that was easy. Then four bytes containing the version, I guess, because I have another firmware which is a bit newer and they just differ by increasing 0x2c to 0x30.

Everying after that I don't understand right away, and the header after 0x050 is just zeros until it ends at 0x1FF.

At offset 0x200, the real firmware seems to start:

reverse engineering binary

At first glance, it looks as expected: First four bytes show the stack pointer address, and it's located in SRAM (starting 0x2000_0000).

But the following entries are supposed to be a vector table, and the addresses in there point to strings:

reverse engineering binary

I know that's thumb addressing, and all the LSB are set, but in the vicinity of these addresses there's just strings.

I don't understand that. And I don't know how to go on from here, if I don't know where the actual entry point is located.

For comparison, I opened an STM32 .elf for a project I wrote. In this .elf, the real code starts at offset 0x1000:

STM32.elf

Four bytes stack pointer, and then flash locations for the vector table. Going there and taking the file offset 0x1000 into account:

STM32.elf

I figured, fe e7 fe e7 must be pretty rare in the original firmware binary, so I searched for it:

reverse engineering binary

That does look pretty similar. But why is that, and where does this offset come from? And how should I continue?

reddit.com
u/PhreakSh0w — 5 days ago
▲ 60 r/stm32+2 crossposts

H₂H³ // Smart Twin USB Host Switch & Triple USB Hub & STM32 fourth USB peripheral

Hey everyone, I was tired of flaky commercial KVM switches, so I built a robust alternative for my desk. It toggles 3 USB 2.0 peripherals between 2 hosts.

The Tech: Driven by an STM32 managing the switching logic and driving an I2C OLED for real-time VBUS/current monitoring. The PCB is a 4-layer controlled-impedance board laid out in KiCad 9.0.

The Fun Part: Instead of just managing the hardware, the STM32 is wired natively into the USB hub as a 4th peripheral. This allows the host to talk directly to the MCU, opening up custom HID macro injections or automated switching scripts.

The KVM C++ firmware is about 95% finalized, and everything is 100% open-source (KiCad, FreeCAD 1.0 snap-fit case, and firmware). I'd love to hear your thoughts on the host-to-MCU link applications!

Code & CAD files are here: TwinUSB on Github ask me questions. What are you interested in?

Enthusiastic about open source: TwinUSB on Hackaday.io

u/Bright_Remote5154 — 5 days ago
▲ 20 r/stm32+2 crossposts

Looking for PCB review/feedback — STM32F411 motion data logger with USB-C, SDIO microSD, SPI IMU, RTC backup

The board is intended to work as a small motion/event data logger or “black box” for robotics applications. The idea is to mount it on a robot or moving system, record IMU/current-sensor data, store logs on a microSD card, and communicate with a host such as a Raspberry Pi or Jetson through USB/UART.

Main features:

MCU: STM32F411CEU6

USB-C: used for power and USB data

IMU: BMI088 connected through SPI

Storage: microSD card using SDIO 4-bit mode

RTC: internal STM32 RTC using 32.768 kHz LSE crystal

Backup power: coin cell on VBAT to keep RTC time when main power is removed

Debug: SWD/ST-LINK header

Analog input: current-sensor input through JST, filtered before going into the STM32 ADC

Extra interface: USART/UART pins for telemetry or external sensor communication

For the stackup, I’m using a 4-layer structure:

L1: Signal + components + local power routing

L2: Solid GND plane

L3: Solid GND plane

L4: Signal + power routing / polygon pours

I decided not to use a dedicated inner power plane. Instead, I’m using solid continuous ground planes on both inner layers so that the signal and power routing on the outer layers always have an adjacent ground reference. Power is distributed using wider traces and polygon pours on the outer layers.

My goal with this stackup is to improve return paths, reduce EMI risks and maintain signal integrity. In the routing of the IMU and the microSD Card Socket, I feel that I have overused vias a bit. Does my use of vias in this scenario affect the performance of the board (signal integrity and EMI)?

Things I would especially appreciate feedback on:

USB-C routing and protection

SDIO microSD routing and pull-up placement

SPI routing to the BMI088 IMU

RTC crystal/VBAT layout

Grounding strategy and the two-inner-ground-plane stackup

Power distribution using polygon pours on the outer layers instead of a power plane

Any obvious schematic/layout mistakes or manufacturability concerns

I’m still learning PCB design seriously, so any comments about layout, signal integrity, grounding, EMI, component placement, or general design choices would be really helpful.

Thanks in advance!

u/Adventurous-Rip-7015 — 5 days ago
▲ 34 r/stm32

Chud beginner can’t figure out st link device error

Hey guys completely new to STM and I bought an F446RE development board to practice and teach myself.

Just doing basic things like trying to get the onboard LED to blink but it won’t work because I just keep getting this recurring error where it can’t initialize the st link device.

Any idea why this is? I know it’s probably something basic I’m missing but I straight up idk

u/ChairGodIsGreat — 7 days ago
▲ 4 r/stm32

Getting a GPS tracker to last a year on a tiny battery was much harder than I expected.

One of the hardest parts of building my LoRa GPS tracker wasn't the RF design or even the firmware.

It was battery life.

When people ask how a tiny GPS tracker can last close to a year on a single charge, they usually expect some secret hardware trick.

There isn't one.

It's mostly about avoiding unnecessary work.

Here are a few of the biggest lessons I learned:

• Sleeping is everything. Every microamp matters when your goal is measured in months instead of days. Most of the time, the MCU is doing absolutely nothing—and that's exactly how it should be.

• GPS is expensive. Keeping the receiver running continuously drains power quickly. Deciding when to acquire a fix turned out to be just as important as getting the fix itself.

• Radio airtime matters. Transmitting every second sounds nice until you look at the battery graph. Simply increasing the reporting interval can extend runtime dramatically.

• Every wake-up has a cost. Reading sensors, checking timers, writing to flash, or transmitting "just in case" all add up over thousands of cycles.

• The battery wasn't the answer. It would have been easy to install a much larger battery, but I wanted the device to stay small enough to fit almost anywhere. That meant squeezing every bit of efficiency out of the hardware and firmware instead.

After dozens of firmware revisions and more current measurements than I'd like to admit, I finally reached a point where slow reporting intervals could achieve close to a year of operation on a tiny rechargeable battery.

I'm curious—what's the biggest battery optimization you've discovered in your own embedded projects? I'm always interested in learning new techniques.

https://preview.redd.it/ery0a2o4zcah1.jpg?width=4032&format=pjpg&auto=webp&s=b0484c51a2311de6522e8c62638ca3ec3912c053

reddit.com
u/nolilab — 6 days ago
▲ 32 r/stm32+1 crossposts

Bootstrapping an STM32 Embedded Systems R&D Project – Looking for ECE Contributors

Hi everyone,

I’m Patrick, founder of an early-stage embedded systems R&D project called SBW (Shoot-By-Wire). Over the past year I’ve been bootstrapping the project entirely out of pocket, while balancing full-time work and school. Mark I is approaching completion, and we’re beginning to recruit a few additional contributors before starting Mark II.

SBW is an embedded telemetry platform focused on validating a secure sensor-to-storage data pipeline before expanding into more advanced embedded systems.

Current Mark I hardware includes:
- STM32U575 (NUCLEO-U575ZI-Q)
- LSM6DSOX IMU
- TMP117 temperature sensor
- MicroSD storage (FatFs over SPI)

Current firmware and system work includes:
- Bare-metal embedded C
- Sensor acquisition
- TLV-based telemetry architecture
- Block-based data logging
- Heatshrink compression
- AES-GCM encryption (current milestone)
- Python host-side decoding and validation tools

Mark II expands significantly beyond proving the data pipeline and begins introducing a more modular embedded architecture, additional sensing capabilities, power management, communications, and a much larger firmware framework.

We’re looking for people interested in areas such as:
- Embedded systems
- Electrical & Computer Engineering
- STM32 development
- PCB design
- Sensor integration
- Firmware architecture
- Communications
- Low-power systems
- Embedded security
- Signal processing
- Hardware validation and testing

This is currently an unpaid volunteer effort while we continue bootstrapping, but the long-term goal is to build a serious engineering organization around the project.

Even if you’re not interested in contributing, I’d appreciate feedback on the project architecture, documentation, or overall engineering approach.

I’ll also attach a photo of the current Mark I bench setup.

u/DevStu_ — 7 days ago
▲ 3 r/stm32

Maintaining servo

I have a 6-legged robot (hexapod) project where I use an STM32F4 to communicate via PCA9685 to control the servos. When I transmit a set of angles to keep the robot stationary, it poses correctly right after booting up. However, an issue occurs when I try to manually force or shift the servos back and forth while the angles are being transmitted: the servos start spinning wildly for a moment before returning to their designated positions. I suspect this is due to interference caused by the deviation between the forced physical angle and the commanded angle from the PCA9685. Is there a way to resolve this issue? Could it perhaps be that the current I am supplying to the servos is insufficient?

reddit.com
u/Former-Hold-1589 — 6 days ago
▲ 144 r/stm32

Bought STM32F411RE Board what should I do first for preparing for Job.

HOW CAN I LEARN EMBEDDED SYSTEMS. I WILL ALWAYS UPDATE MY PROGRESS HERE SOMEBODY JUST GIVE AN ASSIGNMENT

u/Weekly_Passenger_535 — 10 days ago
▲ 17 r/stm32+2 crossposts

Firmware problem - ADC buffer updates correctly but OLED stays blank and LDR logic doesn't work

I've been stuck on this for almost two days and I'm running out of ideas.

I'm using an STM32G070RB (NUCLEO-G070RB) with CubeMX/HAL.

MAIN PROBLEM - in video you can see both adc_buffers are getting values perfectly but not assigning to raw_adc_value and joystick_x. oled always black. ldr light is also always black.
i have checked all devices bord ,pins connections , oled ,ldr , everything hardware is perfect not faulted .

CODE - https://github.com/vivek91173/multi-sensor-

Hardware

  • STM32G070RB
  • SSD1306 OLED (I2C)
    • SCL -> PB8
    • SDA -> PB9
  • Joystick VRX -> PA4 (ADC Channel 4, Rank 1)
  • LDR -> PA1 (ADC Channel 1, Rank 2)
  • LDR indicator LED -> PA6
  • PWM output -> TIM3 CH2 (PA7)

Goal

I'm trying to build a small multi-sensor project.

  • Joystick changes OLED pages.
  • LDR value is displayed on the OLED.
  • LDR also controls an LED.
  • PWM is shown on another OLED page.

ADC Configuration

  • ADC1
  • Scan Conversion Enabled
  • Continuous Conversion Enabled
  • DMA Circular Mode
  • Number of conversions = 2

Rank 1 -> ADC Channel 4 (Joystick)

Rank 2 -> ADC Channel 1 (LDR)

DMA buffer:

volatile uint16_t adc_buffer[2];

Started using:

HAL_ADC_Start_DMA(&hadc1, (uint32_t *)adc_buffer, 2);

What works

The DMA buffer updates correctly.

Debugger continuously shows different values for both channels.

Example:

adc_buffer[0] = 3176   // joystick
adc_buffer[1] = 139    // LDR

The values change correctly when I move the joystick or change the light on the LDR.

The problem

Even though adc_buffer is updating correctly:

  • OLED remains black (or sometimes completely blank).
  • LDR LED never responds to the LDR.
  • It feels like the rest of my application isn't using the updated ADC values correctly.

For example:

if(adc_buffer[1] < 3000)
{
    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_SET);
}
else
{
    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_RESET);
}

The debugger clearly shows adc_buffer[1] changing, but the LED never behaves accordingly.

Similarly, the OLED pages never display the live values even though ssd1306_UpdateScreen() is being called inside the main loop.

Things I've already checked

  • DMA interrupt is enabled.
  • DMA Channel 1 is linked correctly.
  • ADC scan mode is enabled.
  • Continuous conversion is enabled.
  • Circular DMA mode is enabled.
  • ADC buffer values update correctly in Live Expressions.
  • OLED worked perfectly before switching from polling to Scan + DMA.
  • Wiring has been checked multiple times.

At this point I'm wondering if:

  • my main loop has a logic issue,
  • the SSD1306 code is blocking somewhere,
  • I'm missing something obvious in the DMA/ADC setup,
  • or there's another mistake I haven't noticed.

I've attached my CubeMX .ioc, main.c, ssd1306.c, stm32g0xx_hal_msp.c, and interrupt files.

Any help would be greatly appreciated. Even if someone spots something silly, I'd rather know than spend another day staring at this code.

u/Efficient_Estate6145 — 8 days ago
▲ 2 r/stm32+1 crossposts

Minimal circuit stm32wb

Previously, when I purchased Espressif MCUs (e.g., esp32-c3, not board), it was easy to find and build minimal circuit - just few resistors.

Is it the same with pure stm32 chips, specifically stm32wb09ke? And how can I find these minimal schemes in docs?

reddit.com
u/Accomplished-Use405 — 8 days ago
▲ 18 r/stm32

Title: How do I learn to read reference manuals and write bare-metal code instead of copying examples?

I'm an ECE student and I've recently started learning STM32 (Blue Pill / STM32F103). My goal right now is not RTOS, Linux, AI, or advanced projects. I just want to learn how to properly understand a microcontroller and write code from the reference manual.

The problem I'm facing is that I still don't fully understand even the basics. I can't confidently blink an LED on my own yet without following a tutorial step-by-step. I get confused about things like enabling clocks, configuring GPIO registers, and writing the correct bit manipulations. I feel like I'm missing some very fundamental understanding, and I want to build that from the ground up instead of just copying code.

I don't want to become someone who only copies HAL examples. I want to understand:

  • How experienced embedded engineers read reference manuals
  • What information should become muscle memory vs what should be looked up
  • How to navigate a datasheet/reference manual efficiently
  • How to go from "I want to blink an LED" to finding the right registers and writing the code myself
  • How to learn bare-metal programming the right way

Could you recommend:

  • YouTube channels
  • Blog series
  • STM32 learning paths
  • Exercises/projects that specifically teach reading documentation and writing code from it

If you were starting from scratch today and your goal was to become very comfortable with microcontroller architecture, registers, datasheets, and bare-metal programming, how would you do it?

I'd appreciate any roadmap or resources from people who have gone through this themselves.

reddit.com
u/microscammer — 11 days ago
▲ 0 r/stm32

I wanted to tell Claude Code "fix the bug, build, and flash my STM32" — so I gave it the real STM32 toolchain

u/Brilliant-Luck-1456 — 12 days ago
▲ 8 r/stm32

A practical guide to learning embedded firmware development

About a year ago, I made a post (https://www.reddit.com/r/embedded/s/rk0xTafhjy) asking whether there was still a need for a practical guide to learning firmware engineering. The response was pretty clear — there’s still demand for it.

So I’ve decided to commit the next 3–6 months to writing one.

The challenge is that since I’ve been doing this for a while, it’s hard for me to step into the shoes of someone just starting out. I already know how to navigate datasheets, search for solutions, debug hardware, and piece things together. That makes it harder to identify where beginners actually struggle.

That’s where I need help.

I’m looking for a few learners who are willing to spend time over the next few months actively learning embedded firmware development. If that sounds like you, comment here or send me a DM.

What this guide will be about

This will be a practical, hands-on, build-first guide — not a theory-heavy one.

Instead of covering endless concepts upfront, we’ll pick small tasks/projects, build them, and document the process.

For example:

"I want to control an LED."

From there, we’ll work through:

  • What do I need to understand about my microcontroller?
  • Which parts of the datasheet matter?
  • How do I find relevant examples or methods online?
  • How do I implement it?
  • How do I verify that it’s correct?

As the guide progresses, the tasks will naturally become more complex, introducing deeper concepts along the way.

How this will work

  • I’ll first understand where you are in your learning journey and what you already know.
  • I’ll give you practical tasks to solve.
  • You’ll explore documentation, datasheets, and online resources to figure them out.
  • I’ll guide you whenever you get stuck.
  • Afterward, you’ll tell me how you approached the problem:
    • What was your first thought?
    • What did you read?
    • What confused you?
    • How did you solve it?
    • What did you learn?

Your feedback will directly shape how I write the tutorials.

What you’ll need

  • Access to at least one microcontroller development board (AVR, Arduino, 8051, ESP32, STM32, etc.) — or be willing to buy one.
  • Willingness to spend time learning and experimenting.
  • Willingness to give honest feedback about your process.

What you need to know beforehand

Not much.

A basic understanding of C and some electronics knowledge will help, but you don’t need prior firmware experience.

reddit.com
u/HolyDevil_777 — 10 days ago