From cab2401bca4fe0d22a7a98a1c226ada5148dec5c Mon Sep 17 00:00:00 2001 From: Vaaranan Yogalingam Date: Wed, 25 Aug 2021 21:28:43 +0000 Subject: [PATCH 01/23] Replaced old NTC curve with new experimental curve --- projects/solar/src/sense_temperature.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/projects/solar/src/sense_temperature.c b/projects/solar/src/sense_temperature.c index b70fbf657..348941b8f 100644 --- a/projects/solar/src/sense_temperature.c +++ b/projects/solar/src/sense_temperature.c @@ -34,10 +34,16 @@ static void prv_sense_callback(void *context) { case NTC_THERMISTOR: // NTC: T = 1 / ( ( ln(0.56 * V / (3.3 - V)) / 3428 ) + 1/298.15 ) in KELVIN. For Celsius, // subtract 273.15 - converted_reading = - (1 / - ((ln(0.56 * converted_reading / (3.3 - converted_reading)) / 3428.0) + 1.0 / 298.15)) - - 273.15; + // NEW NTC CURVE (BASED ON EXPERIMENTAL DATA): T = (-14.195)*V^3 + (37.9434)*V^2 - 64.8244V + + // 121.362 (already in celsius) + // converted_reading = + // (1 / + // ((ln(0.56 * converted_reading / (3.3 - converted_reading)) / 3428.0) + 1.0 / 298.15)) + // - + // 273.15; + converted_reading = (-14.195) * pow(converted_reading, 3) + + (37.9434) * pow(converted_reading, 2) - 64.8244 * converted_reading + + 121.362; // Convert from Celsius to deciCelsius converted_reading = converted_reading * 10; From f1ce7d0e01211428803f3e6320801245a2da254b Mon Sep 17 00:00:00 2001 From: Vaaranan Yogalingam Date: Wed, 25 Aug 2021 22:23:53 +0000 Subject: [PATCH 02/23] modified appropriate test(s) --- projects/solar/test/test_sense_temperature.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/projects/solar/test/test_sense_temperature.c b/projects/solar/test/test_sense_temperature.c index 3c4f463fe..60c987056 100644 --- a/projects/solar/test/test_sense_temperature.c +++ b/projects/solar/test/test_sense_temperature.c @@ -1,5 +1,3 @@ -#include "sense_temperature.h" - #include #include "adc.h" @@ -7,6 +5,7 @@ #include "gpio.h" #include "log.h" #include "sense.h" +#include "sense_temperature.h" #include "test_helpers.h" #include "unity.h" @@ -15,7 +14,7 @@ // The two test variables below are calculated from inputting 0x800 into the relative conversion // formulae (see sense_temperature.c) #define TEST_RTD_CONVERTED_READING (-541) -#define TEST_NTC_CONVERTED_READING (272) +#define TEST_NTC_CONVERTED_READING (258) static SenseCallback s_sense_callbacks[MAX_THERMISTORS]; static void *s_sense_callback_contexts[MAX_THERMISTORS]; From 6d4839702ae11cca48df4d5b93935cd44c180ab5 Mon Sep 17 00:00:00 2001 From: Vaaranan Yogalingam Date: Sat, 2 Oct 2021 15:13:14 +0000 Subject: [PATCH 03/23] implemented jump to bootloader, follow comments --- projects/bootloader/inc/jump_to_bootloader.h | 4 ++ .../bootloader/inc/stm32f0xx/bootloader_mcu.h | 4 ++ projects/bootloader/src/main.c | 3 ++ .../src/stm32f0xx/jump_to_bootloader.c | 40 +++++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 projects/bootloader/inc/jump_to_bootloader.h create mode 100644 projects/bootloader/src/stm32f0xx/jump_to_bootloader.c diff --git a/projects/bootloader/inc/jump_to_bootloader.h b/projects/bootloader/inc/jump_to_bootloader.h new file mode 100644 index 000000000..91938239a --- /dev/null +++ b/projects/bootloader/inc/jump_to_bootloader.h @@ -0,0 +1,4 @@ +#pragma once + +// Jump to the bootloade at the beginning of flash memory +void jump_to_bootloader(void); diff --git a/projects/bootloader/inc/stm32f0xx/bootloader_mcu.h b/projects/bootloader/inc/stm32f0xx/bootloader_mcu.h index 9db01a743..d464aef35 100644 --- a/projects/bootloader/inc/stm32f0xx/bootloader_mcu.h +++ b/projects/bootloader/inc/stm32f0xx/bootloader_mcu.h @@ -15,6 +15,8 @@ extern uint32_t _application_size; extern uint32_t _ram_start; extern uint32_t _ram_size; extern uint32_t _vector_table_size; +extern uint32_t _bootloader_start; +extern uint32_t _bootloader_size; #define BOOTLOADER_CONFIG_PAGE_1_START ((void *)&_config_page1_start) #define BOOTLOADER_CONFIG_PAGE_2_START ((void *)&_config_page2_start) @@ -23,3 +25,5 @@ extern uint32_t _vector_table_size; #define BOOTLOADER_RAM_START ((void *)&_ram_start) #define BOOTLOADER_RAM_SIZE ((size_t)&_ram_size) #define BOOTLOADER_VECTOR_TABLE_SIZE ((size_t)&_vector_table_size) +#define BOOTLOADER_DEFAULT_LOCATION ((size_t)&_bootloader_start) +#define BOOTLOADER_SIZE ((size_t)&_bootloader_size) diff --git a/projects/bootloader/src/main.c b/projects/bootloader/src/main.c index b037408d8..d9a321e70 100644 --- a/projects/bootloader/src/main.c +++ b/projects/bootloader/src/main.c @@ -3,6 +3,7 @@ #include "flash.h" #include "interrupt.h" #include "jump_to_application.h" +#include "jump_to_bootloader.h" #include "log.h" #include "soft_timer.h" @@ -16,6 +17,8 @@ int main(void) { config_init(); jump_to_application(); + jump_to_bootloader(); + // not reached return 0; } diff --git a/projects/bootloader/src/stm32f0xx/jump_to_bootloader.c b/projects/bootloader/src/stm32f0xx/jump_to_bootloader.c new file mode 100644 index 000000000..e6689023b --- /dev/null +++ b/projects/bootloader/src/stm32f0xx/jump_to_bootloader.c @@ -0,0 +1,40 @@ +#include "jump_to_bootloader.h" + +#include +#include +#include + +#include "bootloader_mcu.h" +#include "stm32f0xx_misc.h" +#include "stm32f0xx_syscfg.h" + +static noreturn __attribute__((naked)) void prv_perform_jump(uint32_t sp, uint32_t pc) { + __asm( + "msr msp, %[sp] \n" // reset the main stack pointer (msp) to sp + "bx %[pc] \n" // jump to pc + + // this bizarre syntax associates the "sp" and "pc" in asm with the sp and pc parameters + // see http://www.ethernut.de/en/documents/arm-inline-asm.html + : + : [sp] "r"(sp), [pc] "r"(pc)); +} + +void jump_to_bootloader(void) { + // Disable all interrupts so their is no interference when working with vector tables + __disable_irq(); + + // Reset the vector table to bootloader's vector table + SYSCFG_MemoryRemapConfig( + SYSCFG_MemoryRemap_SRAM); // change where the vector table is stored to beginning of flash + + // story memory location of bootloader starting point at the beginning of flash? + uint32_t *bootloader_in_flash = BOOTLOADER_DEFAULT_LOCATION; + // setting the stack pointer to the bootloader location now + uint32_t initial_sp = bootloader_in_flash[0]; + uint32_t reset_handler_pc = bootloader_in_flash[1]; + + // re-enable interrupts + __enable_irq(); + // jump to bootloader + prv_perform_jump(initial_sp, reset_handler_pc); +} From b0a8848394b9a22b5e8f229b14ba50a8f8ecbb16 Mon Sep 17 00:00:00 2001 From: Vaaranan Yogalingam Date: Sat, 2 Oct 2021 15:29:19 +0000 Subject: [PATCH 04/23] updated main in bootloader --- projects/bootloader/src/main.c | 57 +++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/projects/bootloader/src/main.c b/projects/bootloader/src/main.c index d9a321e70..72052f394 100644 --- a/projects/bootloader/src/main.c +++ b/projects/bootloader/src/main.c @@ -1,24 +1,73 @@ +#include "bootloader_can.h" +#include "bootloader_events.h" +#include "can_datagram.h" #include "config.h" #include "crc32.h" +#include "dispatcher.h" +#include "event_queue.h" #include "flash.h" #include "interrupt.h" #include "jump_to_application.h" #include "jump_to_bootloader.h" #include "log.h" +#include "ping.h" +#include "query.h" #include "soft_timer.h" +#include "wait.h" + +static CanStorage s_can_storage; +static CanSettings s_can_settings = { + .loopback = false, + .bitrate = CAN_HW_BITRATE_500KBPS, + .rx_event = CAN_DATAGRAM_EVENT_RX, + .tx_event = CAN_DATAGRAM_EVENT_TX, + .fault_event = CAN_DATAGRAM_EVENT_FAULT, + .tx = { GPIO_PORT_A, 12 }, + .rx = { GPIO_PORT_A, 11 }, +}; + +static CanDatagramSettings s_datagram_settings = { + .tx_event = DATAGRAM_EVENT_TX, + .rx_event = DATAGRAM_EVENT_RX, + .repeat_event = DATAGRAM_EVENT_REPEAT, + .error_event = DATAGRAM_EVENT_ERROR, + .error_cb = NULL, +}; int main(void) { LOG_DEBUG("Hello from the bootloader!\n"); - // initialize all the modules + flash_init(); interrupt_init(); soft_timer_init(); crc32_init(); + event_queue_init(); config_init(); - jump_to_application(); - jump_to_bootloader(); + // gets the board id + BootloaderConfig blconfig = { + .controller_board_id = 0xFF, + }; + config_get(&blconfig); + uint8_t board_id = blconfig.controller_board_id; + + // can and datagram + bootloader_can_init(&s_can_storage, &s_can_settings, board_id); + can_datagram_init(&s_datagram_settings); + + dispatcher_init(board_id); + + ping_init(board_id); + query_init(&blconfig); + + Event e = { 0 }; + while (true) { + while (event_process(&e) == STATUS_CODE_OK) { + can_process_event(&e); + can_datagram_process_event(&e); + } + wait(); + } - // not reached return 0; } From 069f19be92e90d15feed7d62356fe43bbeca2c28 Mon Sep 17 00:00:00 2001 From: Vaaranan Yogalingam Date: Sat, 2 Oct 2021 15:43:04 +0000 Subject: [PATCH 05/23] Fixed macro typecast error --- projects/bootloader/inc/stm32f0xx/bootloader_mcu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/bootloader/inc/stm32f0xx/bootloader_mcu.h b/projects/bootloader/inc/stm32f0xx/bootloader_mcu.h index d464aef35..ec90632ed 100644 --- a/projects/bootloader/inc/stm32f0xx/bootloader_mcu.h +++ b/projects/bootloader/inc/stm32f0xx/bootloader_mcu.h @@ -25,5 +25,5 @@ extern uint32_t _bootloader_size; #define BOOTLOADER_RAM_START ((void *)&_ram_start) #define BOOTLOADER_RAM_SIZE ((size_t)&_ram_size) #define BOOTLOADER_VECTOR_TABLE_SIZE ((size_t)&_vector_table_size) -#define BOOTLOADER_DEFAULT_LOCATION ((size_t)&_bootloader_start) +#define BOOTLOADER_DEFAULT_LOCATION ((void *)&_bootloader_start) #define BOOTLOADER_SIZE ((size_t)&_bootloader_size) From d7782c6066efee4d0a1a8d83515f3926643701a3 Mon Sep 17 00:00:00 2001 From: Vaaranan Yogalingam Date: Sat, 9 Oct 2021 04:11:35 +0000 Subject: [PATCH 06/23] [SOFT-468] Fixed memory configuration to flash, not SRAM --- projects/bootloader/src/stm32f0xx/jump_to_bootloader.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/bootloader/src/stm32f0xx/jump_to_bootloader.c b/projects/bootloader/src/stm32f0xx/jump_to_bootloader.c index e6689023b..143d6aa52 100644 --- a/projects/bootloader/src/stm32f0xx/jump_to_bootloader.c +++ b/projects/bootloader/src/stm32f0xx/jump_to_bootloader.c @@ -25,7 +25,7 @@ void jump_to_bootloader(void) { // Reset the vector table to bootloader's vector table SYSCFG_MemoryRemapConfig( - SYSCFG_MemoryRemap_SRAM); // change where the vector table is stored to beginning of flash + SYSCFG_MemoryRemap_Flash); // change where the vector table is stored to beginning of flash // story memory location of bootloader starting point at the beginning of flash? uint32_t *bootloader_in_flash = BOOTLOADER_DEFAULT_LOCATION; From 4ec7d102b05e1e92121d041ffa01a5bf3386dea3 Mon Sep 17 00:00:00 2001 From: Vaaranan Yogalingam Date: Sat, 9 Oct 2021 16:47:39 +0000 Subject: [PATCH 07/23] [SOFT-468] Modularized jump function --- projects/bootloader/inc/jump.h | 7 +++++++ projects/bootloader/src/stm32f0xx/jump.c | 12 ++++++++++++ .../bootloader/src/stm32f0xx/jump_to_bootloader.c | 1 + 3 files changed, 20 insertions(+) create mode 100644 projects/bootloader/inc/jump.h create mode 100644 projects/bootloader/src/stm32f0xx/jump.c diff --git a/projects/bootloader/inc/jump.h b/projects/bootloader/inc/jump.h new file mode 100644 index 000000000..ae7be3fb3 --- /dev/null +++ b/projects/bootloader/inc/jump.h @@ -0,0 +1,7 @@ +#pragma once + +#include +#include + +// Reset main stack pointer to main stack pointer, and jump to program counter +static noreturn __attribute__((naked)) void prv_perform_jump(uint32_t sp, uint32_t pc); diff --git a/projects/bootloader/src/stm32f0xx/jump.c b/projects/bootloader/src/stm32f0xx/jump.c new file mode 100644 index 000000000..e85162384 --- /dev/null +++ b/projects/bootloader/src/stm32f0xx/jump.c @@ -0,0 +1,12 @@ +#include "jump.h" + +static noreturn __attribute__((naked)) void prv_perform_jump(uint32_t sp, uint32_t pc) { + __asm( + "msr msp, %[sp] \n" // reset the main stack pointer (msp) to sp + "bx %[pc] \n" // jump to pc + + // this bizarre syntax associates the "sp" and "pc" in asm with the sp and pc parameters + // see http://www.ethernut.de/en/documents/arm-inline-asm.html + : + : [sp] "r"(sp), [pc] "r"(pc)); +} diff --git a/projects/bootloader/src/stm32f0xx/jump_to_bootloader.c b/projects/bootloader/src/stm32f0xx/jump_to_bootloader.c index 143d6aa52..18f8c0568 100644 --- a/projects/bootloader/src/stm32f0xx/jump_to_bootloader.c +++ b/projects/bootloader/src/stm32f0xx/jump_to_bootloader.c @@ -5,6 +5,7 @@ #include #include "bootloader_mcu.h" +#include "jump.h" #include "stm32f0xx_misc.h" #include "stm32f0xx_syscfg.h" From 8b21f0d8f3524c917ee934cc410f1faf505fb055 Mon Sep 17 00:00:00 2001 From: Vaaranan Yogalingam Date: Sat, 9 Oct 2021 17:14:53 +0000 Subject: [PATCH 08/23] [SOFT-468] Added ms-bootloader library --- libraries/ms-bootloader/README.md | 16 ++++++++++++++++ libraries/ms-bootloader/rules.mk | 9 +++++++++ 2 files changed, 25 insertions(+) create mode 100644 libraries/ms-bootloader/README.md create mode 100644 libraries/ms-bootloader/rules.mk diff --git a/libraries/ms-bootloader/README.md b/libraries/ms-bootloader/README.md new file mode 100644 index 000000000..83854796d --- /dev/null +++ b/libraries/ms-bootloader/README.md @@ -0,0 +1,16 @@ + +# ms-bootloader + diff --git a/libraries/ms-bootloader/rules.mk b/libraries/ms-bootloader/rules.mk new file mode 100644 index 000000000..f4958023a --- /dev/null +++ b/libraries/ms-bootloader/rules.mk @@ -0,0 +1,9 @@ +# Defines $(T)_SRC, $(T)_INC, $(T)_DEPS, and $(T)_CFLAGS for the build makefile. +# Tests can be excluded by defining $(T)_EXCLUDE_TESTS. +# Pre-defined: +# $(T)_SRC_ROOT: $(T)_DIR/src +# $(T)_INC_DIRS: $(T)_DIR/inc{/$(PLATFORM)} +# $(T)_SRC: $(T)_DIR/src{/$(PLATFORM)}/*.{c,s} + +# Specify the libraries you want to include +$(T)_DEPS := From 068736809e69edd81ad10d3e47b84bc3ca8e7220 Mon Sep 17 00:00:00 2001 From: Vaaranan Yogalingam Date: Sun, 10 Oct 2021 16:22:53 +0000 Subject: [PATCH 09/23] [SOFT-468] Implemented preprocessorconditional upon compilation for apps on bootloader --- libraries/ms-bootloader/inc/jump.h | 7 ++++ .../ms-bootloader/inc/jump_to_bootloader.h | 4 ++ libraries/ms-bootloader/src/jump.c | 12 ++++++ .../ms-bootloader/src/jump_to_bootloader.c | 41 +++++++++++++++++++ libraries/ms-common/src/can_fsm.c | 5 +++ platform/stm32f0xx/platform.mk | 1 + 6 files changed, 70 insertions(+) create mode 100644 libraries/ms-bootloader/inc/jump.h create mode 100644 libraries/ms-bootloader/inc/jump_to_bootloader.h create mode 100644 libraries/ms-bootloader/src/jump.c create mode 100644 libraries/ms-bootloader/src/jump_to_bootloader.c diff --git a/libraries/ms-bootloader/inc/jump.h b/libraries/ms-bootloader/inc/jump.h new file mode 100644 index 000000000..ae7be3fb3 --- /dev/null +++ b/libraries/ms-bootloader/inc/jump.h @@ -0,0 +1,7 @@ +#pragma once + +#include +#include + +// Reset main stack pointer to main stack pointer, and jump to program counter +static noreturn __attribute__((naked)) void prv_perform_jump(uint32_t sp, uint32_t pc); diff --git a/libraries/ms-bootloader/inc/jump_to_bootloader.h b/libraries/ms-bootloader/inc/jump_to_bootloader.h new file mode 100644 index 000000000..91938239a --- /dev/null +++ b/libraries/ms-bootloader/inc/jump_to_bootloader.h @@ -0,0 +1,4 @@ +#pragma once + +// Jump to the bootloade at the beginning of flash memory +void jump_to_bootloader(void); diff --git a/libraries/ms-bootloader/src/jump.c b/libraries/ms-bootloader/src/jump.c new file mode 100644 index 000000000..e85162384 --- /dev/null +++ b/libraries/ms-bootloader/src/jump.c @@ -0,0 +1,12 @@ +#include "jump.h" + +static noreturn __attribute__((naked)) void prv_perform_jump(uint32_t sp, uint32_t pc) { + __asm( + "msr msp, %[sp] \n" // reset the main stack pointer (msp) to sp + "bx %[pc] \n" // jump to pc + + // this bizarre syntax associates the "sp" and "pc" in asm with the sp and pc parameters + // see http://www.ethernut.de/en/documents/arm-inline-asm.html + : + : [sp] "r"(sp), [pc] "r"(pc)); +} diff --git a/libraries/ms-bootloader/src/jump_to_bootloader.c b/libraries/ms-bootloader/src/jump_to_bootloader.c new file mode 100644 index 000000000..18f8c0568 --- /dev/null +++ b/libraries/ms-bootloader/src/jump_to_bootloader.c @@ -0,0 +1,41 @@ +#include "jump_to_bootloader.h" + +#include +#include +#include + +#include "bootloader_mcu.h" +#include "jump.h" +#include "stm32f0xx_misc.h" +#include "stm32f0xx_syscfg.h" + +static noreturn __attribute__((naked)) void prv_perform_jump(uint32_t sp, uint32_t pc) { + __asm( + "msr msp, %[sp] \n" // reset the main stack pointer (msp) to sp + "bx %[pc] \n" // jump to pc + + // this bizarre syntax associates the "sp" and "pc" in asm with the sp and pc parameters + // see http://www.ethernut.de/en/documents/arm-inline-asm.html + : + : [sp] "r"(sp), [pc] "r"(pc)); +} + +void jump_to_bootloader(void) { + // Disable all interrupts so their is no interference when working with vector tables + __disable_irq(); + + // Reset the vector table to bootloader's vector table + SYSCFG_MemoryRemapConfig( + SYSCFG_MemoryRemap_Flash); // change where the vector table is stored to beginning of flash + + // story memory location of bootloader starting point at the beginning of flash? + uint32_t *bootloader_in_flash = BOOTLOADER_DEFAULT_LOCATION; + // setting the stack pointer to the bootloader location now + uint32_t initial_sp = bootloader_in_flash[0]; + uint32_t reset_handler_pc = bootloader_in_flash[1]; + + // re-enable interrupts + __enable_irq(); + // jump to bootloader + prv_perform_jump(initial_sp, reset_handler_pc); +} diff --git a/libraries/ms-common/src/can_fsm.c b/libraries/ms-common/src/can_fsm.c index 7eaec813c..4258feb2b 100644 --- a/libraries/ms-common/src/can_fsm.c +++ b/libraries/ms-common/src/can_fsm.c @@ -1,9 +1,11 @@ #include "can_fsm.h" + #include "bootloader_can.h" #include "can.h" #include "can_hw.h" #include "can_msg_defs.h" #include "can_rx.h" +#include "jump_to_bootloader.h" FSM_DECLARE_STATE(can_rx_fsm_handle); FSM_DECLARE_STATE(can_tx_fsm_handle); @@ -57,6 +59,9 @@ static void prv_handle_rx(Fsm *fsm, const Event *e, void *context) { // Process bootloader messages if (rx_msg.source_id == SYSTEM_CAN_DEVICE_BOOTLOADER) { +#ifdef APP_COMP_ON_BOOT + jump_to_bootloader(); +#endif result = bootloader_can_receive(&rx_msg); return; } diff --git a/platform/stm32f0xx/platform.mk b/platform/stm32f0xx/platform.mk index 414448609..402c5a02c 100644 --- a/platform/stm32f0xx/platform.mk +++ b/platform/stm32f0xx/platform.mk @@ -44,6 +44,7 @@ endif DEFAULT_LINKER_SCRIPT ?= stm32f0_default.ld ifeq ($(MAKECMDGOALS),temp-bootloader-write) DEFAULT_LINKER_SCRIPT := stm32f0_application.ld +CFLAGS += -DAPP_COMP_ON_BOOT endif # Device openocd config file From b5824540f9c0449c4900799513154ddbe9fb49bc Mon Sep 17 00:00:00 2001 From: Vaaranan Yogalingam Date: Sun, 10 Oct 2021 16:40:32 +0000 Subject: [PATCH 10/23] [SOFT-468] fixed jump function implementation --- libraries/ms-bootloader/src/jump_to_bootloader.c | 11 ----------- .../bootloader/src/stm32f0xx/jump_to_bootloader.c | 11 ----------- 2 files changed, 22 deletions(-) diff --git a/libraries/ms-bootloader/src/jump_to_bootloader.c b/libraries/ms-bootloader/src/jump_to_bootloader.c index 18f8c0568..458146374 100644 --- a/libraries/ms-bootloader/src/jump_to_bootloader.c +++ b/libraries/ms-bootloader/src/jump_to_bootloader.c @@ -9,17 +9,6 @@ #include "stm32f0xx_misc.h" #include "stm32f0xx_syscfg.h" -static noreturn __attribute__((naked)) void prv_perform_jump(uint32_t sp, uint32_t pc) { - __asm( - "msr msp, %[sp] \n" // reset the main stack pointer (msp) to sp - "bx %[pc] \n" // jump to pc - - // this bizarre syntax associates the "sp" and "pc" in asm with the sp and pc parameters - // see http://www.ethernut.de/en/documents/arm-inline-asm.html - : - : [sp] "r"(sp), [pc] "r"(pc)); -} - void jump_to_bootloader(void) { // Disable all interrupts so their is no interference when working with vector tables __disable_irq(); diff --git a/projects/bootloader/src/stm32f0xx/jump_to_bootloader.c b/projects/bootloader/src/stm32f0xx/jump_to_bootloader.c index 18f8c0568..458146374 100644 --- a/projects/bootloader/src/stm32f0xx/jump_to_bootloader.c +++ b/projects/bootloader/src/stm32f0xx/jump_to_bootloader.c @@ -9,17 +9,6 @@ #include "stm32f0xx_misc.h" #include "stm32f0xx_syscfg.h" -static noreturn __attribute__((naked)) void prv_perform_jump(uint32_t sp, uint32_t pc) { - __asm( - "msr msp, %[sp] \n" // reset the main stack pointer (msp) to sp - "bx %[pc] \n" // jump to pc - - // this bizarre syntax associates the "sp" and "pc" in asm with the sp and pc parameters - // see http://www.ethernut.de/en/documents/arm-inline-asm.html - : - : [sp] "r"(sp), [pc] "r"(pc)); -} - void jump_to_bootloader(void) { // Disable all interrupts so their is no interference when working with vector tables __disable_irq(); From a91053cbe73034206ccc9b28259b2e313eb77ba1 Mon Sep 17 00:00:00 2001 From: Vaaranan Yogalingam Date: Sun, 10 Oct 2021 17:10:45 +0000 Subject: [PATCH 11/23] [SOFT-468] moved jump.c --- projects/bootloader/src/{stm32f0xx => }/jump.c | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename projects/bootloader/src/{stm32f0xx => }/jump.c (100%) diff --git a/projects/bootloader/src/stm32f0xx/jump.c b/projects/bootloader/src/jump.c similarity index 100% rename from projects/bootloader/src/stm32f0xx/jump.c rename to projects/bootloader/src/jump.c From 3837dd3ec38e83cd121a6a707a87f3d4ab2ba6cb Mon Sep 17 00:00:00 2001 From: Vaaranan Yogalingam Date: Sun, 10 Oct 2021 18:08:35 +0000 Subject: [PATCH 12/23] [SOFT-468] made perform_jump non-static/public --- libraries/ms-bootloader/inc/jump.h | 2 +- libraries/ms-bootloader/src/jump.c | 2 +- libraries/ms-bootloader/src/jump_to_bootloader.c | 2 +- projects/bootloader/inc/jump.h | 2 +- projects/bootloader/src/jump.c | 2 +- projects/bootloader/src/stm32f0xx/jump_to_bootloader.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/ms-bootloader/inc/jump.h b/libraries/ms-bootloader/inc/jump.h index ae7be3fb3..c7a117660 100644 --- a/libraries/ms-bootloader/inc/jump.h +++ b/libraries/ms-bootloader/inc/jump.h @@ -4,4 +4,4 @@ #include // Reset main stack pointer to main stack pointer, and jump to program counter -static noreturn __attribute__((naked)) void prv_perform_jump(uint32_t sp, uint32_t pc); +noreturn __attribute__((naked)) void perform_jump(uint32_t sp, uint32_t pc); diff --git a/libraries/ms-bootloader/src/jump.c b/libraries/ms-bootloader/src/jump.c index e85162384..addab0fff 100644 --- a/libraries/ms-bootloader/src/jump.c +++ b/libraries/ms-bootloader/src/jump.c @@ -1,6 +1,6 @@ #include "jump.h" -static noreturn __attribute__((naked)) void prv_perform_jump(uint32_t sp, uint32_t pc) { +noreturn __attribute__((naked)) void prv_perform_jump(uint32_t sp, uint32_t pc) { __asm( "msr msp, %[sp] \n" // reset the main stack pointer (msp) to sp "bx %[pc] \n" // jump to pc diff --git a/libraries/ms-bootloader/src/jump_to_bootloader.c b/libraries/ms-bootloader/src/jump_to_bootloader.c index 458146374..4eaa51811 100644 --- a/libraries/ms-bootloader/src/jump_to_bootloader.c +++ b/libraries/ms-bootloader/src/jump_to_bootloader.c @@ -26,5 +26,5 @@ void jump_to_bootloader(void) { // re-enable interrupts __enable_irq(); // jump to bootloader - prv_perform_jump(initial_sp, reset_handler_pc); + perform_jump(initial_sp, reset_handler_pc); } diff --git a/projects/bootloader/inc/jump.h b/projects/bootloader/inc/jump.h index ae7be3fb3..c7a117660 100644 --- a/projects/bootloader/inc/jump.h +++ b/projects/bootloader/inc/jump.h @@ -4,4 +4,4 @@ #include // Reset main stack pointer to main stack pointer, and jump to program counter -static noreturn __attribute__((naked)) void prv_perform_jump(uint32_t sp, uint32_t pc); +noreturn __attribute__((naked)) void perform_jump(uint32_t sp, uint32_t pc); diff --git a/projects/bootloader/src/jump.c b/projects/bootloader/src/jump.c index e85162384..b02547046 100644 --- a/projects/bootloader/src/jump.c +++ b/projects/bootloader/src/jump.c @@ -1,6 +1,6 @@ #include "jump.h" -static noreturn __attribute__((naked)) void prv_perform_jump(uint32_t sp, uint32_t pc) { +noreturn __attribute__((naked)) void perform_jump(uint32_t sp, uint32_t pc) { __asm( "msr msp, %[sp] \n" // reset the main stack pointer (msp) to sp "bx %[pc] \n" // jump to pc diff --git a/projects/bootloader/src/stm32f0xx/jump_to_bootloader.c b/projects/bootloader/src/stm32f0xx/jump_to_bootloader.c index 458146374..4eaa51811 100644 --- a/projects/bootloader/src/stm32f0xx/jump_to_bootloader.c +++ b/projects/bootloader/src/stm32f0xx/jump_to_bootloader.c @@ -26,5 +26,5 @@ void jump_to_bootloader(void) { // re-enable interrupts __enable_irq(); // jump to bootloader - prv_perform_jump(initial_sp, reset_handler_pc); + perform_jump(initial_sp, reset_handler_pc); } From 718f7f816917ebc0ade70c026d36eb9dc73ffdf9 Mon Sep 17 00:00:00 2001 From: Vaaranan Yogalingam Date: Sun, 10 Oct 2021 18:49:28 +0000 Subject: [PATCH 13/23] [SOFT-468] included string library to jump header --- libraries/ms-bootloader/inc/jump.h | 1 + projects/bootloader/inc/jump.h | 1 + 2 files changed, 2 insertions(+) diff --git a/libraries/ms-bootloader/inc/jump.h b/libraries/ms-bootloader/inc/jump.h index c7a117660..b3a2f690f 100644 --- a/libraries/ms-bootloader/inc/jump.h +++ b/libraries/ms-bootloader/inc/jump.h @@ -2,6 +2,7 @@ #include #include +#include // Reset main stack pointer to main stack pointer, and jump to program counter noreturn __attribute__((naked)) void perform_jump(uint32_t sp, uint32_t pc); diff --git a/projects/bootloader/inc/jump.h b/projects/bootloader/inc/jump.h index c7a117660..b3a2f690f 100644 --- a/projects/bootloader/inc/jump.h +++ b/projects/bootloader/inc/jump.h @@ -2,6 +2,7 @@ #include #include +#include // Reset main stack pointer to main stack pointer, and jump to program counter noreturn __attribute__((naked)) void perform_jump(uint32_t sp, uint32_t pc); From d3d5bd5b17895d642ab0ff68683cfdf3887a70ac Mon Sep 17 00:00:00 2001 From: Vaaranan Yogalingam Date: Wed, 13 Oct 2021 03:33:46 +0000 Subject: [PATCH 14/23] [SOFT-468] Removed naked attribute from jump function --- libraries/ms-bootloader/inc/jump.h | 2 +- libraries/ms-bootloader/src/jump.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/ms-bootloader/inc/jump.h b/libraries/ms-bootloader/inc/jump.h index b3a2f690f..321c50ebe 100644 --- a/libraries/ms-bootloader/inc/jump.h +++ b/libraries/ms-bootloader/inc/jump.h @@ -5,4 +5,4 @@ #include // Reset main stack pointer to main stack pointer, and jump to program counter -noreturn __attribute__((naked)) void perform_jump(uint32_t sp, uint32_t pc); +noreturn void perform_jump(uint32_t sp, uint32_t pc); diff --git a/libraries/ms-bootloader/src/jump.c b/libraries/ms-bootloader/src/jump.c index addab0fff..dd04d329d 100644 --- a/libraries/ms-bootloader/src/jump.c +++ b/libraries/ms-bootloader/src/jump.c @@ -1,6 +1,6 @@ #include "jump.h" -noreturn __attribute__((naked)) void prv_perform_jump(uint32_t sp, uint32_t pc) { +noreturn void prv_perform_jump(uint32_t sp, uint32_t pc) { __asm( "msr msp, %[sp] \n" // reset the main stack pointer (msp) to sp "bx %[pc] \n" // jump to pc From ad43709e3dec5e89d8caeb8c7893beb5e07327fc Mon Sep 17 00:00:00 2001 From: Vaaranan Yogalingam Date: Wed, 13 Oct 2021 04:04:17 +0000 Subject: [PATCH 15/23] [SOFT-468] Removed naked attribute from jump function in project itself --- projects/bootloader/inc/jump.h | 2 +- projects/bootloader/src/jump.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/bootloader/inc/jump.h b/projects/bootloader/inc/jump.h index b3a2f690f..321c50ebe 100644 --- a/projects/bootloader/inc/jump.h +++ b/projects/bootloader/inc/jump.h @@ -5,4 +5,4 @@ #include // Reset main stack pointer to main stack pointer, and jump to program counter -noreturn __attribute__((naked)) void perform_jump(uint32_t sp, uint32_t pc); +noreturn void perform_jump(uint32_t sp, uint32_t pc); diff --git a/projects/bootloader/src/jump.c b/projects/bootloader/src/jump.c index b02547046..e002674b6 100644 --- a/projects/bootloader/src/jump.c +++ b/projects/bootloader/src/jump.c @@ -1,6 +1,6 @@ #include "jump.h" -noreturn __attribute__((naked)) void perform_jump(uint32_t sp, uint32_t pc) { +noreturn void perform_jump(uint32_t sp, uint32_t pc) { __asm( "msr msp, %[sp] \n" // reset the main stack pointer (msp) to sp "bx %[pc] \n" // jump to pc From f3a9b4bf0d2f3b6c6526c6bfb3c105cdfb619c02 Mon Sep 17 00:00:00 2001 From: Vaaranan Yogalingam Date: Thu, 11 Nov 2021 01:07:23 +0000 Subject: [PATCH 16/23] [SOFT-468] Moved implementation to STM32F0XX --- projects/bootloader/src/{ => stm32f0xx}/jump.c | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename projects/bootloader/src/{ => stm32f0xx}/jump.c (100%) diff --git a/projects/bootloader/src/jump.c b/projects/bootloader/src/stm32f0xx/jump.c similarity index 100% rename from projects/bootloader/src/jump.c rename to projects/bootloader/src/stm32f0xx/jump.c From 4be00058882fbb2b275fabc79e37be8b4c1d8881 Mon Sep 17 00:00:00 2001 From: Vaaranan Yogalingam Date: Thu, 11 Nov 2021 01:37:29 +0000 Subject: [PATCH 17/23] [SOFT-468] removed noreturn from perform jump --- projects/bootloader/src/stm32f0xx/jump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/bootloader/src/stm32f0xx/jump.c b/projects/bootloader/src/stm32f0xx/jump.c index e002674b6..227a57999 100644 --- a/projects/bootloader/src/stm32f0xx/jump.c +++ b/projects/bootloader/src/stm32f0xx/jump.c @@ -1,6 +1,6 @@ #include "jump.h" -noreturn void perform_jump(uint32_t sp, uint32_t pc) { +void perform_jump(uint32_t sp, uint32_t pc) { __asm( "msr msp, %[sp] \n" // reset the main stack pointer (msp) to sp "bx %[pc] \n" // jump to pc From f379df387fb051250c381271dd378765e0d42085 Mon Sep 17 00:00:00 2001 From: Vaaranan Yogalingam Date: Sat, 13 Nov 2021 17:41:50 +0000 Subject: [PATCH 18/23] [SOFT-468] moved implementation from bootloader project to ms-bootloader --- libraries/ms-bootloader/src/jump.c | 2 +- projects/bootloader/inc/jump.h | 8 ----- projects/bootloader/inc/jump_to_bootloader.h | 4 --- projects/bootloader/src/stm32f0xx/jump.c | 12 -------- .../src/stm32f0xx/jump_to_bootloader.c | 30 ------------------- 5 files changed, 1 insertion(+), 55 deletions(-) delete mode 100644 projects/bootloader/inc/jump.h delete mode 100644 projects/bootloader/inc/jump_to_bootloader.h delete mode 100644 projects/bootloader/src/stm32f0xx/jump.c delete mode 100644 projects/bootloader/src/stm32f0xx/jump_to_bootloader.c diff --git a/libraries/ms-bootloader/src/jump.c b/libraries/ms-bootloader/src/jump.c index dd04d329d..1cdf3d144 100644 --- a/libraries/ms-bootloader/src/jump.c +++ b/libraries/ms-bootloader/src/jump.c @@ -1,6 +1,6 @@ #include "jump.h" -noreturn void prv_perform_jump(uint32_t sp, uint32_t pc) { +__attribute__((naked)) noreturn void prv_perform_jump(uint32_t sp, uint32_t pc) { __asm( "msr msp, %[sp] \n" // reset the main stack pointer (msp) to sp "bx %[pc] \n" // jump to pc diff --git a/projects/bootloader/inc/jump.h b/projects/bootloader/inc/jump.h deleted file mode 100644 index 321c50ebe..000000000 --- a/projects/bootloader/inc/jump.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include -#include -#include - -// Reset main stack pointer to main stack pointer, and jump to program counter -noreturn void perform_jump(uint32_t sp, uint32_t pc); diff --git a/projects/bootloader/inc/jump_to_bootloader.h b/projects/bootloader/inc/jump_to_bootloader.h deleted file mode 100644 index 91938239a..000000000 --- a/projects/bootloader/inc/jump_to_bootloader.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once - -// Jump to the bootloade at the beginning of flash memory -void jump_to_bootloader(void); diff --git a/projects/bootloader/src/stm32f0xx/jump.c b/projects/bootloader/src/stm32f0xx/jump.c deleted file mode 100644 index 227a57999..000000000 --- a/projects/bootloader/src/stm32f0xx/jump.c +++ /dev/null @@ -1,12 +0,0 @@ -#include "jump.h" - -void perform_jump(uint32_t sp, uint32_t pc) { - __asm( - "msr msp, %[sp] \n" // reset the main stack pointer (msp) to sp - "bx %[pc] \n" // jump to pc - - // this bizarre syntax associates the "sp" and "pc" in asm with the sp and pc parameters - // see http://www.ethernut.de/en/documents/arm-inline-asm.html - : - : [sp] "r"(sp), [pc] "r"(pc)); -} diff --git a/projects/bootloader/src/stm32f0xx/jump_to_bootloader.c b/projects/bootloader/src/stm32f0xx/jump_to_bootloader.c deleted file mode 100644 index 4eaa51811..000000000 --- a/projects/bootloader/src/stm32f0xx/jump_to_bootloader.c +++ /dev/null @@ -1,30 +0,0 @@ -#include "jump_to_bootloader.h" - -#include -#include -#include - -#include "bootloader_mcu.h" -#include "jump.h" -#include "stm32f0xx_misc.h" -#include "stm32f0xx_syscfg.h" - -void jump_to_bootloader(void) { - // Disable all interrupts so their is no interference when working with vector tables - __disable_irq(); - - // Reset the vector table to bootloader's vector table - SYSCFG_MemoryRemapConfig( - SYSCFG_MemoryRemap_Flash); // change where the vector table is stored to beginning of flash - - // story memory location of bootloader starting point at the beginning of flash? - uint32_t *bootloader_in_flash = BOOTLOADER_DEFAULT_LOCATION; - // setting the stack pointer to the bootloader location now - uint32_t initial_sp = bootloader_in_flash[0]; - uint32_t reset_handler_pc = bootloader_in_flash[1]; - - // re-enable interrupts - __enable_irq(); - // jump to bootloader - perform_jump(initial_sp, reset_handler_pc); -} From 450b24302618c83026f7aba81d69f2c516eaae37 Mon Sep 17 00:00:00 2001 From: Vaaranan Yogalingam Date: Sat, 13 Nov 2021 17:43:50 +0000 Subject: [PATCH 19/23] [SOFT-468] changes APP_COMP_ON_BOOT to BOOTLOADER_APPLICATION --- platform/stm32f0xx/platform.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/stm32f0xx/platform.mk b/platform/stm32f0xx/platform.mk index 402c5a02c..3df400b64 100644 --- a/platform/stm32f0xx/platform.mk +++ b/platform/stm32f0xx/platform.mk @@ -44,7 +44,7 @@ endif DEFAULT_LINKER_SCRIPT ?= stm32f0_default.ld ifeq ($(MAKECMDGOALS),temp-bootloader-write) DEFAULT_LINKER_SCRIPT := stm32f0_application.ld -CFLAGS += -DAPP_COMP_ON_BOOT +CFLAGS += -DBOOTLOADER_APPLICATION endif # Device openocd config file From 426d9e30adac966f320b2464b46e86cd088fe162 Mon Sep 17 00:00:00 2001 From: Vaaranan Yogalingam Date: Sat, 13 Nov 2021 17:50:02 +0000 Subject: [PATCH 20/23] [SOFT-468] changed BOOTLOADER_DEFAULT_LOCATION to BOOTLOADER_START --- libraries/ms-bootloader/src/jump_to_bootloader.c | 2 +- projects/bootloader/inc/stm32f0xx/bootloader_mcu.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/ms-bootloader/src/jump_to_bootloader.c b/libraries/ms-bootloader/src/jump_to_bootloader.c index 4eaa51811..6e3091cac 100644 --- a/libraries/ms-bootloader/src/jump_to_bootloader.c +++ b/libraries/ms-bootloader/src/jump_to_bootloader.c @@ -18,7 +18,7 @@ void jump_to_bootloader(void) { SYSCFG_MemoryRemap_Flash); // change where the vector table is stored to beginning of flash // story memory location of bootloader starting point at the beginning of flash? - uint32_t *bootloader_in_flash = BOOTLOADER_DEFAULT_LOCATION; + uint32_t *bootloader_in_flash = BOOTLOADER_START; // setting the stack pointer to the bootloader location now uint32_t initial_sp = bootloader_in_flash[0]; uint32_t reset_handler_pc = bootloader_in_flash[1]; diff --git a/projects/bootloader/inc/stm32f0xx/bootloader_mcu.h b/projects/bootloader/inc/stm32f0xx/bootloader_mcu.h index ec90632ed..579f9e300 100644 --- a/projects/bootloader/inc/stm32f0xx/bootloader_mcu.h +++ b/projects/bootloader/inc/stm32f0xx/bootloader_mcu.h @@ -25,5 +25,5 @@ extern uint32_t _bootloader_size; #define BOOTLOADER_RAM_START ((void *)&_ram_start) #define BOOTLOADER_RAM_SIZE ((size_t)&_ram_size) #define BOOTLOADER_VECTOR_TABLE_SIZE ((size_t)&_vector_table_size) -#define BOOTLOADER_DEFAULT_LOCATION ((void *)&_bootloader_start) +#define BOOTLOADER_START ((void *)&_bootloader_start) #define BOOTLOADER_SIZE ((size_t)&_bootloader_size) From d75fa56f583d353b034c09a0c3fbc40b5c74f364 Mon Sep 17 00:00:00 2001 From: Vaaranan Yogalingam Date: Sat, 13 Nov 2021 17:51:55 +0000 Subject: [PATCH 21/23] [SOFT-468] Added description for ms-bootloader --- libraries/ms-bootloader/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/ms-bootloader/README.md b/libraries/ms-bootloader/README.md index 83854796d..598e2f4d0 100644 --- a/libraries/ms-bootloader/README.md +++ b/libraries/ms-bootloader/README.md @@ -12,5 +12,9 @@ - How does it fit into the overall system? - How does it work? (architectural overview, e.g. what each module's purpose is or how data flows through the firmware) --> + # ms-bootloader +