Skip to content

Build and Flash Station

This guide covers building the RTK Base firmware and programming both the ESP32 and STM32 microcontrollers.

Prerequisites

  • ESP-IDF v5.3.1 or later
  • USB-to-Serial adapter (FTDI/CP2102)
  • STM32 programmer (optional, for direct programming)

Building the Software

Build Commands

RTK Base (Main Firmware)

idf.py -B build-rtkbase/ build -DRTK_BASE=1 -DSTATION=0

Station Board

idf.py -B build-station/ build -DRTK_BASE=0 -DSTATION=1

Build Parameters:

  • -DRTK_BASE=1: Build RTK Base firmware
  • -DSTATION=1: Build station board firmware
  • -B build-<target>/: Build directory

Full Build with Port

# Build and specify port for flashing
idf.py -B build-station/ build -DRTK_BASE=0 -DSTATION=1 -p /dev/ttyUSB1

Programming the ESP32

Prerequisites

  • USB-to-Serial cable connected
  • Boot mode: IO0 (BP S3) pulled low during reset
  • Use BP S2 for manual reset

Flash Command

idf.py -B build-station/ flash -DRTK_BASE=0 -DSTATION=1 -p /dev/ttyUSB1

Note: After programming, press BP S2 to reset. BP S3 (IO0) must be released for normal boot.

Programming the STM32

The ESP32 can program the STM32 automatically, or you can program it directly.

Method 1: Via ESP32 (Automatic)

Setup

Place the file station2.mot in the root directory:

  • Empty file: ESP32 does not program STM32
  • Different binary: ESP32 programs STM32 automatically
  • Same binary: No action taken

Binary Location

The STM32 binary is located in the Navigation project:

firmware/station2/bin/station2.mot

Branch: SM1000-B2

Process

  1. Copy station2.mot to RTK Base root directory
  2. Boot the ESP32
  3. ESP32 detects different binary
  4. Automatic programming occurs
  5. Verification performed

Method 2: Direct Programming

Using curl

Connect to the STM32 via the ESP32's web interface:

# Using link-local address
curl --data-binary @station2.mot '[fe80::1%wlan0]/firmware?stm&force'

# Or using IP address
curl --data-binary @station2.mot '[192.168.4.1]/firmware?stm&force'

Notes:

  • Replace wlan0 with your wireless interface name
  • Use fe80::1%<interface> format for link-local
  • force parameter forces programming regardless of current version

Using fwbelrob

Requirements: - FTDI cable at 115200 baud, 8N1 - Connection to CEC or SGB port

Command:

fwbelrob -T stm32uart -d /dev/ttyUSB0 write station2.mot

Cable Connection:

CEC Port:

  • Yellow -> Pin 1
  • Orange -> Pin 2
  • Black -> Pin 4

SGB Port:

  • Yellow -> Pin 1
  • Orange -> Pin 2
  • Black -> Pin 3

Build Artifacts

After successful build, the following files are generated:

ESP32

  • build-<target>/ye-esp32.bin - Main firmware binary
  • build-<target>/ye-esp32.elf - ELF file for debugging
  • build-<target>/ye-esp32.map - Memory map
  • build-<target>/bootloader/bootloader.bin - Bootloader
  • build-<target>/partition_table/partition-table.bin - Partition table
  • build-<target>/ota_data_initial.bin - OTA data

Web UI

  • webUI/ - Web interface files
  • Packaged as webUI.tar.gz for distribution

Complete Flash Sequence

Initial Flash

# 1. Build firmware
idf.py -B build-rtkbase/ build -DRTK_BASE=1 -DSTATION=0

# 2. Flash bootloader, partition table, and app
idf.py -B build-rtkbase/ flash -DRTK_BASE=1 -DSTATION=0 -p /dev/ttyUSB0

# 3. Reset device (press BP S2)

OTA Update

For field updates, use the web interface or MQTT:

# Via REST API
curl -X POST "192.168.4.1/system?firmware=http://server/firmware.bin"

# Or upload directly
curl -X POST "192.168.4.1/update-firmware?esp" --data-binary @firmware.bin

Troubleshooting

Flash Failures

Error: "Failed to connect to ESP32"

  • Check USB cable connection
  • Ensure IO0 (BP S3) is grounded during reset
  • Try lowering baud rate: -b 115200

Error: "Invalid head of packet"

  • Check USB cable quality
  • Try different USB port
  • Verify ESP32 is in download mode

STM32 Programming

Error: "Cannot connect to STM32"

  • Verify station2.mot file is valid
  • Check STM32 is powered
  • Try force parameter

Error: "Programming timeout"

  • Check file integrity
  • Verify sufficient power
  • Retry with direct programming method

Build Errors

Error: "CMake configuration failed"

  • Run idf.py fullclean
  • Re-export ESP-IDF environment
  • Check ESP-IDF version compatibility

Development Workflow

Incremental Build

# After code changes, just build
idf.py -B build-rtkbase/ build -DRTK_BASE=1 -DSTATION=0

# Flash only if needed
idf.py -B build-rtkbase/ flash -DRTK_BASE=1 -DSTATION=0 -p /dev/ttyUSB0

Monitor Output

# View serial output after flashing
idf.py -B build-rtkbase/ monitor -p /dev/ttyUSB0

# Or use minicom
minicom -D /dev/ttyUSB0 -b 115200

Clean Build

# Full clean rebuild
idf.py fullclean
idf.py -B build-rtkbase/ build -DRTK_BASE=1 -DSTATION=0

References