博文

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 ...

Verilog Functions and Task Usage in FPGA Development

图片
 In Verilog (and SystemVerilog), functions and tasks are both ways to package reusable logic—but they’re meant for different kinds of work. Getting this right matters in FPGA RTL because it affects synthesizability, timing, and code clarity . Functions vs Tasks (the core differences) Function Use a function when you want a pure calculation that: returns one value takes inputs does not consume time (no #delay , no @event , no wait ) is typically used inside expressions (RHS of assignments, conditions, parameters) Think: “combinational math / bit manipulations / encoding / decoding”. Task Use a task when you want a procedure that: may return multiple values via output/inout arguments is called from procedural code ( always , initial , etc.) in testbenches , can include time/event controls in synthesizable RTL , must still be zero-time (no delays/events) Think: “do these steps” (especially in testbenches), or “group repeated procedural c...

What voltage does Raspberry Pi Zero 2 W use?

图片
  The   Raspberry Pi Zero 2 W   operates at   5 volts   like all modern Raspberry Pi models. Here are the key details: Power Input Specifications: Voltage:   5V DC  (±5% tolerance, so ideally between 4.75V and 5.25V) Current:  Minimum 2.5A recommended for reliable operation (especially under load) Power Connector:  Micro USB port (same as original Pi Zero) Important Notes: Do NOT use voltages above 5V  - this can permanently damage the board. Amperage matters:  While the Pi Zero 2 W itself typically draws 0.8-1.2A under load, you need: Official recommendation:  2.5A power supply With accessories:  More if using USB devices, HATs, or cameras Power can also come from: GPIO header pins (Pin 2: 5V, Pin 6: Ground) From a USB hub that supports power delivery Compared to original Pi Zero: Pi Zero 2 W uses more power due to its quad-core processor Original Pi Zero: ~100-150mA idle Pi Zero 2 W: ~240-300mA idle Under load: Can reac...

How to design a microcontroller PCB in Altium?

图片
 Here’s a practical, Altium-first workflow to design a microcontroller PCB (from “empty project” to “ready for fabrication”), with the checks that prevent 90% of first-rev pain. 1) Start with requirements (so the schematic is correct) MCU part number + package (QFN/LQFP/BGA) Power rails (1.8/3.3/5V), max current, ADC reference needs Clocking (internal RC ok? need crystal?) Programming/debug (SWD/JTAG/USB-UART/boot pins) Interfaces (I²C/SPI/UART/CAN/USB), connector types Environment (ESD, EMI, automotive? temperature?) 2) In Altium: create a clean project structure File → New → Project → PCB Project Add: Schematic ( .SchDoc ) PCB ( .PcbDoc ) Set units , grids, and templates early (keeps footprint placement sane). 3) Build or verify your libraries (critical) You need: Schematic symbol Footprint 3D model (optional but helpful) Pin mapping correct (power pins, SWD, BOOT, NRST) Best practice: Prefer manufacturer/Altium v...

How to use LCD on Arduino?

图片
 You use an LCD on Arduino by doing two things : Wire it correctly Use the LiquidCrystal (or I2C) library in your sketch I’ll show you both the classic 16×2 LCD with parallel pins and the I2C backpack version. 1. The LCD we’re talking about Most tutorials (and this answer) assume a 16×2 character LCD that’s “HD44780-compatible”, like this: 16 characters × 2 lines Pins: VSS, VDD, VO, RS, RW, E, D0–D7, A, K If yours has only 4 pins (GND, VCC, SDA, SCL) → that’s an I2C backpack version. I’ll cover that in section 4. 2. Wiring a 16×2 LCD directly to Arduino (4-bit mode) We’ll use 4 data lines (D4–D7) to save pins. Parts: Arduino Uno (any board is fine) 16×2 LCD 10 kΩ potentiometer (for contrast) Some jumper wires Optional: 220 Ω resistor for LCD backlight Typical wiring table (4-bit mode) Assume these connections: LCD Pin Name Connect To 1 VSS GND 2 VDD +5V 3 VO Middle pin of 10k pot (contrast) Pot side 1 → GND, side 2 → +5V 4 RS A...

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...