avec dfu
Fork of Utils by
Revision 19:2b5bac7f435e, committed 2018-05-24
- Comitter:
- potless
- Date:
- Thu May 24 23:16:22 2018 +0000
- Parent:
- 18:522e18b47823
- Commit message:
- avec le flag pour le bootloader et l'id?e de d?clarer l usbserial uniquement si on n'est pas en phase de bootload
Changed in this revision
Utils.cpp | Show annotated file Show diff for this revision Revisions of this file |
Utils.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/Utils.cpp Thu May 17 07:45:30 2018 +0000 +++ b/Utils.cpp Thu May 24 23:16:22 2018 +0000 @@ -386,6 +386,8 @@ serial_port->printf(" K 1 = capteur CO2 mode streaming.\r\n"); serial_port->printf(" K 2 = capteur CO2 mode spooling.\r\n"); serial_port->printf(" A X = digi filter X. X égal à 32, 64, 128...\r\n"); + serial_port->printf(""); + serial_port->printf(" DFU = mise à jour firmware\r\n"); //serial_port->printf("\r\n"); fflush(stdout); } @@ -535,4 +537,117 @@ clean_line_EEPROM(pointer, address); } DEBUG("Eeprom néttoyée.\r\n"); +} + +void UTILS::DFU() +{ +DEEP_DEBUG(" mode DFU utils \r\n\r\n"); + +DEEP_DEBUG(" mode DFU deadbeef \r\n\r\n"); +wait(1); + + + +void (*SysMemBootJump)(void); + +/** +* Step: Set system memory address. +* +* For STM32F446, system memory is on 0x1FFF 0000 +* For other families, check AN2606 document table 110 with descriptions of memory addresses +*/ +volatile uint32_t addr = 0x1FFF0000; + + +/** +* Step: Disable RCC, set it to default (after reset) settings +* Internal clock, no PLL, etc. +*/ +HAL_RCC_DeInit(); +DEEP_DEBUG(" mode DFU rcc deinit \r\n\r\n"); +wait(1); + +__HAL_RCC_SYSCFG_CLK_ENABLE(); +DEEP_DEBUG(" mode DFU clk enable \r\n\r\n"); +wait(1); + +/** +* Step: Disable systick timer and reset it to default values +*/ +SysTick->CTRL = 0; +SysTick->LOAD = 0; +SysTick->VAL = 0; + + +/** +* Step: Disable all interrupts +*/ +__disable_irq(); +DEEP_DEBUG(" mode DFU irq disable \r\n\r\n"); +wait(1); + +__DSB(); + +/** +* Step: Remap system memory to address 0x0000 0000 in address space +* For each family registers may be different. +* Check reference manual for each family. +* +* For STM32F4xx, MEMRMP register in SYSCFG is used (bits[1:0]) +* For STM32F0xx, CFGR1 register in SYSCFG is used (bits[1:0]) +* For others, check family reference manual +*/ +//SYSCFG->MEMRMP = 1; + +__HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH(); //Call HAL macro to do this for you + +DEEP_DEBUG(" mode DFU remap \r\n\r\n"); +wait(1); + +/** +* Step: Set jump memory location for system memory +* Use address with 4 bytes offset which specifies jump location where program starts +*/ + + +/* Remap is not visible at once. Execute some unrelated command! */ +__DSB(); +__ISB(); + + + + +SysMemBootJump = (void (*)(void)) (*((uint32_t *)(addr + 4))); + +DEEP_DEBUG(" mode DFU jump \r\n\r\n"); +wait(1); + + +/** +* Step: Set main stack pointer. +* This step must be done last otherwise local variables in this function +* don't have proper value since stack pointer is located on different position +* +* Set direct address location which specifies stack pointer in SRAM location +*/ +__set_MSP(*(uint32_t *)addr); + +DEEP_DEBUG(" mode DFU set msp \r\n\r\n"); +wait(1); + +/** +* Step: Actually call our function to jump to set location +* This will start system memory execution +*/ + +SysMemBootJump(); + +/** +* Step: Connect USB<->UART converter to dedicated USART pins and test +* and test with bootloader works with STM32 Flash Loader Demonstrator software +*/ + +while (1); + + } \ No newline at end of file
--- a/Utils.h Thu May 17 07:45:30 2018 +0000 +++ b/Utils.h Thu May 24 23:16:22 2018 +0000 @@ -33,7 +33,7 @@ #define DEBUG(...) #endif -#define DEEP_DEBUG_MODE 0 +#define DEEP_DEBUG_MODE 1 #if DEEP_DEBUG_MODE #define DEEP_DEBUG(...) { printf(__VA_ARGS__); fflush(stdout);} @@ -270,6 +270,13 @@ */ static void clean_EEPROM(int address = EEPROM_ADDRESS); + /**Fonction pour mise à jour firmware par USB. + * @param + * @returns + * + */ + static void DFU(); + private: //Rien... };