40 Commits

Author SHA1 Message Date
Eric Callahan
8d8ac60256 stm32: remove stm32f4 CAN warning
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-07-01 14:34:30 -04:00
Eric Callahan
8b010a64a1 build: sync Kconfig and Makefile changes with Klipper
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-07-01 14:34:30 -04:00
Eric Callahan
d6a605d6b7 src: add updated can source from Klipper
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-07-01 14:34:30 -04:00
Eric Callahan
8702008265
stm32: use TME bits to determine the can tx mailbox
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-06-02 20:05:56 -04:00
Kevin O'Connor
115582ce88 stm32: Add stm32g0 support
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-17 19:29:58 -04:00
Kevin O'Connor
4857a70189 stm32: Improve out-of-bounds check on erase sector index calculation
Avoid wrapping the sector index, as that could potentially result in
erasing the booloader itself.

Also, move the stm32f4_sector_index() inline into erase_page().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-17 19:29:58 -04:00
Kevin O'Connor
1e6a2de3b1 stm32: Enable support on other stm32f0 chips
The remaining stm32f0 chips have flash hardware similar to stm32f1.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-17 19:29:58 -04:00
Kevin O'Connor
5cbc25d676 stm32: Enable support for stm32f2 - it has same flash interface as stm32f4
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-17 19:29:58 -04:00
Kevin O'Connor
d2ea272de0 stm32: Resync stm32f4 with upstream Klipper
There was a Klipper bugfix for STM32F401 clock init.

There was a Klipper build bugfix when building with gcc hardfloat flags.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-17 12:00:31 -04:00
Kevin O'Connor
3d924f52ec stm32: Support 16KiB application start on stm32f4
The default remains 32KiB, but a smaller size bootloader may be useful
for testing.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-16 20:38:56 -04:00
Kevin O'Connor
9820445b92 stm32: Default to 8KiB application start on stm32f0 and stm32f1
Using 8KiB is a better default for most users.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-05-16 20:38:56 -04:00
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
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
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
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
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
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
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
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
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
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
011d3a8f45 generic: add crc16 from klipper
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-05-09 17:12:24 -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
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
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
Eric Callahan
b5ff2ce29b
kconfig: fix page size description
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-04-14 17:22:51 -04:00
Eric Callahan
0f1bd588a8
kconfig: fix stm32f072 flash size
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-04-14 09:15:32 -04:00
Eric Callahan
3a29a4d0da
kconfig: disable stm32f4 choices
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-04-14 08:55:09 -04:00
Eric Callahan
26b12a658b
src: update stm32 source
Bring in the latest changes from Klipper.  The STM32F4 variants are
still unsupported at this time.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2022-04-11 19:59:56 -04:00
Arksine
4cd17a6f5e stm32f0: intiial attempt at canboot support
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2021-02-07 14:29:00 -05:00
Arksine
2762299895 canboot: initial source commit
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2021-02-06 20:04:47 -05:00