Bug 1 (PRIMARY — DCache/USB coherency): SCB_DisableDCache() was buried inside icm42688_init(), called ~3.5s after USB starts. STM32F7 DCache/USB coherency issue: when DCache is on (enabled by SystemInit()), CPU writes to TX buffers stay in cache and the USB hardware reads stale SRAM data. Moved SCB_DisableDCache() to main() before HAL_Init(), ensuring coherency for all USB transfers. Bug 2 (USB TX corruption): CDC_Transmit() passed the caller's stack-allocated buf pointer directly to the USB stack. The USB TXFE interrupt fires asynchronously; by then the stack buffer may have been modified by the next loop iteration. CDC_Transmit() now copies into the static UserTxBuffer before handing off to the USB hardware, ensuring the buffer is stable for the transfer. Bug 3 (IMU type mismatch → wrong data to balance): main.c called icm42688_init()/icm42688_read() directly, passing icm42688_data_t* (raw int16 ax/ay/az/gx/gy/gz) to balance_update() which expects IMUData* (float pitch/pitch_rate from complementary filter). Type mismatch produced garbage balance values. Fixed by using mpu6000_init()/mpu6000_read() which wraps icm42688 + sensor fusion. Telemetry updated to report fused pitch/rate instead of raw ADC counts. Also fix icm42688_init() returning 0 on who==0 (no SPI response), which falsely indicated IMU success. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Description
SaltyLab self-balancing bot firmware (STM32F722)
Languages
Python
67.1%
C
11.4%
JavaScript
9.2%
OpenSCAD
7.8%
HTML
1.5%
Other
2.9%