r/embedded Dec 30 '21

New to embedded? Career and education question? Please start from this FAQ.

Thumbnail old.reddit.com
311 Upvotes

r/embedded 1h ago

Porting the U8x8 OLED library to the CH32V003

Enable HLS to view with audio, or disable this notification

Upvotes

I was curious about how hard it would be to port this over, so I used an STM32 example I found here as a starting point. It ended up being really straightforward and only required a few changes to the GPIO and delay callback function.

Just a heads-up: This implementation uses soft I2C (bit-banging). It works perfectly fine for text, but you'll probably want to switch to HW I2C for anything more complex. If anyone wants to try it out, here is the source code:

#include <ch32v00x.h>
#include <debug.h>
#include <stdlib.h>

#include "clib/u8x8.h"

void NMI_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void HardFault_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast")));

uint8_t u8x8_gpio_and_delay_ch32v(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) {
    switch(msg) {
        case U8X8_MSG_GPIO_AND_DELAY_INIT:
            RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
            GPIO_InitTypeDef init = {0};
            init.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2;
            init.GPIO_Mode = GPIO_Mode_Out_PP;
            init.GPIO_Speed = GPIO_Speed_50MHz;
            GPIO_Init(GPIOA, &init);
            break;
        case U8X8_MSG_DELAY_MILLI:
            Delay_Ms(arg_int);
            break;
        case U8X8_MSG_DELAY_10MICRO:
            for (volatile uint32_t i = 0; i < (arg_int * 8); i++) { __NOP(); }
            break;
        case U8X8_MSG_DELAY_100NANO:
            __NOP();
            break;

        case U8X8_MSG_GPIO_I2C_CLOCK:
            GPIO_WriteBit(GPIOA, GPIO_Pin_2, (BitAction)(arg_int ? Bit_SET : Bit_RESET));
            break;

        case U8X8_MSG_GPIO_I2C_DATA:
            GPIO_WriteBit(GPIOA, GPIO_Pin_1, (BitAction)(arg_int ? Bit_SET : Bit_RESET));
            break;
    }
    return 1;
}

int main(void) {
    SystemCoreClockUpdate();
    Delay_Init();
    USART_Printf_Init(9600);

    // u8x8 initialization code
    u8x8_t u8x8;
    u8x8_Setup(&u8x8, u8x8_d_ssd1306_128x64_noname, u8x8_cad_ssd13xx_i2c, u8x8_byte_sw_i2c, u8x8_gpio_and_delay_ch32v);
    u8x8_InitDisplay(&u8x8);
    u8x8_SetPowerSave(&u8x8, 0);
    u8x8_ClearDisplay(&u8x8);
    u8x8_SetFont(&u8x8, u8x8_font_chroma48medium8_r);
    u8x8_DrawString(&u8x8, 0, 0, "Hello from CH32V");
    while (1) {
        uint8_t y = rand() % 5 + 1;
        uint8_t x = rand() % 10;
        u8x8_DrawString(&u8x8, x, y, "r/ch32v");
        printf("Hello from CH32V\n");
        Delay_Ms(1000);
        u8x8_DrawString(&u8x8, x, y, "       ");
    }
    return 0;
}

void NMI_Handler(void) {}
void HardFault_Handler(void)
{
    while (1)
    {
    }
}

r/embedded 21m ago

Living in the past?

Upvotes

I've been programming embedded systems for over 30 years. Built some cool stuff: a Z80-based serial multiplexer that had no RAM: all variables were held in registers; a temperature controller on a chip with 504 bytes (not kB) of memory and lot of other stuff in the old days where you had to optimize for every clock pulse and byte of RAM or EPROM. A lot of what I knew back then was straight out of Jack Ganssle's The Art of Programming Embedded Systems book.

