Flashing & Debugging Guide
Overview
To update the firmware on the Snake-V1, you can use either the USB-C interface (DFU Mode) for quick updates or the SWD (Serial Wire Debug) header for development and real-time debugging.
Method 1: USB Flashing (DFU Mode)
The STM32WB35 microcontroller features a built-in USB bootloader. This is the most convenient method for users who do not own an external debugger.
Prerequisites
- STM32CubeProgrammer: Download and install from STMicroelectronics.
- A USB-C to USB-A (or USB-C) data cable.
Steps
- Enter Bootloader Mode:
- Press and hold the BOOT0 button (if available on your hardware revision) while connecting the device to your computer via USB.
- Alternatively, if the firmware is already running, the device may support a "Reboot to Bootloader" command via the CLI.
- Open STM32CubeProgrammer:
- Select USB from the connection dropdown menu on the right.
- Click Refresh. The "USB1" port should appear in the Port field.
- Click Connect.
- Flash the Firmware:
- Go to the Erasing & Programming tab (pencil icon).
- Browse for your firmware file (usually
snake_v1_firmware.binor.elf). - Check the Verify programming and Run after programming checkboxes.
- Click Start Programming.
Method 2: SWD Flashing & Debugging
For developers who need to step through code or recover a "bricked" device, the SWD interface is required.
Prerequisites
- Hardware Debugger: ST-LINK (V2 or V3), Segger J-Link, or a CMSIS-DAP probe.
- Software: STM32CubeIDE, VS Code (with Cortex-Debug extension), or OpenOCD.
Wiring Diagram
Connect your debugger to the Snake-V1 SWD pads/header as follows:
| Debugger Pin | Snake-V1 Pin | | :--- | :--- | | VCC (3.3V) | VCC / 3V3 | | SWDIO | SWDIO | | SWCLK | SWCLK | | GND | GND | | NRST (Optional) | RESET |
Flashing via CLI (OpenOCD)
If you prefer the command line, use the following command to flash a binary:
openocd -f interface/stlink.cfg -f target/stm32wbx.cfg \
-c "program firmware.elf verify reset exit"
Debugging Workflow
The Snake-V1 utilizes the STM32WB35's dual-core architecture. When debugging, ensure your environment is targeting the Cortex-M4 (Application Core).
Using STM32CubeIDE
- Import the project into your workspace.
- Right-click the project -> Debug As -> STM32 Cortex-M C/C++ Application.
- The IDE will switch to the Debug Perspective, allowing you to set breakpoints and inspect peripheral registers for the CC1101 or the IR transmitter.
Serial Console Debugging
The default firmware provides debug logs via the USB-C port (Virtual COM Port).
- Baud rate: 115200
- Data bits: 8
- Stop bits: 1
- Parity: None
You can use any serial monitor (e.g., PuTTY, Tera Term, or the Arduino Serial Monitor) to view real-time feedback from the sensors and sub-GHz transceiver.
[INFO] Snake-V1 Initializing...
[INFO] CC1101 Transceiver detected.
[INFO] IR Receiver ready.
[DEBUG] Sub-GHz frequency set to 433.92MHz
Troubleshooting
- Device not recognized via USB: Ensure you are using a USB cable capable of data transfer; some cables are "charge-only."
- Connection Refused (SWD): If the MCU is in a low-power state or pins are repurposed, you may need to use "Connect under reset." Hold the Reset button, click Connect in your software, and release the button immediately.
- Verification Failed: This often indicates a power stability issue. Ensure the device is getting a clean 3.3V supply from the debugger or USB port.