dzid26 / StepperServoCAN

Closed loop stepper motor controller with CANbus capabilities. This Project open source hardware and code, support platformio build and upload firmware.
https://shop.retropilot.org/product/stepperservocan
18 stars 5 forks source link

Add CANbus bootloader #5

Open dzid26 opened 1 year ago

dzid26 commented 1 year ago

CANbus programming shall be enabled by magic packet/on a specific CAN message id and when motor is not off (essentially whenA4950_Enabled == false)

Implementations: https://github.com/feaser/openblt - has built in XCP, supports CAN dongles on the host, uses ST HAL https://github.com/Arksine/CanBoot https://github.com/UberLambda/CANnuccia https://github.com/madprogrammer/stm32-can-bootloader https://stackoverflow.com/questions/61243660/stm32103-custom-bootloader-jump-to-main-firmware-issue

Todo:

OxygenLiu commented 1 year ago

Is 64k flash too limited for an UDS bootloader over CAN? For example https://github.com/LittleBasdart/UdsBootloader

dzid26 commented 1 year ago

@OxygenLiu I think it could work. It's hard to see though how much memory it uses. I see that it expects adjustable 4k payloads, so that's RAM.

First issue is the drivers are made for Stm32L4 registers.

Second it would need to be well integrated, for example SysTick needs to be either not used by delay.c or it should share this resource nicely. This is valid for any resource that is shared and becomes a little more complicated when a bootloader does more things than just loading the new program.

OxygenLiu commented 1 year ago

:+1: Hopefully it will support OTA upgrade using A/B partitions.

The current firmware is about 29k bytes, seems a bit bulky. Assuming the bootloader takes 20k, the remaining 44k shall accomendate 20k A and 20K B partitions.

dzid26 commented 1 year ago

I looked into the size stuff using this useful tool.

image

Platformio also has something similar.

Here is a report from mbed-os-linker-report

image

Remarks:

I guess the solution to save ROM, if necessary, will be using -Os -flto and removing unnecessary code.

Edit: Extra 1kB can be saved by storing both parameters and CalData in the same Page (separated by some offset) since I made it much smaller than it used to be.

OxygenLiu commented 1 year ago

There is certainly some unnecessary code in .text , such as BSP/display.c, which is about 2.89%.

OxygenLiu commented 2 months ago

Two interesting implementations of CAN bootloader for STM32F103,