博文

目前显示的是标签为“STM32”的博文

How to include a file in an stm32cubeide project?

图片
 In STM32CubeIDE, “including a file” usually means adding it to the project so it gets built , and/or making headers discoverable by the compiler . Here are the common cases. 1) Add an existing .c/.h file into your project (copy into project) In Project Explorer , choose the target folder: C files → Core/Src Header files → Core/Inc Right-click the folder → Import… Choose General → File System → Next Browse to your file(s) → check them Make sure “Copy files into project” is enabled Finish Then in your code: # include "myfile.h" 2) Add a new source/header file (create inside the project) Right-click Core/Src → New → Source File Name it myfile.c → Finish Right-click Core/Inc → New → Header File Name it myfile.h → Finish 3) Use a file that lives outside the project (link, don’t copy) Useful if you share code across multiple projects. Right-click your target folder (e.g., Core/Src ) → Import… General → File System ...

How to reflash microcontroller Klipper?

图片
 Here’s the standard (safe) way to reflash Klipper firmware to a printer microcontroller board , plus the common variations (SD card, USB/DFU, RP2040 UF2, etc.). 0) When do you actually need to reflash? Most “Klipper updates” are host-only . You typically reflash the MCU when Klipper/Mainsail/Fluidd shows a firmware version mismatch or you changed MCU settings in make menuconfig . Klipper’s FAQ explicitly notes you may need to recompile + flash after upgrades (and that RESTART / FIRMWARE_RESTART does not load new firmware). 1) Build the correct firmware (on your Pi / host) Go to Klipper source and open config: cd ~/klipper make menuconfig Tip: the comments at the top of your printer board’s Klipper config usually tell you exactly what to pick in menuconfig . Compile: make clean make (“make clean” is commonly used before rebuilds.) Your output firmware will appear in ~/klipper/out/ (e.g., klipper.bin or klipper.uf2 ). 2) Find the MCU device path (USB fl...

Where is my hex file on STM32?

图片
 On STM32 there isn’t a special “HEX storage” on the chip—your .hex file is generated on your PC by the build toolchain , and its location depends on the IDE/build config. If you use STM32CubeIDE (most common) Build Debug → typically here: <your_project>/Debug/ Example: ...\workspace\<project>\Debug\<project>.hex Build Release → typically here: <your_project>/Release/ Important: CubeIDE always creates an .elf . The .hex/.bin may not appear unless enabled. Enable it in CubeIDE: Project Properties → C/C++ Build → Settings → MCU Post build outputs → check “Convert to Intel Hex” (and/or Bin). If you use Keil µVision Usually in: <project>\Objects\ (or whatever you set in Options for Target). If you use IAR EWARM In the project output directory you configured (often under Debug/Exe or similar), depending on settings. Quick way to find it (any IDE) Search your project/workspace folder for: *.hex .

How to find model of microcontroller for Arduino IDE?

图片
 In Arduino -land, the “ microcontroller model” is usually determined by which Board (and sometimes Processor) you select in the IDE. If you don’t know what chip is on the board, there are a few reliable ways to find it. 1) The fastest: check Tools → Board (and Tools → Processor ) Connect the board. In Arduino IDE: Tools → Board : pick (or confirm) the board family (Uno, Nano, Mega, ESP32 Dev Module, Pico, etc.) Tools → Processor (only appears for some AVR boards like Nano/Pro Mini): this often directly shows the MCU choice, e.g. ATmega328P vs ATmega168 . If you see a “Processor” submenu, that’s basically your answer. 2) Arduino IDE 2.x: Tools → Get Board Info With the board plugged in and the correct Tools → Port selected: Tools → Get Board Info shows things like board name , VID/PID , and sometimes the identified board profile. This won’t always print the exact MCU model, but it helps you confirm the board family so you can map it to the MCU. 3...

How to disable all interrupt on STM32?

图片
 Here are the practical ways to “disable all interrupts” on STM32 , depending on what you mean (mask CPU interrupts vs. stop peripherals from generating them). 1) Mask (disable) all CPU interrupts globally This is the most common meaning: prevent any interrupt handler from running on the Cortex-M core. CMSIS (portable) way # include "cmsis_gcc.h" // or core_cm*.h via your device header __disable_irq(); // masks IRQs (PRIMASK = 1) // critical section... __enable_irq(); // unmasks IRQs Direct register (same thing) __set_PRIMASK( 1 ); // disable IRQ // ... __set_PRIMASK( 0 ); // enable IRQ Notes This masks all “normal” interrupts (IRQ) . NMI (Non-Maskable Interrupt) and HardFault still happen. 2) Also stop Fault exceptions (more “everything”) If you also want to block most fault exceptions (MemManage/BusFault/UsageFault), use FAULTMASK . __disable_fault_irq(); // sets FAULTMASK = 1 // ... __enable_fault_irq(); // clea...