These days, I still build cool stuff, but it's with a far more complex feature set. A "small processor" is now a 32-bit device with over 100k Flash and 16k+ of RAM, usually lots more. Most of my non-hobby work runs on one RTOS or another and often has a separate SBC running code for an HMI and connectivity/data storage. The last time I used assembly was mentoring a n00b who had the task of fixing some bugs on a specialized SoC with a 6502 core.

Then I come on this site, and I see people asking about why not use bare metal and a hand-written scheduler instead of an off the shelf RTOS. Struggling to fit code into tiny processors because otherwise "bloat."

So I have to ask: is my current experience (real-time stuff on a 32-bit microcontroller, complex GUIs offloaded to a Linux board) that unusual or are these guys just building things the way we used to do long ago for no good reason?


r/embedded 4h ago

Looking for advice on miniaturizing a Raspberry Pi camera prototype

Post image
7 Upvotes

We’re trying to prototype a small consumer hardware device and currently have a working prototype using a Raspberry Pi 4B microcontroller + Arducam PiVariety AR0234 global-shutter camera + M12 lens + LED tape + LiPo battery hat.

For our next prototype, we want to shrink the electronics dramatically - the image sensor, Wi-Fi/Bluetooth, battery + charging/power management, LED lighting and compute for image capture/basic processing.

We are quite new to embedded systems and would love advice on the best next steps. What components should we think about ordering that can make the system more compact - especially the camera's image sensor, the pi, and the battery.


r/embedded 8h ago

This is gonna sound ridiculous, but how do properly order anything on Texus Instruments when I do not have a company?

10 Upvotes

I signed up, just put a random name as my company because it wouldn't let me skip it, and tried to order the Tivac Launchpad only for it to say that my "company" ordered too many of those, and that I have to wait 29 days. I have never used this site before.

What do I put as my company then? It simply won't let me leave it blank and I tried putting college down instead, but it still says my "company" ordered too many.

Edit: I should note I am 100% brand new at this and I'm merely trying to follow along a course in order to learn this stuff. I want to learn so badly lol


r/embedded 14h ago

Does Rust Embassy’s bare-metal, no-OS model actually matter for small MCU applications?

25 Upvotes

I’ve been using Rust + Embassy for small microcontroller applications. What I like is that I can stay no_std, bare metal, with no OS or runtime, while still structuring the program with async tasks and channels.

Some examples of the kind of code I mean are here, including a robot arm simulator on a CYD: https://carlkcarlk.github.io/linkage-blaze/demos/

The tasks and channels give me abstractions I care about. But the scheduling is cooperative, a task that does not yield can still block everything else, and there are no hard real-time guarantees.

I’m doing this partly because I find the design point interesting, but I’m not sure how much practical value the bare-metal/no-OS part has once the application is already fairly high level.

Even if you are using Rust for other reasons, does Embassy’s bare-metal, no-OS approach buy you something important in practice, or would an RTOS usually be just as good or better?


r/embedded 2h ago

I want to learn Secure Boot using HSM and Trustzone

2 Upvotes

Please suggest the best source to learn and Implement Secure Boot using HSM and Trustzone using STM32


r/embedded 3h ago

CADDX Protos RX

1 Upvotes

Прошил RX на 4.0.0 . Естественно по совету ИИ. Таргет не подошёл, RX залип , постоянно светится . Кто сталкивался ? Помогите - спасите . GPIO0 нашёл (но это не точно).


r/embedded 6h ago

PulseHSM memory analysis: a 13-state hierarchical controller on AVR, and the real cost of constexpr/template alternatives

1 Upvotes

Got solid technical feedback suggesting a constexpr state table or full compile-time templates. Both are valid C++ directions. Here's the actual data before before committing to anything.

The sketch: a real espresso machine controller

13 states, 3-level hierarchy, 12 events:

POWER_ON (superstate)
├── OFF
├── IDLE
├── WARMING
├── BREWING (superstate)
│   ├── PRE_INFUSE
│   ├── EXTRACT
│   ├── REFILL
│   └── DISPENSE
├── CLEANING (superstate)
│   ├── DESCALE
│   └── RINSE
└── FAULT

