stm32: Add support for a bootloader on stm32f0
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
c9cb462f90
commit
79e2376993
|
@ -19,7 +19,9 @@ SECTIONS
|
||||||
{
|
{
|
||||||
.text : {
|
.text : {
|
||||||
. = ALIGN(4);
|
. = ALIGN(4);
|
||||||
|
_text_vectortable_start = .;
|
||||||
KEEP(*(.vector_table))
|
KEEP(*(.vector_table))
|
||||||
|
_text_vectortable_end = .;
|
||||||
*(.text .text.*)
|
*(.text .text.*)
|
||||||
*(.rodata .rodata*)
|
*(.rodata .rodata*)
|
||||||
} > rom
|
} > rom
|
||||||
|
@ -27,6 +29,14 @@ SECTIONS
|
||||||
. = ALIGN(4);
|
. = ALIGN(4);
|
||||||
_data_flash = .;
|
_data_flash = .;
|
||||||
|
|
||||||
|
#if CONFIG_ARMCM_RAM_VECTORTABLE
|
||||||
|
.ram_vectortable (NOLOAD) : {
|
||||||
|
_ram_vectortable_start = .;
|
||||||
|
. = . + ( _text_vectortable_end - _text_vectortable_start ) ;
|
||||||
|
_ram_vectortable_end = .;
|
||||||
|
} > ram
|
||||||
|
#endif
|
||||||
|
|
||||||
.data : AT (_data_flash)
|
.data : AT (_data_flash)
|
||||||
{
|
{
|
||||||
. = ALIGN(4);
|
. = ALIGN(4);
|
||||||
|
|
|
@ -93,9 +93,9 @@ config STACK_SIZE
|
||||||
default 512
|
default 512
|
||||||
|
|
||||||
choice
|
choice
|
||||||
prompt "Bootloader offset" if MACH_STM32F407 || MACH_STM32F103
|
prompt "Bootloader offset" if MACH_STM32F407 || MACH_STM32F103 || MACH_STM32F070
|
||||||
config STM32_FLASH_START_2000
|
config STM32_FLASH_START_2000
|
||||||
bool "8KiB bootloader (stm32duino)" if MACH_STM32F103
|
bool "8KiB bootloader (stm32duino)" if MACH_STM32F103 || MACH_STM32F070
|
||||||
config STM32_FLASH_START_7000
|
config STM32_FLASH_START_7000
|
||||||
bool "28KiB bootloader" if MACH_STM32F103
|
bool "28KiB bootloader" if MACH_STM32F103
|
||||||
config STM32_FLASH_START_8000
|
config STM32_FLASH_START_8000
|
||||||
|
@ -110,6 +110,11 @@ config FLASH_START
|
||||||
default 0x8008000 if STM32_FLASH_START_8000
|
default 0x8008000 if STM32_FLASH_START_8000
|
||||||
default 0x8000000
|
default 0x8000000
|
||||||
|
|
||||||
|
config ARMCM_RAM_VECTORTABLE
|
||||||
|
bool
|
||||||
|
default y if MACH_STM32F0 && FLASH_START != 0x8000000
|
||||||
|
default n
|
||||||
|
|
||||||
choice
|
choice
|
||||||
prompt "Clock Reference" if LOW_LEVEL_OPTIONS
|
prompt "Clock Reference" if LOW_LEVEL_OPTIONS
|
||||||
config STM32_CLOCK_REF_8M
|
config STM32_CLOCK_REF_8M
|
||||||
|
|
|
@ -99,6 +99,22 @@ usb_request_bootloader(void)
|
||||||
NVIC_SystemReset();
|
NVIC_SystemReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copy vector table and remap ram so new vector table is used
|
||||||
|
static void
|
||||||
|
enable_ram_vectortable(void)
|
||||||
|
{
|
||||||
|
// Symbols created by armcm_link.lds.S linker script
|
||||||
|
extern uint32_t _ram_vectortable_start, _ram_vectortable_end;
|
||||||
|
extern uint32_t _text_vectortable_start;
|
||||||
|
|
||||||
|
uint32_t count = (&_ram_vectortable_end - &_ram_vectortable_start) * 4;
|
||||||
|
__builtin_memcpy(&_ram_vectortable_start, &_text_vectortable_start, count);
|
||||||
|
barrier();
|
||||||
|
|
||||||
|
enable_pclock(SYSCFG_BASE);
|
||||||
|
SYSCFG->CFGR1 |= 3 << SYSCFG_CFGR1_MEM_MODE_Pos;
|
||||||
|
}
|
||||||
|
|
||||||
#if !CONFIG_STM32_CLOCK_REF_INTERNAL
|
#if !CONFIG_STM32_CLOCK_REF_INTERNAL
|
||||||
DECL_CONSTANT_STR("RESERVE_PINS_crystal", "PF0,PF1");
|
DECL_CONSTANT_STR("RESERVE_PINS_crystal", "PF0,PF1");
|
||||||
#endif
|
#endif
|
||||||
|
@ -188,6 +204,9 @@ armcm_main(void)
|
||||||
|
|
||||||
SystemInit();
|
SystemInit();
|
||||||
|
|
||||||
|
if (CONFIG_ARMCM_RAM_VECTORTABLE)
|
||||||
|
enable_ram_vectortable();
|
||||||
|
|
||||||
// Set flash latency
|
// Set flash latency
|
||||||
FLASH->ACR = (1 << FLASH_ACR_LATENCY_Pos) | FLASH_ACR_PRFTBE;
|
FLASH->ACR = (1 << FLASH_ACR_LATENCY_Pos) | FLASH_ACR_PRFTBE;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue