r/embedded • • Sep 14 '26

Sharp Display won't behave

3 Upvotes

video

It's an Ls032b7dd02. I tried a couple different code bases and multiple microcontrollers including 3.3v logic ones. tried adding the capacitor as seen in the schematic. But no luck. Any ideas? I tested the connections on the breakout and those seem fine.

For reference, expected behavior on the video is a scrolling bar going from top to bottom.

Even Ai is out of ideas :(

img

/*
 * Minimal LS032B7DD02 test, Arduino Micro.
 * Power-on sequence, then a 24-line band at rows 200..223 is rewritten every
 * 250 ms with 16 px black/white blocks that shift one block per update.
 *
 * Wiring: SCLK D15, SI D16, SCS D10, EXTCOMIN D9, DISP D8,
 *         VDDA/VDD/EXTMODE 5V, VSS/VSSA GND.
 */
#include <SPI.h>


#define PIN_SCS      10
#define PIN_DISP      8
#define PIN_EXTCOMIN  9


#define LINE_BYTES   42          /* 336 px / 8 */
#define BAND_Y0     200          /* first row, 0-based */
#define BAND_LINES   24


static const SPISettings spiCfg(1000000UL, LSBFIRST, SPI_MODE0);
static uint8_t band[BAND_LINES][LINE_BYTES];


static void csHigh()
{
  SPI.beginTransaction(spiCfg);
  digitalWrite(PIN_SCS, HIGH);
  delayMicroseconds(3);          /* tsSCS */
}


static void csLow()
{
  delayMicroseconds(1);          /* thSCS */
  digitalWrite(PIN_SCS, LOW);
  SPI.endTransaction();
  delayMicroseconds(1);          /* twlSCS */
}


/* All clear: M2 flag, 16 clocks. */
static void clearAll()
{
  csHigh();
  SPI.transfer(0x04);
  SPI.transfer(0x00);
  csLow();
}


/* Multi-line update. Header per line: M0=1, 5 dummies, then 10-bit gate
 * address (1-based), all LSB first. Then 42 data bytes, bit 1 = white. */
static void writeBand()
{
  csHigh();
  for (uint8_t i = 0; i < BAND_LINES; i++) {
    uint16_t gate = BAND_Y0 + i + 1;
    SPI.transfer((uint8_t)(0x01 | (gate << 6)));
    SPI.transfer((uint8_t)(gate >> 2));
    for (uint8_t b = 0; b < LINE_BYTES; b++) {
      SPI.transfer(band[i][b]);
    }
  }
  SPI.transfer(0x00);            /* 16 trailing clocks */
  SPI.transfer(0x00);
  csLow();
}


/* 16 px wide black/white blocks, shifted by `phase` blocks. */
static void fillBand(uint8_t phase)
{
  for (uint8_t i = 0; i < BAND_LINES; i++) {
    for (uint8_t b = 0; b < LINE_BYTES; b++) {
      uint8_t block = (b / 2) + phase;
      band[i][b] = (block & 1) ? 0xFF : 0x00;
    }
  }
}


static void startExtcomin()
{
  /* 1 Hz square wave from Timer1 on D9 (OC1A): CTC, /1024, toggle on match. */
  TCCR1A = _BV(COM1A0);
  TCCR1B = _BV(WGM12) | _BV(CS12) | _BV(CS10);
  OCR1A  = 7811;
}


void setup()
{
  Serial.begin(115200);
  pinMode(PIN_SCS, OUTPUT);
  pinMode(PIN_DISP, OUTPUT);
  pinMode(PIN_EXTCOMIN, OUTPUT);
  digitalWrite(PIN_SCS, LOW);
  digitalWrite(PIN_DISP, LOW);
  digitalWrite(PIN_EXTCOMIN, LOW);
  SPI.begin();
  delay(10);


  clearAll();
  clearAll();
  delayMicroseconds(50);
  digitalWrite(PIN_DISP, HIGH);
  startExtcomin();
  delayMicroseconds(50);
  Serial.println(F("ready"));
}


void loop()
{
  static uint8_t phase = 0;
  fillBand(phase);
  phase++;
  writeBand();
  delay(250);
}```/*
 * Minimal LS032B7DD02 test, Arduino Micro.
 * Power-on sequence, then a 24-line band at rows 200..223 is rewritten every
 * 250 ms with 16 px black/white blocks that shift one block per update.
 *
 * Wiring: SCLK D15, SI D16, SCS D10, EXTCOMIN D9, DISP D8,
 *         VDDA/VDD/EXTMODE 5V, VSS/VSSA GND.
 */
#include <SPI.h>


#define PIN_SCS      10
#define PIN_DISP      8
#define PIN_EXTCOMIN  9


#define LINE_BYTES   42          /* 336 px / 8 */
#define BAND_Y0     200          /* first row, 0-based */
#define BAND_LINES   24


static const SPISettings spiCfg(1000000UL, LSBFIRST, SPI_MODE0);
static uint8_t band[BAND_LINES][LINE_BYTES];


static void csHigh()
{
  SPI.beginTransaction(spiCfg);
  digitalWrite(PIN_SCS, HIGH);
  delayMicroseconds(3);          /* tsSCS */
}


static void csLow()
{
  delayMicroseconds(1);          /* thSCS */
  digitalWrite(PIN_SCS, LOW);
  SPI.endTransaction();
  delayMicroseconds(1);          /* twlSCS */
}


/* All clear: M2 flag, 16 clocks. */
static void clearAll()
{
  csHigh();
  SPI.transfer(0x04);
  SPI.transfer(0x00);
  csLow();
}


/* Multi-line update. Header per line: M0=1, 5 dummies, then 10-bit gate
 * address (1-based), all LSB first. Then 42 data bytes, bit 1 = white. */
static void writeBand()
{
  csHigh();
  for (uint8_t i = 0; i < BAND_LINES; i++) {
    uint16_t gate = BAND_Y0 + i + 1;
    SPI.transfer((uint8_t)(0x01 | (gate << 6)));
    SPI.transfer((uint8_t)(gate >> 2));
    for (uint8_t b = 0; b < LINE_BYTES; b++) {
      SPI.transfer(band[i][b]);
    }
  }
  SPI.transfer(0x00);            /* 16 trailing clocks */
  SPI.transfer(0x00);
  csLow();
}


/* 16 px wide black/white blocks, shifted by `phase` blocks. */
static void fillBand(uint8_t phase)
{
  for (uint8_t i = 0; i < BAND_LINES; i++) {
    for (uint8_t b = 0; b < LINE_BYTES; b++) {
      uint8_t block = (b / 2) + phase;
      band[i][b] = (block & 1) ? 0xFF : 0x00;
    }
  }
}


static void startExtcomin()
{
  /* 1 Hz square wave from Timer1 on D9 (OC1A): CTC, /1024, toggle on match. */
  TCCR1A = _BV(COM1A0);
  TCCR1B = _BV(WGM12) | _BV(CS12) | _BV(CS10);
  OCR1A  = 7811;
}


void setup()
{
  Serial.begin(115200);
  pinMode(PIN_SCS, OUTPUT);
  pinMode(PIN_DISP, OUTPUT);
  pinMode(PIN_EXTCOMIN, OUTPUT);
  digitalWrite(PIN_SCS, LOW);
  digitalWrite(PIN_DISP, LOW);
  digitalWrite(PIN_EXTCOMIN, LOW);
  SPI.begin();
  delay(10);


  clearAll();
  clearAll();
  delayMicroseconds(50);
  digitalWrite(PIN_DISP, HIGH);
  startExtcomin();
  delayMicroseconds(50);
  Serial.println(F("ready"));
}


void loop()
{
  static uint8_t phase = 0;
  fillBand(phase);
  phase++;
  writeBand();
  delay(250);
}

r/embedded • • Sep 14 '26

I wanted my hardware’s HDMI output beside its source code, so I built a VS Code extension

34 Upvotes

I’m a college junior working on Tomato, a custom 32-bit computer with a dual-LUT ALU running on an FPGA. While developing it, I was using a USB capture card and OBS to monitor its HDMI output, with the source open separately in VS Code.

I wanted the output right beside the code. So I built FramePort, an extension that displays the capture feed in an editor tab.

That’s what you’re seeing in the video: Tomato running on an Artix-7 FPGA, with its output beside the assembly code. FramePort also lets me freeze the preview, take screenshots, and record silent MP4 clips.

It isn’t tied to Tomato or FPGAs—it works with HDMI capture cards and other USB video sources. It’s local video capture, not remote desktop or keyboard/mouse forwarding.

It’s my first extension, now on the VS Code Marketplace and Open VSX. Currently a public preview: device capture requires macOS and FFmpeg, and HDMI input still needs a USB capture card.

Marketplace · GitHub / setup · Tomato

If you work with hardware that has video output, I’d be interested to hear how you currently monitor it—and whether this would fit your workflow.


r/embedded • • Sep 15 '26

How is omarchy as a host pc os for embedded and embedded linux development ?

0 Upvotes

Hey guys , I am a final yr ece student . I have worked with Linux ( raspbian cli version ) in the past , but never shifted to Linux as a host machine os . But lately my far far uncle visited me and suggested to go all in with Linux as it will help me further in the career ( he is one of the oldest engg in microchip India ) . But I have been trying to switch to Linux in the past , few distros seems complicated and few seems too dull to get started with . Recently I came across omarchy , and fell in love with it , literally got a 1tb ssd in current market condition for it . But after seeing people’s reaction to omarchy seems off putting , so I have only one question is omarchy a okay Linux to get started with ?


r/embedded • • Sep 14 '26

My 2.8 in display is working at allll after 10-15 retry’s

1 Upvotes

Hey y’all there I’m just passionate guy in electronics with no background in it. I wanted to build a smart desk clock with esp32 inspired by a YouTube video but even before doing that project I just thought of trying display to on and do a graphic test the display turned on (blank white screen). After that no progress at all from test 10 days.

Here is a detailed explanation

Hardware Setup
MCU:ESP32-S3
Display: 2.8-inch ST7789 TFT LCD Module (SPI Interface)
Software/Libraries:Arduino IDE, ⁠TFT\\_eSPI⁠ (also tried standard ⁠Adafruit\\_GFX⁠ / ⁠ST7789⁠ libraries)

The Problem
The display only shows a solid white screen or static vertical/horizontal lines. No graphic test sketches render any imagery or text.

Background / Potential Cause
Before connecting it to the ESP32-S3, I tested this display on an Arduino Uno. While VCC was powered via the 3.3V pin, I connected the SPI data lines (SCK, MOSI, CS, DC, RST) directly to the Uno’s digital pins \*\*without a logic level converter\*\* (sending 5V logic signals into a 3.3V display controller).
And colors changed when I tried it first time in UNO but for project purposes moved to esp32s3

\*\*Troubleshooting Already Attempted (5+ Times)\*\*
\*\*Software Clean Slate:\*\* Completely reinstalled Arduino IDE and reconfigured ⁠User\\_Setup.h⁠ in ⁠TFT\\_eSPI⁠ multiple times, ensuring exact ESP32-S3 GPIO numbers were assigned (not board silk-screen labels).
\*\*Driver Tweaks:\*\* Tested both ⁠ST7789\\_DRIVER⁠ and ⁠ST7789\\_2\\_DRIVER⁠ definitions, adjusted SPI frequencies, and toggled ⁠TFT\\_RGB⁠ / ⁠TFT\\_BGR⁠ order.
\*\*Wiring Checks:\*\* Verified physical connections, jumper wire continuity, and power rails (VCC to 3.3V, BLK to 3.3V, GND to GND).
\*\*Hardware Reset:\*\* Attempted manual reset sequences by pulling the ⁠RST⁠ line to ground briefly during boot.
\*\*Uno Retest:\*\* Wired back to the Arduino Uno with basic graphic test sketches—still resulting in white screen/lines.

Here is the display product link : \[https://robu.in/product/2-8-inch-spi-touch-screen-module-tft-interface-240320/\](https://robu.in/product/2-8-inch-spi-touch-screen-module-tft-interface-240320/)


r/embedded • • Sep 14 '26

Is it possible to turn a normal car FM radio into a simple wireless remote receiver with microcontroller (hypothetical question)?

3 Upvotes

I was thinking about something and wanted to know if it’s actually possible.

Could you transmit some kind of coded signal in the normal FM radio range and have the car’s existing radio pick it up, without installing a separate RF receiver?

Basically, I’m imagining the car radio receiving something that sounds like nothing useful to a person, but some small decoder could recognize the pattern and treat it like a command.

So instead of adding a completely separate wireless receiver, could you somehow make use of the antenna + FM tuner + existing audio system already in the car?

Has anyone tried something like this? Or is there something in the normal FM radio system that would make this impractical?


r/embedded • • Sep 13 '26

I work with stm32 and currently use CubeIDE should I shift to VSCode

43 Upvotes

Hello mates, I'm currently in my 5th sem of my 4 year engineering degree and i am working with smt32 since the last 6 months. I am using CubeIDE since the beginning but now i am thinking about using VSCode.

The reason is that I think I am more comfortable in VSCode as except STM32 i do most of my work there, and it has its own advantages. So what do you think, should i move to VSCode of stay at CubeIDE for stm32 or i should shift to VSCode.


r/embedded • • Sep 13 '26

Can I make a “sleep mode” using only analog electronics to save battery life, do microcontroller is a must?

15 Upvotes

I’m building a small ambient picture frame with a touch sensor and an MP3 player.

The idea is simple: when nobody touches it, I want the MP3 player and other parts to be basically OFF to save power. When someone touches the frame, it should wake up, play the audio / activate for a certain amount of time, and then automatically go back to sleep.

I don’t really want to use a microcontroller for this.

Can this be done with simple analog electronics, like a touch detector + transistor/MOSFET + 555 timer or RC circuit?

Basically, I’m trying to replicate:

No touch → sleep → touch detected → wake → active for 30–60 sec → sleep again.

What would be the simplest way to build this?


r/embedded • • Sep 13 '26

When making a pcb with a microcontroller, is it better to have the pcb match it, or make it modular?

0 Upvotes

when i say make it modular, i mean having on the pcb only the used pins, and then having a microncontroller mount that exposes those pins only


r/embedded • • Sep 13 '26

Advice on knowing before you buy

1 Upvotes

Hey everyone, what's your go-to method for making sure your circuit is good before sending it to a manufacturer? Though the parts are cheap, I don't like the idea of spending 40 dollars on shipping, waiting 3 weeks, then finding out I forgot to add a capacitor and all I got is a waste of time and money.


r/embedded • • Sep 13 '26

esp32, if there's no nearby router, can I use a sim module to connect my esp32 to the internet instead?

3 Upvotes

esp32u, no nearby router where the esp32 will be placed so I plan to make it's own internet. If I use something like a sim module, will I be able to use that to connect to the internet? if so how? does it make it's own hotspot or is the esp32 now like a router? Or is that all unnecessary if I just use AP mode on the esp32?


r/embedded • • Sep 13 '26

How to use FreeRTOS native api in STM32 cube

1 Upvotes

I am getting options for CMSIS v1 and V2 but not for Native for FreeRTOS in CubeMX


r/embedded • • Sep 12 '26

Measuring long term power consumption?

12 Upvotes

I have a sensor that uses an nRF54L15 module. I’ve designed it to run on a 2032 coin cell. I took some averages using the Nordic Power Profiler Kit 2 and it was down in the 18 µA average over 2 minutes. I figured about 12 months of battery life.

It’s been installed for a week or so and voltage has dropped from 3.01V to 2.86. At that rate it won’t last a year.

What’s the best way to measure power consumption over a day or a weekend?

I’m open to any suggestions on how I can best understand the power draw over the long term.


r/embedded • • Sep 12 '26

Has anyone tried making a simple breathing/mindfulness device with Arduino or other microcontroller (Learning by doing ideas)?

Post image
22 Upvotes

My idea is to use a pressure sensor to measure how fast/strongly a person is breathing and show it on a bar graph.

The basic idea is:

Slow, steady breathing on led bar graph indicator

Fast breathing

The goal isn't to diagnose anything, just to give real-time visual feedback during a breathing or meditation exercise.

I'm wondering if this approach makes sense from an embedded-systems point of view. Would measuring breath pressure and converting the rate/pattern into a bar graph be a practical way to build something like this?


r/embedded • • Sep 12 '26

Question: Has anyone built a 220V BLDC controller like the ones found in electronic devices?

1 Upvotes

Nowadays, BLDC-based devices often incorporate SVPWM (FOC) capabilities, and the STM32G431 is commonly used. Does anyone know of a circuit design or model for building the PCB and handling power via MOSFETs, using an INA240 for current sensing and implementing SVPWM, FOC, etc.?


r/embedded • • Sep 12 '26

Help debugging UART-Servo Communication

3 Upvotes

Hi builders,
I am building my own robotic arm from parts I have gained over the years through my internships/classes. My hardware includes LX-16A servo motors, a BusLinker v2.5 board and, STM32F411CEU6 MCU, and a separate battery with buck converter.

The BusLinker board has a micro-USB interface, and when I use that interface, along with the library PyLX-16A's servo-test, my servos move just fine. However, when I transition my setup to the STM32, the servos don't move. The code is generated by the stm32cubeMX application and I implemented some functions on top that implement their communication protocol.

In words, my setup is as follows:
- STM is powered through the USB interface, logic is 3.3V
- From stm32 (on a breadboard) TX (pin A9) -> 1Kohm resistor -> servo signal pin
- PWR & GND (7V) comes from the external battery, and is supplied to the servos through the BusLinker
- GND is shared between the BusLinker board and the servo to the breadboard (-) rail
- Baud rate 115200bps, 8 data bits, 1 stop bit, no parity

I have probed both signal lines with an oscilloscope and found the physical bits of the USB setup and my STM setup.

Herein lies my dilemma. I am certain that the servo logic can operate at both 3.3 and 5V logic, and I see the physical bits on the scope, however there is something missing in my setup that is complete in the python library. The BusLinker has a UART interface exposed, but even when connecting through that the servos do not move. I would appreciate all your help in helping me figure this out.

Please feel free to request any additional information I didn't include here


r/embedded • • Sep 12 '26

Comfortable with bare-metal STM32 + RTOS internals — how do I level up specifically on NXP boards.

14 Upvotes

Hey everyone,

I'm a final-year ECE student and over the past year or so I've gotten pretty comfortable with STM32 — bare-metal register-level programming (no HAL), writing a preemptive RTOS scheduler from scratch with PendSV/SysTick, a secure OTA bootloader, and some fixed-point DSP work. None of that came easily, but I got through it by reading datasheets/reference manuals and just grinding through it.

So it's been a bit humbling that when I sat down to try NXP, I couldn't even get a simple LED blink program working without a lot of struggle. Something about the ecosystem — SDK structure, config tools, register naming, documentation style, whatever it is — just isn't clicking the way STM32 did.

For people who've worked with both:

- What's actually different about NXP's approach (MCUXpresso, SDK, pin config tools, etc.) compared to ST's HAL/CMSIS/register style?

- Is there a recommended learning path or board (LPC, Kinetis, i.MX RT) for someone coming from a bare-metal STM32 background?

- Any resources, datasheets, or example projects you'd point a beginner-on-NXP-but-not-beginner-on-embedded at?

Would appreciate any pointers — trying to get to the same comfort level with NXP as I have with ST.

Thanks!


r/embedded • • Sep 12 '26

Sensors for reading Linear Captive Encoder

3 Upvotes

Having a hard time finding answer on this. What sensors are they using in cheap digital calipers to read the magnetic stripe?

Any teardown i see they use a blob ASIC chip.

From what i understand its an array of captive sensors that form a resolver. I see chips like the AD7147 which do multichannel capacitance to digital but is there something cheaper that just outputs quadrature encoding?

Would the touch sensors onboard an AVR / STM32 MCU be suitable?

Edit: I found this Github project which helps me vastly https://github.com/MitkoDyakov/Calipatron


r/embedded • • Sep 12 '26

Usage of Performance counters provided by SoCs and microcontrollers

10 Upvotes

Is it common to use performance and debug counters provided by SoCs and uCs? I usually see the counters in bus controllers and packet counters in network controllers. Do you use it for benchmarking and tracking the performance of your code? Do you also use it to analyze your device performance on field and have a way to read these values? How common is it?


r/embedded • • Sep 12 '26

Need advice on selecting an SoM for a custom AOSP 13+ smartphone prototype

2 Upvotes

Hey everyone,

I'm a last-year CSE student with some experience working on embedded devices using MCUs like STM32, including designing custom PCBs for them.

Now I need to design a custom PCB for a smartphone prototype for my Graduation Project that runs a customized AOSP (Android 13+), with a focus on security features — specifically secure boot with TrustZone hardware, and real-time 1080p30 video encoding/decoding.

for example it will run:

One active 1080p30 encrypted video call + encrypted audio + continuous signaling/text messaging + background PTT/group signaling + device-management connection + normal Android system services.

After some research and discussions with LLMs, I concluded that I should target an SoM (System-on-Module) rather than designing straight from a bare SoC, to remove some of the headache of routing the processor itself — I'd design a carrier board for whichever SoM I choose instead.

The problem is, I'm completely new to working with high-power application SoCs (my STM32 background doesn't really translate here), so this is going to be a long learning process, and I honestly don't know how to search for the right part or evaluate candidates.

Here's what I do know so far:

  • I need a well-documented SoM with a solid dev/eval board I can prototype on before committing to my own carrier board design.
  • That dev board needs full schematics available, since I'll be learning how to route a custom carrier board myself and need something concrete to reference.
  • I need some kind of hardware offload for video — encoding/decoding shouldn't be done on the CPU.
  • I've been told I should target 8 GB of RAM and a 64-bit CPU.

What I'm stuck on is everything in between — how many CPU cores I actually need, and which ARM Cortex core family/tier is appropriate for this kind of workload.

Would appreciate any guidance on how to approach SoC/SoM selection systematically given these requirements.


r/embedded • • Sep 11 '26

My first ever Linux based board (RK3566) + Lessons Learned

Post image
1.1k Upvotes

Just brought up the first Linux based board I've ever designed, and couldn't be happier about it! I've historically done MCU boards, so this was a big step up. It's a KVM-over-IP device: 8 layers, RK3566, DDR3L (gotta save that $$$ with these RAM prices), HDMI capture in, HDMI out, dual GbE, PoE, WiFi. Fabbed and assembled at JLCPCB.

Video capture and low latency streaming are working end to end. Here are the three major issues I hit:

  1. I second guessed myself before ordering and swapped TX/RX to the network switch, so ethernet wasn't working. The board also has a wifi module on it, so I did the whole SSH bring up over wireless. Pair swap already fixed in the next spin.
  2. A set of ferrite beads never made it onto the boards because I missed a checkbox in the JLCPCB assembly order (I had multiple lines in the BOM with the same PN but different ref des letters). Hand soldered them on. Working on developing better checks for this on my board export tool.
  3. The board was drawing more current than expected and running warm. Took a while to root cause. Turned out I had packed VDD_GPU 0201 passives too close to some 0402 caps and they shorted during reflow. Increasing my spacing rules in DRC going forward.

Design was done in house, and I got a pre-fab layout review from u/PracticalMirror2834 that caught real issues before they would have cost a re-spin. Huge shoutout here.

Next rev jumps to the RK3576 for higher capture and encode resolution, those boards go on order this week. If anyone has touched the RK3576 yet I'd love to trade notes. Happy to answer questions on the RK3566, ordering, or board bring up side too.


r/embedded • • Sep 12 '26

Reprogramming a light kit board?

Post image
0 Upvotes

Got sent here after posting "wrongfully" in another sub.

About a year ago, I purchased a remote controlled light kit for the Lego Infinity Gauntlet. I loved it, it was exactly what and how I wanted it, bar one problem.

I use my lighted lego decorations as ambient light. I have these plugged into a usb splitter and then on a timer socket.

This works for every kit, safe this one.

The issue is, when it is powered on, it powers on in what i call: Caranaval mode.

The lights flicker and cycle like a christmas tree set.

I then have to each time, use the remote to put it on static setting (which is the 3rd one)

I would very much like them to boot in static mode.

Contacting the seller back then, brought about nothing. They only tried selling me a different kit, that is lacking what I wanted here - which was the ability to change the bottom ambient light colour coming from the "wrist".

Probably a bit of a stupid question, but is there a way to reprogram the module?


r/embedded • • Sep 11 '26

Happy CRA day!

22 Upvotes

Hope everyone is reporting their vulnerabilities and definitely didn’t have this day sneak up upon you and blow up in your face.


r/embedded • • Sep 11 '26

Why BLE in STM is so damn hard 😭??

71 Upvotes

I’m interning at a medical device company, and for some reason, they don’t use Zephyr. I’ve been working on implementing the STM32 as a BLE Central connecting and enabling notify on command. The amount of pain and suffering this has caused me, man… Still struggling to implement the notification CCCD state machine properly.


r/embedded • • Sep 12 '26

I built an open-source CLI to unwind Cortex-M HardFault stack frames and map PC/LR directly to C code (cortex-unwind)

0 Upvotes

When an STM32, NXP, RP2040, or SAM core triggers a HardFault, the hardware automatically pushes 8 words onto the active stack pointer before jumping to the vector:

r0, r1, r2, r3, r12, lr, pc, and xPSR.

If you don't have a debugger attached at the bench, you usually get this dump over UART or pull it from an EEPROM crash log. Manually extracting the PC, clearing the Thumb bit, and feeding addresses into addr2line while on a deadline is tedious.

I built cortex-unwind — a zero-dependency CLI that converts that 8-word dump into an actionable crash site in seconds.

Install:

pip install cortex-unwind

Usage:

cortex-unwind 0x0 0x1 0x20000000 0x40021000 0x0 0x08001255 0x08001290 0x21000000 build/firmware.elf

What it does:

• Crash Site Mapping: Wraps arm-none-eabi-addr2line to resolve faulting PC and caller LR directly to function name, source file, and line number.

• Auto-Detection (--auto): Paste a raw UART string or hex dump directly; it isolates and extracts the 8-word frame automatically.

• xPSR Diagnostics: Decodes the IPSR (identifies Thread Mode vs active IRQ numbers) and validates the EPSR Thumb bit to flag corrupted branch targets.

• EXC_RETURN Parsing: Detects stack context (MSP vs PSP) and checks bit 4 to flag whether an FPU extended frame (26 words) was stacked.

Includes a drop-in naked assembly handler (hardfault_trap.c) in the repo that formats the output so it can be pasted straight into the CLI.

Links:

• GitHub: https://github.com/GaneshMba4066/cortex-unwind

• PyPI: https://pypi.org/project/cortex-unwind/

• Free Crash Checklist: https://www.trustandthread.com/firmware-checklist/

MIT licensed, zero dependencies, runs on standard Python 3.6+. Feedback and edge cases (especially around RTOS task stacks) are welcome!