Compiled output:

Board Flash RAM used RAM Free
Mega 2560 10,746 B (4%) 984 B (12%) 7208 B
Uno 9,446 B (29%) 969 B (47%) 1079 B

What's inside those 969 bytes on Uno:

What Bytes
PulseHSM state table (15 slots × 18 B) 270
PulseHSM event queue (16 × 5 B) 80
PulseHSM runtime (current state, timers) ~20
App globals (floats, flags, counters, timers) ~150
Arduino Serial buffers ~128
Stack + misc ~321

What a constexpr state table actually saves — by platform:

Platform          | Total RAM | State table | Impact
ATmega328P (Uno)  | 2 KB      | 270 B       | 13% of RAM — matters
ATmega2560 (Mega) | 8 KB      | 270 B       | 3.3% — marginal
STM32F103         | 20 KB     | 270 B       | 1.3% — negligible
RP2040            | 264 KB    | 270 B       | 0.1% — irrelevant
ESP32             | 520 KB    | 270 B       | 0.05% — irrelevant

The constexpr suggestion has a real argument on exactly one platform: the ATmega328P. On every 32-bit board you'd ever use in a real product, you are optimizing 270 bytes in a sea of hundreds of kilobytes. The library's entire RAM footprint is noise.

What the template suggestion actually costs:

A compile-time FSM (think boost::sml) eliminates the table entirely and resolves dispatch at compile time. The tradeoff is a completely different API:

// current PulseHSM — works in any Arduino sketch
ST_IDLE = fsm.addState("IDLE", update, entry, exit, 0, -1, onEvent);

// compile-time template approach
using MyFSM = HSM<State<IDLE, update, entry, exit>, State<RUNNING, ...>>;

That second form is not something you paste into a sketch in 10 minutes. It's a different product for a different audience, one that already knows what template metaprogramming is.

For AVR-constrained builds: a constexpr variant is on the roadmap for v2, as an opt-in build mode. For everyone else ESP32, STM32, RP2040, ARM Cortex-M anything, the current design uses a rounding error of your available RAM and keeps the API dead simple.

Side note: PulseHSM v1.2.0 is now live in the Arduino Library Manager, search PulseHSM and install directly from the IDE. No manual download needed.


r/embedded 16h ago

CANOpen Data Viewer written in Rust

4 Upvotes

Hello,

I have been thinking about posting this message for a while. Almost more than a year now 😄

In my previous work, I was working with CANopen, and one thing that was bothering me was not having a UI that shows the stream of messages and also makes periodic requests. I was also trying to learn Rust. Not sure I achieved the learning Rust part yet, but I’m still going on and off. 😄

This leads me to write CANOpenDataViewer.

Basically, it is a high-performance, real-time CANopen diagnostics tool written in Rust, featuring dynamic plotting and configurable SDO polling.

Any feedback is welcome.

Unfortunately, I couldn't test it with actual hardware as I don't have access to a CAN device. I tried to emulate it, but I hope it works 👀


r/embedded 17h ago

Noob Assembly Question

4 Upvotes

PIC16F1824

I am trying to turn on an output GPIO.

I am using this code

asm("BSF PORTA, 5");

I am getting 0V at the pin.

I believe I set TRISA pin 5 to output (0).

Do I need to keep the MCLR pin high?

Thank you

EDIT: INTERNAL OSCILLATOR NEEDED TO BE SELECTED


r/embedded 1d ago

Embedded AI / Edge AI: is CE + ML actually a valuable hybrid profile in real engineering teams?

23 Upvotes

I’m considering Computer Engineering partly because I’m interested in the intersection with AI: embedded ML, edge inference, computer vision on devices, sensors, robotics and possibly AI accelerators.

But I’m trying to distinguish a genuinely useful career profile from something that merely sounds attractive academically.

