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)¶
Station Board¶
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¶
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:
Branch: SM1000-B2
Process¶
- Copy
station2.motto RTK Base root directory - Boot the ESP32
- ESP32 detects different binary
- Automatic programming occurs
- 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
wlan0with your wireless interface name - Use
fe80::1%<interface>format for link-local forceparameter forces programming regardless of current version
Using fwbelrob¶
Requirements: - FTDI cable at 115200 baud, 8N1 - Connection to CEC or SGB port
Command:
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 binarybuild-<target>/ye-esp32.elf- ELF file for debuggingbuild-<target>/ye-esp32.map- Memory mapbuild-<target>/bootloader/bootloader.bin- Bootloaderbuild-<target>/partition_table/partition-table.bin- Partition tablebuild-<target>/ota_data_initial.bin- OTA data
Web UI¶
webUI/- Web interface files- Packaged as
webUI.tar.gzfor 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.motfile is valid - Check STM32 is powered
- Try
forceparameter
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¶
References¶
- ESP-IDF Programming Guide
- STM32 Programming Manual
- Console Commands - For post-flash configuration