From 41105cd29fa0193903a4ba5c04a7f97317180026 Mon Sep 17 00:00:00 2001 From: rusefillc <48498823+rusefillc@users.noreply.github.com> Date: Mon, 27 Dec 2021 23:39:02 -0500 Subject: [PATCH] extracting hardware-specifc CAN from BL (#32) * extracting hardware-specifc CAN from BL reusing CAN settings between FW and BL moving CRC into better location * spelling M0 stuff as M0 stuff Co-authored-by: rusefillc --- firmware/boards/f0_module/bootloader/Makefile | 8 ++++++-- .../boards/f0_module/bootloader/bootloader.cpp | 18 +++++++----------- firmware/boards/f0_module/port.cpp | 6 ------ firmware/boards/f0_module/port_shared.cpp | 9 +++++++++ firmware/boards/port.h | 2 +- firmware/boards/port_shared.h | 4 ++++ .../f0_module/bootloader => shared}/crc.cpp | 0 7 files changed, 27 insertions(+), 20 deletions(-) create mode 100644 firmware/boards/f0_module/port_shared.cpp create mode 100644 firmware/boards/port_shared.h rename firmware/{boards/f0_module/bootloader => shared}/crc.cpp (100%) diff --git a/firmware/boards/f0_module/bootloader/Makefile b/firmware/boards/f0_module/bootloader/Makefile index 7c2ec31..0996f78 100644 --- a/firmware/boards/f0_module/bootloader/Makefile +++ b/firmware/boards/f0_module/bootloader/Makefile @@ -119,7 +119,11 @@ CSRC = $(ALLCSRC) cfg/board.c # C++ sources that can be compiled in ARM or THUMB mode depending on the global # setting. -CPPSRC = $(ALLCPPSRC) bootloader.cpp $(SRCDIR)/shared/flash.cpp crc.cpp +CPPSRC = $(ALLCPPSRC) \ + bootloader.cpp \ + ../port_shared.cpp \ + $(SRCDIR)/shared/flash.cpp \ + $(SRCDIR)/shared/crc.cpp # List ASM source files here. ASMSRC = $(ALLASMSRC) @@ -129,7 +133,7 @@ ASMXSRC = $(ALLXASMSRC) # Inclusion directories. INCDIR = $(CONFDIR) $(ALLINC) $(SRCDIR)/shared/ \ - ../io + ../io ../.. # Define C warning options here. CWARN = -Wall -Wextra -Wundef -Wstrict-prototypes diff --git a/firmware/boards/f0_module/bootloader/bootloader.cpp b/firmware/boards/f0_module/bootloader/bootloader.cpp index 6ce5993..f274105 100644 --- a/firmware/boards/f0_module/bootloader/bootloader.cpp +++ b/firmware/boards/f0_module/bootloader/bootloader.cpp @@ -1,6 +1,5 @@ -#include "ch.h" -#include "hal.h" +#include "port_shared.h" #include "flash.h" #include "io_pins.h" @@ -37,15 +36,18 @@ void boot_app() { const uint32_t* appFlash = __appflash_start__; + // The reset vector is at offset 4 (second uint32) + uint32_t reset_vector = appFlash[1]; + +#ifdef STM32F0XX // copy vector table to sram // TODO: use __ram_vectors_size__ memcpy(reinterpret_cast(&__ram_vectors_start__), appFlash, 256); - // The reset vector is at offset 4 (second uint32) - uint32_t reset_vector = appFlash[1]; - + // M0 core version, newer cores do same thing a bit nicer // switch to use vectors in ram SYSCFG->CFGR1 |= 3; +#endif // TODO: is this necessary? //uint32_t app_msp = appLocation[0]; @@ -214,12 +216,6 @@ void RunBootloaderLoop() } } -static const CANConfig canConfig500 = -{ - CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP, - CAN_BTR_SJW(0) | CAN_BTR_BRP(5) | CAN_BTR_TS1(12) | CAN_BTR_TS2(1), -}; - THD_WORKING_AREA(waBootloaderThread, 512); THD_FUNCTION(BootloaderThread, arg) { diff --git a/firmware/boards/f0_module/port.cpp b/firmware/boards/f0_module/port.cpp index 63c5bf6..61097a5 100644 --- a/firmware/boards/f0_module/port.cpp +++ b/firmware/boards/f0_module/port.cpp @@ -129,9 +129,3 @@ void SetConfiguration(const Configuration& newConfig) sizeof(Configuration) ); } - -const CANConfig canConfig500 = -{ - CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP, - CAN_BTR_SJW(0) | CAN_BTR_BRP(5) | CAN_BTR_TS1(12) | CAN_BTR_TS2(1), -}; diff --git a/firmware/boards/f0_module/port_shared.cpp b/firmware/boards/f0_module/port_shared.cpp new file mode 100644 index 0000000..6642113 --- /dev/null +++ b/firmware/boards/f0_module/port_shared.cpp @@ -0,0 +1,9 @@ +#include "port_shared.h" + +// board-specific stuff shared between bootloader and firmware + +const CANConfig canConfig500 = +{ + CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP, + CAN_BTR_SJW(0) | CAN_BTR_BRP(5) | CAN_BTR_TS1(12) | CAN_BTR_TS2(1), +}; diff --git a/firmware/boards/port.h b/firmware/boards/port.h index e9b4b78..064c022 100644 --- a/firmware/boards/port.h +++ b/firmware/boards/port.h @@ -1,6 +1,7 @@ #pragma once #include "hal.h" +#include "port_shared.h" struct AnalogResult { @@ -33,4 +34,3 @@ public: Configuration GetConfiguration(); void SetConfiguration(const Configuration& newConfig); -extern const CANConfig canConfig500; diff --git a/firmware/boards/port_shared.h b/firmware/boards/port_shared.h new file mode 100644 index 0000000..e04aa74 --- /dev/null +++ b/firmware/boards/port_shared.h @@ -0,0 +1,4 @@ +#include "ch.h" +#include "hal.h" + +extern const CANConfig canConfig500; \ No newline at end of file diff --git a/firmware/boards/f0_module/bootloader/crc.cpp b/firmware/shared/crc.cpp similarity index 100% rename from firmware/boards/f0_module/bootloader/crc.cpp rename to firmware/shared/crc.cpp