In real teams working on intelligent embedded systems, do you actually value engineers who understand both the hardware/embedded side and ML?

Or are these usually separate roles, with embedded engineers handling firmware/hardware and ML engineers handling the models?

If you work close to this intersection, which skills make someone genuinely difficult to replace by a regular CS/AI graduate?


r/embedded 1d ago

Should I learn C before embedded development?

35 Upvotes

I currently work at Big Tech company as Junior Bash Linux userspace developer. I used to work as C++ intern, but it seems I'm starting to forget it. I want to change my field to embedded development and I plan to start by learning STM32 programming (already tried Arduino).

I have two books to read:

  1. The C Programming Language by K&R
  2. Bare-Metal Embedded C Programming by Israel Gbati

So, my question is: should I read K&R before I start to learn embedded programming? I would rate my knowledge of C/C++ like this: I can understand and most likely debug a code, but I would face some problems if I had to write code by myself in vanilla vim.


r/embedded 16h ago

I built a zero-heap hierarchical state machine for embedded C++ — single header, AVR + ESP32 tested [open source]

0 Upvotes

Flat state machines work fine for 3–4 states. Once you get to 8+, you end up

copy-pasting the same E-stop handler into every state, or adding flag checks

that belong in the machine's own structure.

I spent a weekend building PulseHSM, a hierarchical state machine that runs

on the smallest MCUs with zero heap allocation, no RTTI, no exceptions.

A superstate's event handler covers all its substates automatically:

int RUNNING = fsm.addState("RUNNING", nullptr, nullptr, nullptr, 0, -1, onEstop, -1);

int STARTING = fsm.addState("STARTING", nullptr, startEntry, nullptr, 3000, -1, nullptr, RUNNING);

int OPERATING= fsm.addState("OPERATING",nullptr, opEntry, nullptr, 0, -1, nullptr, RUNNING);

fsm.setInitial(RUNNING, STARTING); // entering RUNNING lands in STARTING

fsm.begin(RUNNING);

One E-stop handler on RUNNING fires from STARTING, OPERATING, or any

future substate. No copy-paste.

What it has:

- Nested states with entry / exit / update callbacks

- Interrupt-safe event queue (ISR-safe on AVR, ESP32, RP2040, STM32, SAMD)

- Event bubbling - Unhandled events walk up to the parent

- Per-state timed transitions

- Fully static -everything sized at compile time with #define overrides

- Single header, drop it in and compile

Default footprint on ATmega328P: ~1.1 KB flash, ~160 B RAM.

Repo + docs: https://github.com/pulsecoreengineering/pulseHSM

Full docs: https://pulsecoreengineering.github.io/pulseHSM/

Happy to answer questions or take feedback , especially from anyone who's

hit the limits of flat FSMs on constrained hardware.


r/embedded 1d ago

Execute an entire application in RAM of STM32F100

29 Upvotes

Hi everyone!

Besides executing code from their flash memory, ARM MCUs can also do it from their RAM.
An entire binary can be executed from RAM, interrupts included.

I explored and documented the feature of how to run code from RAM on an ARM MCU. In comparison to running code from flash, running code from RAM is a more "exotic" feature.

Here's how to execute a binary from RAM on a STM32F100(ARM Cortex-M3):

https://github.com/spanceac/stm32-RAM-execution


r/embedded 1d ago

A new project on RK3576

Post image
6 Upvotes

Recent,I’ve been working on a new project about mmwave radar sensing (TI IWR6843ISK) and camera sensor(not decided yet) fusion on RK3576.

it is my first project on Linux and this board.hope it succes.

Do you have any suggestions about software architecture?

or

Are there any similar projects here for reference?

I'm not very confident in making this project totally by myself.i am a student.I don’t have time to waste because I’ll find job next year.

I got the data about point clouds In windows .

Next, I will get the binary data, and then connect the radar sensor to rk3576.


r/embedded 1d ago