How does interrupts works exactly in microcontrollers?

图片
 Interrupts are how a microcontroller stops what it’s doing (briefly) to handle an important event right now , then returns to exactly where it left off. Here’s how it works “under the hood”, step by step. The core idea Your main code runs in a loop (or an RTOS task). Hardware events happen asynchronously: a timer hits zero, a UART byte arrives, a GPIO edge occurs, ADC completes, etc. Instead of polling (“are we there yet?”), the MCU uses an interrupt : a hardware signal that asks the CPU to run a specific function called an ISR (Interrupt Service Routine). What happens when an interrupt occurs (exact sequence) 1) An event sets an interrupt flag Example: a timer overflows → the timer peripheral sets a status bit like TIMERx_IF = 1 . 2) The interrupt controller decides if it should fire An interrupt triggers the CPU only if: The peripheral’s interrupt is enabled (local enable bit), The interrupt is unmasked/enabled in the interrupt controller (e.g., N...

How to use ALT pins on STM32?

图片
 On STM32 , “ALT pins” usually means alternate functions (AF): using a GPIO pin for USART/SPI/I²C/TIM PWM/ADC, etc. You pick the pin’s AF mapping in CubeMX (or write the GPIO registers yourself). Here’s the practical way. The CubeMX way (recommended) Open STM32CubeMX (or CubeIDE → .ioc ). Go to Pinout & Configuration . Enable the peripheral you want (e.g., USART1 , SPI2 , TIM3 PWM ). CubeMX will assign default pins. To use “alt pins”: Click the pin on the package view (e.g., PA9) Choose the function you want (e.g., USART1_TX ) Or open the peripheral settings → GPIO Settings and select alternate pins there. In GPIO Configuration ensure: Mode = Alternate Function Push-Pull (most digital AF signals) Pull-up/down as needed Speed set appropriately (higher for fast edges like SPI) Generate code. CubeMX will create: MX_GPIO_Init() HAL_UART_MspInit() / HAL_SPI_MspInit() etc. that set the AF. Typical HAL GPIO init snippet ...

How to erase chip in STM32CubeIDE?

图片
 To erase the flash of an STM32 “chip” from STM32CubeIDE , you basically use the built-in STM32CubeProgrammer backend. Here’s the standard way, step by step. 1. Full-chip erase from STM32CubeIDE A) Using the Run/Debug configuration (most common) Connect your board Plug in your STM32 board via ST-LINK (or built-in debugger on Nucleo / Discovery ). Make sure drivers are installed and the board shows up in CubeIDE. Open Run/Debug configurations In the menu: Run → Run Configurations… or Run → Debug Configurations… (both dialogs are similar). Select your project/MCU config In the left tree, under STM32 Cortex-M C/C++ Application , click your project’s configuration. Go to the “Startup” or “Debugger” tab (name slightly varies by version) Look for a section like “Initialization” or “Load/Erase” . Enable Flash erase You will see options such as: “Reset behaviour” (Connect under reset, etc.) “Erase Flash” or “Flash Download” option...

How to boot stm32 Blue Pill?

图片
 On the STM32 “Blue Pill”, “booting” basically means: Power the board correctly Put it in the right boot mode (BOOT0/BOOT1) Have valid firmware in flash I’ll walk you through the typical ways to boot it. 1. Powering the Blue Pill (don’t skip this) The board has an STM32F103C8 (or CB) + a 3.3 V regulator. You can power it in three safe ways : Via USB port (Mini-USB) Plug into USB → board gets 5 V → regulator makes 3.3 V for the MCU. Via 5V pin Feed regulated 5 V into the 5V pin, GND to GND. Direct 3.3 V Feed 3.3 V into 3.3V pin, GND to GND (bypasses regulator). ⚠️ Never put 5 V on the 3.3 V pin → instant blue smoke risk. If power is good, the red power LED should light. 2. Boot mode basics: BOOT0 & BOOT1 The STM32 decides where to boot from using BOOT0 and BOOT1 at reset: On the Blue Pill: BOOT0 is broken out with a jumper. BOOT1 (PB2) is usually fixed low (GND) with a resistor. So the useful modes are: BO...