90 Commits

Author SHA1 Message Date
Eric Callahan
fbf59301b3 stm32: add support for stm32f4 flash operations
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-05-16 09:04:45 -04:00
Kevin O'Connor
fc96f0c9bd flash_can: Report errors by default
Change the default log level from CRITICAL to ERROR.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-16 06:19:08 -04:00
Kevin O'Connor
92e9174cae flash_can: Fix pyserial exception handling
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-16 06:19:08 -04:00
Kevin O'Connor
468b756f8d stm32: Avoid alignment issues in flash_read_block()
Use a regular memcpy() call to avoid issues with pointer alignment.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-16 06:19:08 -04:00
Kevin O'Connor
566e9ccf3a flashcmd: Force word alignment of page_buffer
The stm32 flash code requires a page_buffer alignment.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-16 06:19:08 -04:00
Eric Callahan
6c82de6e47
armcm_boot: improve the boot code methods
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-05-15 12:26:02 -04:00
Eric Callahan
c510d532f4
usbfs: remove unused armcm_timer reference
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-05-15 12:12:32 -04:00
Eric Callahan
ad6793dbd4
armcm_boot: add volatile label to bootup_code
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-05-15 10:51:12 -04:00
Kevin O'Connor
721a036b9d sched: Call timer_setup() from sched_main()
Create a board specific timer_setup() function and call it at the
start of sched_main().

Move udelay() from board code to sched.c.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-15 05:51:46 -04:00
Eric Callahan
97dfa9a1d1
readme: update canboot documentation
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-05-13 07:45:53 -04:00
Kevin O'Connor
2821c1c807 flash_can: Add support for flashing over serial
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-13 06:16:08 -04:00
Kevin O'Connor
ad566230c9 stm32: Add support for flashing over USB and serial
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-13 06:16:08 -04:00
Kevin O'Connor
799fe5313b command: Rework command encoding and processing to be more similar to Klipper
Introduce the Klipper command_encode() and command_dispatch() style
functions.  This makes it easier to import additional Klipper
low-level message handling code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-13 06:16:08 -04:00
Kevin O'Connor
4a798a2e3b bootentry: Breakup canboot_main.c to flashcmd.c, bootentry.c, and sched.c
Move command handlers from canboot_main.c to flashcmd.c.  Move startup
code to sched.c.  Rename remaining bootloader entry code to new
bootentry.c file.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-13 06:16:08 -04:00
Kevin O'Connor
09a500cf90 canboot_main: Rework "complete" handling
Convert the "complete" command to use a regular task instead of custom
code in enter_bootloader().

Perform the reboot based on a timer so that it is not necessary to
query the low-level code for ack transmission status.

Use jump_to_application() instead of canbus_reboot() to start the user
code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-13 06:16:08 -04:00
Kevin O'Connor
21469fea3e flashcmd: Move flash command handlers to new flashcmd.c file
Move the flashing command processing code from canboot_main.c to a new
flashcmd.c file.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-13 06:16:08 -04:00
Kevin O'Connor
b0291b3cdb led: Convert code to use a task
There is no need for a custom check_blink_time() function as this can
be done from a new led_blink_task().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-13 06:16:08 -04:00
Kevin O'Connor
38ef4860da command: Move command processing to new command.c file
Move the low-level command parsing and encoding code from
canboot_main.c to a new command.c file.

Standardize the parameters and naming for command handlers.  Rename
send_ack() to console_send_ack() and rework parameters to be similar
to command handlers.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-13 06:16:08 -04:00
Kevin O'Connor
83ecbcc01d command: Add command.h file to make importing Klipper code easier
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-13 06:16:08 -04:00
Kevin O'Connor
db6a9b4d96 sched: Add sched.c and sched.h files to make importing Klipper code easier
Add the sched.c code and associated DECL_INIT(), DECL_TASK() macros so
that it is easier to import low-level Klipper code into the CanBoot
repo.

These additional code wrappers do not increase the overall binary size
as gcc does a good job of inlining the wrappers and removing unused
code during the compile process.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-13 06:16:08 -04:00
Kevin O'Connor
ae687a404d canbus: Add support for verifying the canbus uuid
There is a severe corner case where two mcus could potentially be
assigned the same canbus_id and thus flash commands could go to the
wrong mcu.  Add a get_canbus_id command to attempt to prevent this.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-09 17:12:24 -04:00
Kevin O'Connor
f0a2339822 canboot_main: Make sure to not overwrite the bootloader itself
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-09 17:12:24 -04:00
Kevin O'Connor
a00c4c78c5 canboot_main: Add mcu type to connect response message
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-09 17:12:24 -04:00
Kevin O'Connor
466a9de594 canboot_main: Introduce a command_error response
A nack indicates a transmission error while a command_error indicates
a nonrecoverable error.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-09 17:12:24 -04:00
Kevin O'Connor
702bd5f949 protocol: Fix minor spelling error
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-09 17:12:24 -04:00
Kevin O'Connor
62971c1807 canboot_main: Minor fixes
Wrap defines with expressions in parenthesis.

