From 7ae8e4b67919d15d18bdd28b4ffa08d7e30ca506 Mon Sep 17 00:00:00 2001 From: Sven Wegener Date: Sun, 18 May 2014 11:56:21 +0200 Subject: [PATCH 1/2] stmhal: Activate bootloader with pyb.bootloader() Signed-off-by: Sven Wegener --- stmhal/modpyb.c | 16 ++++++++++++++++ stmhal/qstrdefsport.h | 1 + 2 files changed, 17 insertions(+) diff --git a/stmhal/modpyb.c b/stmhal/modpyb.c index 81dc921173..d93665e305 100644 --- a/stmhal/modpyb.c +++ b/stmhal/modpyb.c @@ -62,6 +62,21 @@ /// /// The `pyb` module contains specific functions related to the pyboard. +/// \function bootloader() +/// Activate the bootloader without BOOT* pins. +STATIC NORETURN mp_obj_t pyb_bootloader(uint n_args, const mp_obj_t *args) { + storage_flush(); + + HAL_RCC_DeInit(); + HAL_DeInit(); + + __set_MSP(*((uint32_t*) 0x1fff0000)); + ((void (*)(void)) *((uint32_t*) 0x1fff0004))(); + + while (1); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_bootloader_obj, 0, 1, pyb_bootloader); + /// \function info([dump_alloc_table]) /// Print out lots of information about the board. STATIC mp_obj_t pyb_info(uint n_args, const mp_obj_t *args) { @@ -302,6 +317,7 @@ MP_DECLARE_CONST_FUN_OBJ(pyb_usb_mode_obj); // defined in main.c STATIC const mp_map_elem_t pyb_module_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_pyb) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_bootloader), (mp_obj_t)&pyb_bootloader_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_info), (mp_obj_t)&pyb_info_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_unique_id), (mp_obj_t)&pyb_unique_id_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_freq), (mp_obj_t)&pyb_freq_obj }, diff --git a/stmhal/qstrdefsport.h b/stmhal/qstrdefsport.h index c2cf6840df..d822a542f0 100644 --- a/stmhal/qstrdefsport.h +++ b/stmhal/qstrdefsport.h @@ -29,6 +29,7 @@ Q(help) Q(pyb) Q(unique_id) +Q(bootloader) Q(info) Q(sd_test) Q(present) From 9bf4f7e3d397e7e602fb83c80c35ab30f97e9f76 Mon Sep 17 00:00:00 2001 From: Sven Wegener Date: Sun, 18 May 2014 13:15:02 +0200 Subject: [PATCH 2/2] stmhal: Remap system flash and adjust addresses Signed-off-by: Sven Wegener --- stmhal/modpyb.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stmhal/modpyb.c b/stmhal/modpyb.c index d93665e305..47e9710d75 100644 --- a/stmhal/modpyb.c +++ b/stmhal/modpyb.c @@ -70,8 +70,9 @@ STATIC NORETURN mp_obj_t pyb_bootloader(uint n_args, const mp_obj_t *args) { HAL_RCC_DeInit(); HAL_DeInit(); - __set_MSP(*((uint32_t*) 0x1fff0000)); - ((void (*)(void)) *((uint32_t*) 0x1fff0004))(); + __HAL_REMAPMEMORY_SYSTEMFLASH(); + __set_MSP(*((uint32_t*) 0x00000000)); + ((void (*)(void)) *((uint32_t*) 0x00000004))(); while (1); }