Skip to content

Conversation

emanuelen5
Copy link
Owner

@emanuelen5 emanuelen5 commented Oct 21, 2024

How to use it:

Flash the bootloader

# Upload the bootloader and set the required fuses
pio run -e bootloader -t upload

Use the bootloader

# Figure out what ports are available
python programmer/programmer.py --list-ports
# Program the millis_firmware.hex file to a device connected to serial port "COM4"
python programmer/programmer.py --port COM4 --hexfile millis_firmware.hex -v

TODO

  • Receive data over UART
  • Checksum data before write
  • ACK/NACK transfers based on message CRC
  • Connect and verify correct chip is connected
  • Configure PlatformIO
  • Configure FUSEs

@emanuelen5 emanuelen5 self-assigned this Oct 21, 2024
@emanuelen5 emanuelen5 force-pushed the emaus/bootloader branch 2 times, most recently from d63e845 to f1cba30 Compare October 23, 2024 20:07
@emanuelen5 emanuelen5 changed the title WIP: Start writing a bootloader Add a UART bootloader Oct 24, 2024
emanuelen5 and others added 15 commits June 7, 2025 15:26
* Add simavr simulator

* Remove some redundant headers

* Move avr object into main

* Remove vcd

* Use fuse values for bootloader

* Extract predicate

* Use getopts to parse arguments

Break out argument parsing into a function

* Ignore flash image run output

* Add debug configuration for running with vscode

* Rename the simulator

* Create Github action for building

* Move UART usages closer to each other

* Break out function for filling flash with main program

* Break out function for adding flash dump hook

* Exit simulator when bootloader finishes

* Draw the status LEDs using OpenGL

* Fix: Make simulator dump flash at finish

* Only draw the pins connected to LEDs

* Use a single interrupt for the whole PORT C

* Break out GLUT init function

* WIP: Implement state machine for receiving programmer data

* Break out graphics functions into their own file

* Remove unhelpful comments

* Add more debug info

* WIP: Update vector table before bootloader

* Use own fork of simavr that has interrupt table patch

* Deinit millis interrupts to make sure we don't get bootloader interrupt when moving to the application

* Convert to assembly function

This makes sure they work regardless of optimization level in the compiler

* Bump simavr
This improves the speed of the protocol significantly since we don't
have to wait until the read command times out.

Benchmark before:
- time between packets: 400-450 ms
- total time to flash millis: 3.1 s

Benchmark after:
- time between packets: 20-30 ms (~17x speedup)
- total time to flash millis: 630 ms (~5x speedup)
@emanuelen5
Copy link
Owner Author

emanuelen5 commented Jun 14, 2025

I improved the bootloader efficiency quite a bit in 6cfe3d9

This improves the speed of the protocol significantly since we don't
have to wait until the read command times out.

Before

Benchmark before:

  • time between packets: 400-450 ms
  • total time to flash millis: 3.1 s

image

After

Benchmark after:

  • time between packets: 20-30 ms (~17x speedup)
  • total time to flash millis: 630 ms (~5x speedup)

image

@emanuelen5 emanuelen5 marked this pull request as ready for review June 14, 2025 10:13
@emanuelen5 emanuelen5 requested a review from nperozzi June 14, 2025 20:41
@emanuelen5
Copy link
Owner Author

I managed to shave off some more time by making some things a bit faster and then increasing the baud rate to 62500. Now it takes 210 ms to flash the millis program (14x total speedup compared to the original baseline).

image

@nperozzi nperozzi merged commit f926028 into main Jun 17, 2025
4 checks passed
@nperozzi nperozzi deleted the emaus/bootloader branch June 17, 2025 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants