202 Commits

Author SHA1 Message Date
Kevin O'Connor
6db366dc3f flash: Report pages written from "eof" command
Commit 4d969764 changed the "eof" command to return the number of
blocks instead of the number of pages written.  Report the number of
pages written again.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-16 20:37:54 -04:00
Kevin O'Connor
4d969764f1 flash: Write each block individually
Don't gather "blocks" into flash pages.  Instead, write each "block"
to flash on each flash_write_block() request.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-16 19:21:51 -04:00
Kevin O'Connor
7287670002 flash: Move page handling from flashcmd.c to flash.c
Allow the low-level board code to handle each flash page.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-16 19:21:51 -04:00
Kevin O'Connor
9f9a872176 stm32: Avoid read-modify-write operations in flash.c
Avoid read-modify-write operations on the FLASH->CR register.  Write
out the desired valid explicitly.

Use writew() and writel() to write the flash bytes out to avoid gcc
reordering the memory write relative to the flash register writes.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-16 19:21:51 -04:00
Kevin O'Connor
8316d2f0af armcm_boot: Introduce application_check_valid()
Move application_check_valid() in bootentry.c to armcm_boot.c and make
the check specific to the ARM cortex-m.  On these ARM machines it is
easier to validate the application stack address.

Also rename jump_to_application() to application_jump().

Also rename flash_read_block() to application_read_flash() and move to
armcm_boot.c .

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-16 19:21:51 -04:00
Kevin O'Connor
e8374ce367 initial_pins: Add compile time check to reduce binary size when not in use
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-16 17:01:52 -04:00
Kevin O'Connor
d6c874b0ad stm32: Support 4KiB application start
Allow the application start address to be configurable from "make
menuconfig".

Add a build check to verify the final binary can fit within the
configured size.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-16 14:08:54 -04:00
Kevin O'Connor
603ed1b6a9 Makefile: Change default to Python3
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-16 13:59:42 -04:00
Kevin O'Connor
24d4eb16c9 initial_pins: Port initial_pins capability from Klipper
Some boards require an initial gpio state in order to start USB.  Port
the initial_pins capability from Klipper to provide that support.

This also synchronizes scripts/buildcommands.py with the latest code
from Klipper.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-16 13:59:42 -04:00
Eric Callahan
1ae63dfbd8 stm32f4: include sched.h
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-05-16 09:04:45 -04:00
Eric Callahan
d36b696ce2 stm32: enable STM32F4 devices in KConfig
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-05-16 09:04:45 -04:00
Eric Callahan
c3c794076a stm32: add usbotg.c from klipper
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-05-16 09:04:45 -04:00
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