Skip to content

Bare Metal

Embedded systems and firmware: C, RTOS, IoT and automotive

t/bare_metal

Code that runs where there is no operating system to blame. Microcontrollers, RTOS scheduling, CAN bus, power budgets, bootloaders and the oscilloscope that tells the truth.

17 members
9 posts
Created Aug 2026

Community rules

3 rules for t/bare_metal

  1. Name the chip

    MCU, toolchain and RTOS version. "My ESP is broken" is not enough.

  2. Bring the detail

    Versions, error text, what you already tried. "It does not work" is not a question anyone can answer.

  3. No drive-by self promotion

    Share your own work when it answers the thread. A link with no context is an advert, and it gets removed.

Moderated by Diego Ramírez

Discussions

1
  • Bare Metal

    The main discussion

    Primary

    Nobody has said anything yet. Be the first.

Showing 9 posts.

Posts in t/bare_metal

6

  • Accepted answer

    IWDG as the last line, always. It runs from LSI, its own clock. If your clock tree dies, PLL unlock, HSE crystal cracked, WWDG dies with it because it runs from APB clock. IWDG still resets you. Never kick from an ISR or a timer callback. Never kick from "the idle task" either. Do this: every critical task sets its own bit in a check-in word each cycle. One supervisor task, priority just below MotorControl, wakes every 20 ms, checks that ALL bits are set, clears them, then kicks IWDG. If any task did not check in, no kick, reset. Runaway loop in one task = its bit not set = reset. This catches what your colleague is worried about without WWDG. LSI is not accurate. On F4 the datasheet range is wide, something like 17 to 47 kHz. Calculate your timeout at the fast end, not the typical. At boot, read RCC_CSR reset flags (IWDGRSTF, WWDGRSTF, BORRSTF, PINRSTF...), store them, then clear with RMVF. Log it. Otherwise you will never know the watchdog fired, you will only know "it restarted sometimes". WWDG on top is fine if you want early-kick detection, but it is not independent. Do the check-in word first.
    1 reply
10

  • The PRIMASK save and restore tip. I have seen so many codebases with __enable_irq() at the end of every critical section, and then a nested one enables interrupts in the middle of the outer one. Great post
  • Bug 4 has a cousin in FPGA land: the CPU writes a descriptor, then sets the "go" bit in a register, and the fabric reads the descriptor before the write left the CPU. Same fix, a barrier. Very nice post.