MAX_OBUF_SIZE is in bytes - divide by 4 for number of words.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-09 17:12:24 -04:00
Eric Callahan
7db2911aed protocol: update for latest changes
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-05-09 17:12:24 -04:00
Eric Callahan
5e7d632c4f flash_can: protocol updates
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-05-09 17:12:24 -04:00
Eric Callahan
beb06d600d canboot_main: use direct addressing
Rather than use indicies, use the desired address when requesting
a block write or read.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-05-09 17:12:24 -04:00
Eric Callahan
047003bf12 canboot_main: switch to little-endian
Simplify the NACK to a single command.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-05-09 17:12:24 -04:00
Eric Callahan
6199e9d107 canboot_main: remove process_state() method
Commands are now executed after decoding, so there is no need to
track any state other than complete.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-05-09 17:12:24 -04:00
Eric Callahan
9762327ac3 protocol: add protocol documentation
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-05-09 17:12:24 -04:00
Eric Callahan
c9d326928c flash_can: update to support new protocol
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-05-09 17:12:24 -04:00
Eric Callahan
54dce642f6 canboot_main: rework the protocol
All commands are now framed, where the payload  must
always be included within a frame.  A 16-bit CRC is postfixed
to each frame for validation.  The protocol is now as follows:

 <16-bit header><8-bit command><8-bit payload length in words><payload><16-bit trailer><16-bit CRC>

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-05-09 17:12:24 -04:00
Eric Callahan
011d3a8f45 generic: add crc16 from klipper
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-05-09 17:12:24 -04:00
Eric Callahan
849b81dce5 led: introduce a short delay before reading initial time
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-05-09 17:12:24 -04:00
Kevin O'Connor
a84b354cee canboot_main: Change double reset time from 2 seconds to 500ms
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-05 15:18:07 -04:00
Kevin O'Connor
66c9853929 canboot_main: Add support for entering the bootloader on a button press
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-05 15:18:07 -04:00
Kevin O'Connor
ce580fa8c6 canboot_main: Make entry via double reset a config option
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-05 15:18:07 -04:00
Kevin O'Connor
807c1ef0bd led: Move led code to new led.c file
Move the led c code from the buildcommands.py to a new led.c file.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-05 15:18:07 -04:00
Kevin O'Connor
5279c33ea0 flash: Autodetect stm32f103 flash page size
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-05 14:06:43 -04:00
Kevin O'Connor
00a65c1570 Makefile: Resync main makefile with Klipper's main makefile
The latest Klipper main Makefile has bugfixes for proper rebuilding on
a change during "make menuconfig".

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-05 12:28:44 -04:00
Kevin O'Connor
9c6e72e3a5 armcm_boot: Introduce cross-platform boot to application code
It's a good idea to reset the cpu before starting the main application
code.  However it is difficult to reliably reset the cpu in software.

This changes the software to actually do a cpu hardware reset prior to
launching the main application - after each bootup the code checks to
see if the application should be started before entering the main
bootloader code.  This helps ensure the application code is started in
a "pristine" cpu state.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-05 05:32:21 -04:00
Kevin O'Connor
726e6e62fa armcm_boot: No need to reset cpu state on bootup
The bootloader is only called after a reset - it doesn't need to worry
about another bootloader launching it.  This reduces the code size by
a small amount.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-05 05:32:21 -04:00
Kevin O'Connor
23f3c0e1e2 armcm_boot: Add get/set_bootup_code() helper functions
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-05 05:32:21 -04:00
Kevin O'Connor
34e14386ed Makefile: Build with -Os instead of -O2
Build size is likely more important than CPU performance for a
bootloader.  So, instruct gcc to optimize for size by default.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-05 05:23:45 -04:00
Kevin O'Connor
da0f92f721 README: Use Klipper3d github http address
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-05 05:23:15 -04:00
Kevin O'Connor
794ccd69c0 canbus: Use Klipper's nodeid to canbus_id scheme
Use Klipper's nodeid to canbus_id scheme (canbus_id = nodeid * 2 +
0x100).  Instead, use a nodeid offset of 128 to avoid collisions with
Klipper.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-05 05:22:55 -04:00
Eric Callahan
95e8a707ca
flash_can: attempt to reset the mcu if an error is encountered
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-04-26 12:12:46 -04:00
Eric Callahan
c5163674ed
src: remove references to the magic key
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-04-26 08:26:45 -04:00