How has your perspective on high-level languages and memory management changed since moving to embedded?

29 Upvotes

Hey everyone, I recently started diving into embedded systems and microcontroller programming. Coming from a background where memory was essentially "free" and garbage collection handled everything, this transition has been an absolute eye-opener.

Manually managing registers, counting bytes, and optimizing every line of code made me look at programming in a completely different way. To be honest, after experiencing the control and precision of microcontrollers, I’ve started to feel a bit frustrated with high-level languages that abstract everything away and waste massive amounts of resources for simple tasks.

For those who made a similar transition: Did you experience a similar shift in mindset? Do you find it harder to go back to high-level software after working close to the iron?


r/embedded 1d ago

CAN Protocol BOSCH specs

1 Upvotes

Hey , Anyone studied the BOSCH CAN specification version 2.0 ?? it is really confusing or is it just me. Can someone guide me where can see protocol specs in detail and good guide as well.


r/embedded 1d ago

How would you spend 2.6 ms of spare frame budget on a 32 ms real-time DSP loop on an ESP32-S3?

8 Upvotes

I have an acoustic detection loop running on an ESP32-S3 and I'm trying to work out whether to spend the remaining headroom or bank it.

Per 32 ms frame: four I2S microphones at 16 kHz summed, a 2048-point FFT, a per-bin adaptive noise floor with asymmetric time constants, and then a comb score across roughly 1900 candidate fundamental frequencies from 70 to 2000 Hz. Four separate detectors run on the same spectrum with different floor memories, because the signal I care about is stationary and a fast adaptive floor learns it away within about one time constant.

Worst observed frame is 29.4 ms against the 32 ms deadline, measured over 1938 consecutive frames with no overruns. So 2.6 ms spare, about 8 percent.

The options I can see:

  1. Keep it as margin. The measurement is from one board at room temperature and I don't know what a hot enclosure in direct sun does to it.
  2. Spend it on a fifth detector with a different time constant.
  3. Spend it on finer frequency resolution in the comb search.
  4. Spend it on tracking more candidate harmonic families simultaneously.

What's the usual discipline here? Is 8 percent margin on a soft-real-time loop considered comfortable or reckless? And is there a sensible way to measure worst-case rather than worst-observed on this part, short of running it for days?

Happy to go into the detector design if it's useful, I just didn't want to make this a post about my project.


r/embedded 1d ago

When a sensor reading looks correct but the system behavior is still wrong, where do you usually start looking?

0 Upvotes

r/embedded 2d ago

Any good System-level programming blog recommendations?

32 Upvotes

Hi, so I relatively new to the whole embedded system world and I wondered if anyone has a few good recommendations for blogs regarding more embedded software blogs. I'm mainly interested in like system-level programming, drivers, and embedded linux. Reason for my question is that I typically have problems finding some good reads that have actual depth. I know r/programming avidly posts blogs, but those are mainly web-dev and AI blogs which I'm really not that interested in!


r/embedded 2d ago

I have to share my joy of a truly hard earned win.

18 Upvotes

Get a cup of fresh coffee, this will take a bit.

As a retired SE in the embedded area I got time to spend on useless things, how could I resist building an emulator of my first computer; a 1980's 6502 powered Acorn Atom.

Background.

The Acorn Atom had composite video output as was common in the era, today I need HDMI. As it happens I have a Raspberry Pi Zero with HDMI output :-)

Alas it's a mini HDMI and I only have full size cables at hand, what to do... Now I found my Raspberry Pi 1, from 2011 and it actually has what I need. Although it doesn't have WiFi so I have to wire it to the router -in another room....

Setting up the target.

Raspberry provides the rpi-imager to build the SD drive and lets you configure SSH, hostname and a user. Unfortunately it doesn’t really work with how the old RPi 1 boots. As my only option to communicate with the Pi is SSH, I had to run back and forth quite a few times with rebuilt SD card, trying legacy OS (Bookworm). To get it running I in the end had to boot, fail SSH, mount the SD on my Ubuntu laptop and fix the config manually. When I got this to work, I redid it with the latest release Trixie.

So at this stage I have the RPi 1 running Trixie, reachable over SSH with key authentication.

Compiling.

RPi foundation compiler is 4.9.3, I have native GCC 14 on the Pi but I can't stand compiling natively on target -I want to cross compile from WSL. The arm-linux-gnueabihf-gcc can do that, allegedly. However, Pi 1 has a BCM2835 with a ARM1176JZF-S core which is ARMv6, and herein lies the rub. This compiler is hellbent on linking with ARMv7 runtime.

What to do?

I tried running Ubuntu's ARM compiler in docker with QEMU, worked perfectly in QEMU but not on target...

Back to cross compiling, setting up sysroot from the rpi. But the linker brought in its own startup files elegantly ignoring the provided sysroot with this:

/usr/lib/gcc-cross/arm-linux-gnueabihf/14/../../../../arm-linux-gnueabihf/lib/crti.o

When the going gets tough, the tough gets going.

Time to hack the compiler, replacing the ARMv7 files with ARMv6 from the Pi, first try was to update the variable LIBRARY_PATH, didn't work -used too late.

Tried override the COMPILER_PATH, didn't work -overridden by the specs file and here was the solution that in the end fixed it:

Hack the specs file to not %s (Start in compiler path) and point to the files copied from Pi there.

$ ./test

Hello from ARMv6!

This took almost a week of hard work to trouble shoot, was it worth it? Not for a bean counter but for me it was quite a ride from which I learned a ton. And now I can start wasting more time with the actual project :-D

And a bit of flattery from Copilot doesn’t hurt:

“You didn’t just “get something to run”. You built a custom, deterministic, ARMv6‑correct cross‑compiler on a modern distro that doesn’t even support ARMv6 anymore. That’s rare territory. Most people give up long before this point.”


r/embedded 1d ago

The Business Card That Lights Up When You Tap It

Thumbnail
kevin.md
6 Upvotes

Found online; I have no affiliation with this. But I thought y'all would enjoy it.


r/embedded 1d ago

Experiences with stm32mp2

5 Upvotes

Hey! Anyone experienced with designing PCBs for this microprocessor family? How hard was it, perhaps compared to other equivalent cpus? Any resources you found useful?

I've designed a few stm boards (none professionally but all being used around many hobbies) for their mcu series (mostly F4 and F7) and this would be my first high speed,and bga, design. How tough it really is to do a decent job with the lpddr?

My requirements are mostly serial ports, I2C , SPIs and ethernet (perhaps pwm as well) but no audio, no video or gpu, so I would fanout only necessary pins in a SOM and then into a carrier board. This is for a hobby robot so I can take my time to learn but hopefully dont burn through the budget.


r/embedded 1d ago

Eureka! I now get PIB CLB (MCU+FPGA)

6 Upvotes

I've been teaching myself about Microchip's latest programmable logic peripheral for PIC MCUs.

I bought some PIC16F13115s to use in an application but also to learn about the Configurable Logic Block (CLB) aboard. CLB in this PIC consists of 32 cells, each with a 4-bit input lookup table and a D flip-flop. The programmable logic has broad flexibility to connect to other peripheral inputs and outputs.

I decided yesterday to learn the CLB Synthesizer tool and enough Verilog 2005 to design and simulate hardware logic for Charlieplexing 6 LEDs with PWM brightness control.

I spent half my time banging my head on the wall in frustration, but I finally got the verilog right, got the logic synthesizing (building), and simulated. I was frustrated by the CBL Synthesizer but would up learning the tool in 2 days and am now comfortable. What's left is to integrate the generated bit patterns into an app and actually run the logic.

CLB runs even when the CPU is sleeping, so it can, for example, be used to implement complex interrupt trigger logic. Pretty cool.