Quick Guide: Getting Started with CooCox CoFlashCooCox CoFlash is a lightweight Windows utility originally designed to program ARM Cortex-M microcontrollers via built-in bootloaders (such as those on STMicroelectronics’ STM32 and Nuvoton chips) using serial (USART), USB DFU, or other vendor boot interfaces. This guide walks you through installing CoFlash, preparing your target MCU, creating and converting firmware, connecting hardware, and performing reliable programming and verification. It’s aimed at beginners who want a fast, practical path from a compiled binary to a flashed microcontroller.
What CoFlash does (quick overview)
- CoFlash programs flash memory on supported Cortex-M MCUs using standard bootloader protocols.
- It accepts common firmware formats (binary, sometimes Intel HEX) and writes them to device flash.
- It can erase, write, verify, and set option bytes depending on target support.
Requirements
- A Windows PC (CoFlash is a Windows program).
- Target microcontroller with a supported bootloader (check vendor docs for built‑in boot ROM/DFU/USART boot modes).
- A serial-to-USB adapter or the appropriate USB connection if the MCU exposes DFU.
- A compiled firmware image (raw binary or HEX). Typically produced by toolchains such as Keil MDK, IAR, GCC/arm-none-eabi (Makefile, PlatformIO, etc.).
- Basic wiring tools (breadboard, jumper wires) and a power supply for the target board.
Installing CoFlash
- Download the CoFlash package from a trustworthy archive or vendor hosting (note: original CooCox project activity has been limited; use community mirrors if official site is unavailable).
- Unpack the ZIP to a folder (no formal installer is typically required).
- Run the executable (often named CoFlash.exe). On first run Windows may prompt for permission — accept if you trust the source.
- If CoFlash requires drivers for a USB DFU interface or a USB-to-serial cable, install appropriate drivers (e.g., ST Virtual COM Port drivers for STLink’s VCP, Silicon Labs CP210x, or FTDI drivers for FT232-based adapters).
Prepare your firmware
- Build your project in your chosen toolchain to create a raw binary (.bin) or Intel HEX (.hex) file.
- For many bootloaders, a raw binary starting at the MCU’s flash base is required. If you have an ELF file, use objcopy to extract a binary:
arm-none-eabi-objcopy -O binary input.elf output.bin
- Ensure the firmware’s vector table and reset handler are at the correct addresses expected by the MCU bootloader. If your project links to an unexpected start address, the device may not boot after flashing.
Put the MCU into bootloader mode
Different vendors require different entry methods to their built-in bootloader. Common approaches:
- STM32 (USART/USB DFU): Use BOOT0/BOOT1 pin states to force system bootloader, or use specific hardware sequences. For example, set BOOT0 = 1 and reset the MCU to let the system bootloader run from system memory.
- Nuvoton/Freescale/Other: Follow vendor-specific boot pin or command sequences.
Consult your MCU’s datasheet or reference manual for the exact sequence. The goal is to have the MCU appear to the PC as a serial/DFU device that accepts bootloader commands.
Connecting hardware
- For serial bootloaders:
- Connect MCU RX to USB-serial TX, MCU TX to USB-serial RX.
- Connect GND between PC adapter and target board.
- Provide target power (do not rely solely on adapter unless it provides regulated 3.3V and you intend to use it).
- Optionally connect reset and boot pins to manual switches or use the serial adapter’s DTR/RTS lines to auto-reset if supported.
- For USB DFU:
- Connect the MCU’s USB data pins to the host via a USB cable or adapter and ensure USB pull-ups/pull-downs are configured per vendor bootloader requirements.
- Double-check voltage levels: many MCUs are 3.3V — do not use 5V signals directly.
Using CoFlash: a step-by-step example (typical flow)
- Launch CoFlash.exe.
- Select the communication port:
- For serial: pick the correct COM port shown in Device Manager.
- For DFU: choose the detected DFU device (if CoFlash supports it).
- Choose target MCU family if the tool requires it (e.g., STM32F1, STM32F4).
- Set the starting address for programming (commonly 0x08000000 for many STM32 devices).
- Browse and load your binary (.bin) or HEX file.
- (Optional) Configure erase behavior: full chip erase or sector/page erase.
- Click “Program” or “Flash.” The tool will usually show progress and report success/failure.
- After programming, click “Verify” if not automatic. Successful verification confirms the written data matches the file.
- Reset the MCU or power-cycle and set boot pins for normal boot (e.g., BOOT0 = 0 on STM32).
Common troubleshooting
- Device not detected:
- Check BOOT pin states and reset sequence.
- Verify correct COM port and drivers.
- Ensure USB cable is data-capable (some are power-only).
- Programming fails or hangs:
- Try a full chip erase first.
- Lower baud rate for serial bootloaders if communication is unreliable.
- Ensure correct start address and file format.
- Verify mismatch:
- Ensure you did not accidentally program the wrong memory region.
- Check for read protection or option bytes that prevent reading — these may need special handling or unlocking via vendor tools.
- MCU doesn’t run after flash:
- Confirm vector table at start of flash and that stack pointer/reset handler values are correct.
- Check that boot pins are set for user flash on reset.
Tips and best practices
- Keep a known-good bootloader recovery plan (e.g., ability to force system boot via BOOT0).
- Use checksums or version strings in your firmware so you can quickly confirm correct image after verify.
- When using serial programming, reducing baud rate can greatly improve reliability for poor-quality USB-serial adapters.
- Maintain a secure backup of working binaries — accidental overwriting or bad builds can brick devices if you lose the correct image.
- For production flashing, consider a hardware programmer (ST-Link, J-Link) that uses SWD/JTAG for higher speed and reliability.
Alternatives and when to use them
CoFlash is useful for quick in-field flashing when the MCU’s built-in bootloader is available and you don’t have a hardware debugger. For development, debugging, and handling read/write protections, hardware programmers like ST-Link, J-Link, or vendor-provided tools are preferable. If you need automated mass production programming, dedicated flasher hardware or a command-line flasher integrated into CI is recommended.
Example: flashing an STM32F103 via USART
- Build binary and ensure it’s linked for 0x08000000.
- Set BOOT0 = 1 and reset MCU.
- Open CoFlash, select COMx (USB-serial adapter).
- Set address 0x08000000 and load output.bin.
- Choose erase -> full chip (if necessary).
- Click Program and wait for completion.
- Set BOOT0 = 0 and reset to run user code.
Resources for further reading
- Your MCU’s reference manual and system memory bootloader documentation.
- Community forums and archived CooCox documentation for device-specific notes.
- Toolchain docs (arm-none-eabi, Keil, IAR) for producing properly linked binaries.
CoFlash remains a handy, minimal tool for quickly programming Cortex-M devices using built-in bootloaders—particularly useful when you don’t have a hardware programmer on hand. Follow the MCU vendor’s bootloader procedure, verify address and file format, and use the troubleshooting tips above to resolve common issues.
Leave a Reply