Archive STM32 firmware to legacy/stm32/: - src/, include/, lib/USB_CDC/, platformio.ini, test stubs, flash_firmware.py - test/test_battery_adc.c, test_hw_button.c, test_pid_schedule.c, test_vesc_can.c, test_can_watchdog.c - USB_CDC_BUG.md Rename: stm32_protocol → esp32_protocol, mamba_protocol → balance_protocol, stm32_cmd_node → esp32_cmd_node, stm32_cmd_params → esp32_cmd_params, stm32_cmd.launch.py → esp32_cmd.launch.py, test_stm32_protocol → test_esp32_protocol, test_stm32_cmd_node → test_esp32_cmd_node Content cleanup across all files: - Mamba F722S → ESP32-S3 BALANCE - BlackPill → ESP32-S3 IO - STM32F722/F7xx → ESP32-S3 - stm32Mode/Version/Port → esp32Mode/Version/Port - STM32 State/Mode labels → ESP32 State/Mode - Jetson Nano → Jetson Orin Nano Super - /dev/stm32 → /dev/esp32 - stm32_bridge → esp32_bridge - STM32 HAL → ESP-IDF docs/SALTYLAB.md: - Update "Drone FC Details" to describe ESP32-S3 BALANCE board (Waveshare ESP32-S3 Touch LCD 1.28) - Replace verbose "Self-Balancing Control" STM32 section with brief note pointing to SAUL-TEE-SYSTEM-REFERENCE.md TEAM.md: Update Embedded Firmware Engineer role to ESP32-S3 / ESP-IDF No new functionality — cleanup only. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
52 lines
2.0 KiB
C
52 lines
2.0 KiB
C
#ifndef IMU_CAL_FLASH_H
|
|
#define IMU_CAL_FLASH_H
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
|
|
/*
|
|
* IMU mount angle calibration flash storage (Issue #680).
|
|
*
|
|
* Sector 7 (128 KB at 0x08060000) layout:
|
|
* 0x0807FF00 imu_cal_flash_t (64 bytes) ← this module
|
|
* 0x0807FF40 pid_sched_flash_t (128 bytes) ← pid_flash.c
|
|
* 0x0807FFC0 pid_flash_t (64 bytes) ← pid_flash.c
|
|
*
|
|
* Calibration flow:
|
|
* 1. Mount robot at its installed angle, power on, let IMU converge (~5s).
|
|
* 2. Send 'O' via USB CDC (dev-only path).
|
|
* 3. Firmware captures current pitch + roll as mount offsets, saves to flash.
|
|
* 4. mpu6000_read() subtracts offsets from output on every subsequent read.
|
|
*
|
|
* The sector erase preserves existing PID data by reading it first.
|
|
*/
|
|
|
|
#define IMU_CAL_FLASH_ADDR 0x0807FF00UL
|
|
#define IMU_CAL_FLASH_MAGIC 0x534C5403UL /* 'SLT\x03' — version 3 */
|
|
|
|
typedef struct __attribute__((packed)) {
|
|
uint32_t magic; /* IMU_CAL_FLASH_MAGIC when valid */
|
|
float pitch_offset; /* degrees subtracted from IMU pitch output */
|
|
float roll_offset; /* degrees subtracted from IMU roll output */
|
|
uint8_t _pad[52]; /* padding to 64 bytes */
|
|
} imu_cal_flash_t; /* 64 bytes total */
|
|
|
|
/*
|
|
* imu_cal_flash_load() — read saved mount offsets from flash.
|
|
* Returns true and fills *pitch_offset / *roll_offset if magic is valid.
|
|
* Returns false if no valid calibration stored (caller keeps 0.0f defaults).
|
|
*/
|
|
bool imu_cal_flash_load(float *pitch_offset, float *roll_offset);
|
|
|
|
/*
|
|
* imu_cal_flash_save() — erase sector 7 and write all three records atomically:
|
|
* imu_cal_flash_t at 0x0807FF00
|
|
* pid_sched_flash_t at 0x0807FF40 (preserved from existing flash)
|
|
* pid_flash_t at 0x0807FFC0 (preserved from existing flash)
|
|
* Must be called while disarmed — sector erase stalls CPU ~1s.
|
|
* Returns true on success.
|
|
*/
|
|
bool imu_cal_flash_save(float pitch_offset, float roll_offset);
|
|
|
|
#endif /* IMU_CAL_FLASH_H */
|