Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CANbus bootloader #5

Open
3 tasks
dzid26 opened this issue Aug 10, 2022 · 6 comments
Open
3 tasks

Add CANbus bootloader #5

dzid26 opened this issue Aug 10, 2022 · 6 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@dzid26
Copy link
Owner

dzid26 commented Aug 10, 2022

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:

  • more ROM needed. Currently, Params 1k, Calibration 1k and Fast calibration 32k takes up most of 64k memory and most of the remaining is Program
  • Create folder containing bootloader outside of /firmware.
  • Create platformio build script (platformio run) for the firmware and CAN uploading using panda
@OxygenLiu
Copy link

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

@dzid26
Copy link
Owner Author

dzid26 commented May 22, 2023

@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
Copy link

OxygenLiu commented May 26, 2023

👍 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 dzid26 added enhancement New feature or request help wanted Extra attention is needed labels May 26, 2023
@dzid26
Copy link
Owner Author

dzid26 commented May 26, 2023

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:

  • most of the size comes from .text section - which is code - not sure if the size is adequate for the amount of the code..
  • For easier analysis in amap I temporarily removed -g option that was adding .debuginfo sections. (This section doesn't go to the firmware, just ELF and is useful with tools like StmStufio or Stmmonitor).
  • adding (again) to -Os -flto reduces size to 24kb, but LTO for some reason removes debug symbols, which is fine
  • board_build.ldscript = ./src/APP/STM32F103C8_DEFAULT.ld in platformio.ini uses STM linker file. Otherwise platformio compiles using gcc's internal linker. It can be verified by building with -Wl,--verbose option. Weirdly, using an internal linker uses 24kb or 25kb with LTO.

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
Copy link

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

@OxygenLiu
Copy link

Two interesting implementations of CAN bootloader for STM32F103,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants