diff --git a/Core/Src/main.c b/Core/Src/main.c index 341278b..3282376 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -60,6 +60,7 @@ /* Private variables ---------------------------------------------------------*/ +// define the magic number for the bootloader 8 bytes /* USER CODE BEGIN PV */ uint8_t gCLS_DEVICE_ADDRESS = 0x11; /* USER CODE END PV */ @@ -72,11 +73,13 @@ static void MPU_Config(void); void MX_FREERTOS_Init(void); /* USER CODE BEGIN PFP */ void ULOG_SendLPUART(ulog_level_t level, char *msg); +void JumpToBootloader_system(void); /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ - +const uint32_t OS_BOOTFLAG_ADDRESS = 0x38000000; +const uint32_t OS_BOOTFLAG_MAGIC = 0xDEADBEFF; /* USER CODE END 0 */ /** @@ -87,10 +90,24 @@ int main(void) { /* USER CODE BEGIN 1 */ + // Check if the bootloader magic number is set at the given address + volatile uint32_t * ptr = (uint32_t *)OS_BOOTFLAG_ADDRESS; + if (*ptr == OS_BOOTFLAG_MAGIC) { + // Jump to the bootloader + *ptr = 0; + JumpToBootloader_system(); + } + + if (*ptr == 0) { + *ptr = 2; + NVIC_SystemReset(); + } + + /* USER CODE END 1 */ /* Enable I-Cache---------------------------------------------------------*/ - SCB_EnableICache(); + //SCB_EnableICache(); /* MCU Configuration--------------------------------------------------------*/ @@ -286,6 +303,17 @@ void ULOG_SendLPUART(ulog_level_t level, char *msg) { } void JumpToBootloader(void) +{ + + // Set the magic number to the given address + volatile uint32_t * ptr = (uint32_t *)OS_BOOTFLAG_ADDRESS; + *ptr = OS_BOOTFLAG_MAGIC; + + + NVIC_SystemReset(); +} + +void JumpToBootloader_system(void) { #define conBootloadAddress 0x1FF09800 diff --git a/STM32H723VGTX_RAM.ld b/STM32H723VGTX_RAM.ld index b00b194..651efc2 100644 --- a/STM32H723VGTX_RAM.ld +++ b/STM32H723VGTX_RAM.ld @@ -43,8 +43,9 @@ _Min_Stack_Size = 0x400; /* required amount of stack */ /* Specify the memory areas */ MEMORY { - RAM_EXEC (xrw) : ORIGIN = 0x24000000, LENGTH = 320K - DTCMRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K + RAM_EXEC (xrw) : ORIGIN = 0x24000000, LENGTH = 319K + RAM_NOINIT(xrw) : ORIGIN = 0x2404fc00, LENGTH = 1K + DTCMRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 127K ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K RAM_D2 (xrw) : ORIGIN = 0x30000000, LENGTH = 32K RAM_D3 (xrw) : ORIGIN = 0x38000000, LENGTH = 16K @@ -161,6 +162,12 @@ SECTIONS . = ALIGN(8); } >DTCMRAM + + .noinit : + { + KEEP(*(.noinitdata)) + } >DTCMRAM2 + /* Remove information from the standard libraries */ /DISCARD/ : {