From 4e3b086afde6a213f3f4bdb4d4c0b54e8d3e1b2b Mon Sep 17 00:00:00 2001 From: pique_n Date: Tue, 6 Dec 2022 08:55:42 +0100 Subject: [PATCH] Add bootloader --- Core/Application/MAIN_MainApplication.c | 8 +++++++- Core/Drivers/ADCD_AdcDriver.c | 13 ++++++++----- Core/Src/main.c | 19 ++++++++++++++++++- Makefile | 7 +++++++ STM32L432KBUX_FLASH.ld | 2 +- STM32L432KBUx_FLASH.ld | 2 +- startup_stm32l432xx.s | 1 + 7 files changed, 43 insertions(+), 9 deletions(-) diff --git a/Core/Application/MAIN_MainApplication.c b/Core/Application/MAIN_MainApplication.c index 66f42b3..e54569e 100644 --- a/Core/Application/MAIN_MainApplication.c +++ b/Core/Application/MAIN_MainApplication.c @@ -70,7 +70,9 @@ #define COMMAND_ALARM 4 #define COMMAND_CLEAR_ERROR 5 -#define WATCHDOG 33000 +#define COMMAND_REBOOT 255 + +#define WATCHDOG 3000 //================================================================================================= // Section: MACROS @@ -276,6 +278,10 @@ PRIVATE VOID vTask( PVOID arg ) case COMMAND_CLEAR_ERROR: VARH_vSetVariableDataFromSystemU32( VARH_eError, 0x00000000 ); break; + case COMMAND_REBOOT: + PECO_Enable( FALSE ); + HAL_NVIC_SystemReset(); + break; default: break; } diff --git a/Core/Drivers/ADCD_AdcDriver.c b/Core/Drivers/ADCD_AdcDriver.c index d7ce5a7..155b0d6 100644 --- a/Core/Drivers/ADCD_AdcDriver.c +++ b/Core/Drivers/ADCD_AdcDriver.c @@ -189,12 +189,12 @@ PRIVATE BOOL boReadReg( U8 u8Register, PU16 pu16Data, BOOL boIs16bit ); //------------------------------------------------------------------------------------------------- BOOL ADCD_boInitializeModule( VOID ) { - BOOL boOK = TRUE; + BOOL boOK = TRUE; - boOK &= ( ( m_pstMutexID = osMutexNew( &m_stMutexAttr ) ) == NULL ) ? FALSE : TRUE; + boOK &= ( ( m_pstMutexID = osMutexNew( &m_stMutexAttr ) ) == NULL ) ? FALSE : TRUE; osMutexAcquire( m_pstMutexID, osWaitForever ); - + // Conifg ADC Cold DIPO_vSetOutput( DIPO_eCS_Module ); boOK &= boWriteReg( REG_CONFIG, (U16) CONFIG | CONFIG_FAULTSTATCLEAR, FALSE ); @@ -204,10 +204,13 @@ BOOL ADCD_boInitializeModule( VOID ) DIPO_vSetOutput( DIPO_eCS_Water ); boOK &= boWriteReg( REG_CONFIG, (U16) CONFIG | CONFIG_FAULTSTATCLEAR, FALSE ); DIPO_vResetOutput( DIPO_eCS_Water ); - + + /** @todo read back configuration */ + + osMutexRelease( m_pstMutexID ); - return( boOK ); + return( boOK ); } //------------------------------------------------------------------------------------------------- diff --git a/Core/Src/main.c b/Core/Src/main.c index c762325..c6a3d0e 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -91,7 +91,24 @@ void vDefaultTask(void *argument); /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ +/** + * @brief Vector base address configuration. It should no longer be at the start of + * flash memory but moved forward because the first part of flash is + * reserved for the bootloader. Note that this is already done by the + * bootloader before starting this program. Unfortunately, function + * SystemInit() overwrites this change again. + * @return none. + */ +static void VectorBase_Config(void) +{ + /* The constant array with vectors of the vector table is declared externally in the + * c-startup code. + */ + extern const unsigned long g_pfnVectors[]; + /* Remap the vector table to where the vector table is located for this program. */ + SCB->VTOR = (unsigned long)&g_pfnVectors[0]; +} /* USER CODE END 0 */ /** @@ -101,7 +118,7 @@ void vDefaultTask(void *argument); int main(void) { /* USER CODE BEGIN 1 */ - + VectorBase_Config(); /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/ diff --git a/Makefile b/Makefile index 2974562..1506fd4 100644 --- a/Makefile +++ b/Makefile @@ -201,6 +201,13 @@ $(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR) $(BUILD_DIR): mkdir $@ +####################################### +# size +####################################### + +size: + "C:\Program Files (x86)\Arm GNU Toolchain arm-none-eabi\12.2 mpacbti-bet1\bin\arm-none-eabi-size.exe" $(BUILD_DIR)/$(TARGET).elf + ####################################### # clean up ####################################### diff --git a/STM32L432KBUX_FLASH.ld b/STM32L432KBUX_FLASH.ld index 19b3ff4..48ed2d1 100644 --- a/STM32L432KBUX_FLASH.ld +++ b/STM32L432KBUX_FLASH.ld @@ -63,7 +63,7 @@ MEMORY { RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K RAM2 (xrw) : ORIGIN = 0x10000000, LENGTH = 16K -FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 128K +FLASH (rx) : ORIGIN = 0x8002800, LENGTH = 128K-10K } /* Define output sections */ diff --git a/STM32L432KBUx_FLASH.ld b/STM32L432KBUx_FLASH.ld index 19b3ff4..48ed2d1 100644 --- a/STM32L432KBUx_FLASH.ld +++ b/STM32L432KBUx_FLASH.ld @@ -63,7 +63,7 @@ MEMORY { RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K RAM2 (xrw) : ORIGIN = 0x10000000, LENGTH = 16K -FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 128K +FLASH (rx) : ORIGIN = 0x8002800, LENGTH = 128K-10K } /* Define output sections */ diff --git a/startup_stm32l432xx.s b/startup_stm32l432xx.s index 27b2be0..35d7d60 100644 --- a/startup_stm32l432xx.s +++ b/startup_stm32l432xx.s @@ -230,6 +230,7 @@ g_pfnVectors: .word RNG_IRQHandler .word FPU_IRQHandler .word CRS_IRQHandler + .word 0x55AA11EE /*******************************************************************************