-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Soft 468 jumping back to bootloader #459
base: master
Are you sure you want to change the base?
Changes from all commits
cab2401
f1ce7d0
6d48397
b0a8848
069f19b
d52dd55
2f6df6a
d7782c6
4ec7d10
8b21f0d
0687368
b582454
3be0a3a
a91053c
3837dd3
adf3c2c
718f7f8
d3d5bd5
8289d59
ad43709
6b5dbae
f3a9b4b
4be0005
b502b92
f379df3
450b243
426d9e3
d75fa56
eaf6cd0
3a84088
47f14b9
fa7f236
f0c9869
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!-- | ||
General guidelines | ||
These are just guidelines, not strict rules - document however seems best. | ||
A README for a firmware-only project (e.g. Babydriver, MU, bootloader, CAN explorer) should answer the following questions: | ||
- What is it? | ||
- What problem does it solve? | ||
- How do I use it? (with usage examples / example commands, etc) | ||
- How does it work? (architectural overview) | ||
A README for a board project (powering a hardware board, e.g. power distribution, centre console, charger, BMS carrier) should answer the following questions: | ||
- What is the purpose of the board? | ||
- What are all the things that the firmware needs to do? | ||
- 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 | ||
|
||
ms-bootloader currently contains the jump_to_bootloader project, which allows an application to jump back to the bootloader on command |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#pragma once | ||
// This library allows client to jump to an arbitrary memory address | ||
#include <stdint.h> | ||
#include <stdnoreturn.h> | ||
#include <string.h> | ||
|
||
// Reset main stack pointer to main stack pointer, and jump to program counter | ||
noreturn void perform_jump(uint32_t sp, uint32_t pc); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#pragma once | ||
|
||
// Jump to the bootloade at the beginning of flash memory | ||
void jump_to_bootloader(void); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 := |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include "jump.h" | ||
|
||
__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 | ||
|
||
// 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)); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include "jump_to_bootloader.h" | ||
|
||
#include <stdint.h> | ||
#include <stdnoreturn.h> | ||
#include <string.h> | ||
|
||
#include "bootloader_mcu.h" | ||
#include "jump.h" | ||
#include "stm32f0xx_misc.h" | ||
#include "stm32f0xx_syscfg.h" | ||
|
||
void jump_to_bootloader(void) { | ||
#ifdef BOOTLOADER_APPLICATION // don't do anything if we're not in the bootloader/application | ||
// 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_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]; | ||
|
||
// re-enable interrupts | ||
__enable_irq(); | ||
// jump to bootloader | ||
perform_jump(initial_sp, reset_handler_pc); | ||
#endif // BOOTLOADER_APPLICATION | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You'll get a linker error here when the |
||
|
||
FSM_DECLARE_STATE(can_rx_fsm_handle); | ||
FSM_DECLARE_STATE(can_tx_fsm_handle); | ||
|
@@ -57,6 +59,10 @@ 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 BOOTLOADER_APPLICATION // *NOTE: jump to bootloader does not actually return | ||
jump_to_bootloader(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: you'll want to add a comment saying that |
||
return; | ||
#endif | ||
result = bootloader_can_receive(&rx_msg); | ||
return; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
#include "flash.h" | ||
#include "interrupt.h" | ||
#include "jump_to_application.h" | ||
#include "jump_to_bootloader.h" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the next steps for this module is that we want to jump from the bootloader to the application when we receive a datagram message while in an application. This will be in can_fsm.c, in the
So there are a couple of parts to doing this:
|
||
#include "log.h" | ||
#include "ping.h" | ||
#include "query.h" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should write a brief description of what goes in ms-bootloader here.