# Developing with the SANPO Firmware This option retains the existing USB/SPI-to-CAN/RS485 functions while allowing you to add I2C, ADC, UART, and other sensor peripherals. If you need to reimplement CAN, RS485, or the complete communication path, use [Developing Custom Firmware](custom_firmware_development). ## Choose a Development Tool The same V47 development framework is available for two toolchains: | Tool | Project | | --- | --- | | STM32CubeIDE | [stm32f407V4_with_socketcan](https://gitcode.com/sanpo/robot/tree/main/products/spine/v4/f407/sdk/stm32f407V4_with_socketcan) | | Keil 5 | [stm32f407V4_with_socketcan_keil](https://gitcode.com/sanpo/robot/tree/main/products/spine/v4/f407/sdk/stm32f407V4_with_socketcan_keil) | Both projects retain the same V47 communication functions and expose the same customer extension entry points. Choose one toolchain. Do not mix static libraries or project settings between the two versions. ## Functions You Can Add | Function | Pins and peripheral | Typical uses | | --- | --- | --- | | Expansion UART | USART3, PD8/TX and PD9/RX | Remote controls, radio modules, external controllers, and custom commands | | I2C | I2C2, PB10/SCL and PB11/SDA | Attitude, temperature, pressure, and other sensors | | Analog inputs | PB0/ADC1 IN8 and PB1/ADC2 IN9 | Voltage, pressure, and other analog signals | | Background processing | Customer task entry point | Status checks, data processing, and simple control logic | USB, SocketCAN, external SPI, CAN, and RS485 are already integrated and normally do not need to be changed. ## Customer Code Location Customer functions are located in: ```text CustomerApp/ ``` Common files: - `CustomerApp/Src/customer_protocol.c`: add custom UART commands and protocol parsing. - `CustomerApp/Src/customer_app.c`: connect UART3, I2C, ADC, and background processing. - `CustomerApp/Inc/`: add customer-facing interfaces. The default example replies to `PING`, `PING\r\n`, or `PING\n` received on USART3 with: ```text PONG\r\n ``` USART3 defaults to `115200-8-N-1`. Verify PING/PONG before adding your device. ## STM32CubeIDE 1. Install STM32CubeIDE. 2. Select `File > Import > Existing Projects into Workspace`. 3. Import `stm32f407V4_with_socketcan`. 4. Select the `Release` configuration, then run Clean and Build. 5. Program and verify with ST-LINK, then restart the board. The SANPO communication library is: ```text Libs/libloop_function_v4.a ``` ## Keil 5 The Keil project requires: - Keil MDK 5.43 or later; - Arm Compiler 6.24; - `Keil::STM32F4xx_DFP` 3.1.1; - ST-LINK. Open: ```text stm32f407V4_with_socketcan_keil/MDK-ARM/spine_v4_v47_keil.uvprojx ``` Select `V47 Release` and press `F7`. A normal build reports `0 Error(s), 0 Warning(s)`. The Keil communication library is: ```text Libs/libloop_function_v4_keil.lib ``` Do not switch this project to Arm Compiler 5, and do not use the GCC library from the STM32CubeIDE project. ## Programming and Saved Data The two STM32 devices use the same development project and pin configuration. If both sides need the same function, program the same build through the two SWD connectors. Use program and verify. Do not perform a full-chip erase. Keep the application within `0x08000000` to `0x0801FFFF` so it does not overwrite the Flash area used for communication settings and offline tasks. See [Firmware Update](firmware_update). ## Do Not Regenerate Code from an IOC These release projects are not blank CubeMX templates: - The release packages do not include `.ioc` or `.mxproject` files. - Do not run `Generate Code`. - Do not replace USB, SPI, CAN, RS485, FreeRTOS, or the static library. - Do not reassign pins used by the SANPO communication functions. If you need unrestricted IOC and communication-interface changes, start from a project in [Developing Custom Firmware](custom_firmware_development). ## Acceptance Checks After a Change At minimum, verify: 1. The project builds without errors or warnings. 2. `AT+VER\r\n` over USB returns `V47\r\n`. 3. `PING\r\n` over USART3 returns `PONG\r\n`. 4. The SANPO USB protocol and SocketCAN work. 5. The SPI protocol works. 6. Both CAN and both RS485 channels can transmit and receive. 7. Added UART, I2C, ADC, or sensor functions work. 8. Saved communication settings remain after a power cycle.