STM32 how to get last reset status

@floppes recommends to: Read RCC_CSR as soon as possible after startup, before initializing any other peripheral. It is safe to initialize your system clocks first (which is done in SystemInit() if you use ST’s libraries). Now, to determine the exact reset cause, here’s a full function to help you. Note that all reset flags can … Read more

What are the various ways to disable and re-enable interrupts in STM32 microcontrollers in order to implement atomic access guards?

Multiple ways to enable/disable interrupts in STM32 mcus: 1. Via ARM-core CMSIS: 1.A. For global interrupts __enable_irq() // enable all interrupts __disable_irq() // disable all interrupts // Returns the current state of the priority mask bit from the Priority Mask // Register. [0 if global interrupts are **enabled** and non-zero if they // are **disabled**] … Read more

Best way to read from a sensor that doesn’t have interrupt pin and requires some time before the measurement is ready

How to do high-resolution, timestamp-based, non-blocking, single-threaded cooperative multi-tasking This isn’t a “how to read a sensor” problem, this is a “how to do non-blocking cooperative multi-tasking” problem. Assuming you are running bare-metal (no operating system, such as FreeRTOS), you have two good options. First, the datasheet shows you need to wait up to 9.04 … Read more