diff --git a/firmware/controllers/injector_central.cpp b/firmware/controllers/injector_central.cpp index c57538fa08..07949401d8 100644 --- a/firmware/controllers/injector_central.cpp +++ b/firmware/controllers/injector_central.cpp @@ -271,6 +271,8 @@ static void handleCommandX14(uint16_t index) { } +void jump_to_bootloader(); + // todo: this is probably a wrong place for this method now void executeTSCommand(uint16_t subsystem, uint16_t index) { scheduleMsg(logger, "IO test subsystem=%d index=%d", subsystem, index); @@ -301,8 +303,9 @@ void executeTSCommand(uint16_t subsystem, uint16_t index) { } else if (subsystem == 0x79) { scheduleStopEngine(); } else if (subsystem == 0xba) { -// todo: this does not work yet - // DFU mode +#if EFI_PROD_CODE + jump_to_bootloader(); +#endif /* EFI_PROD_CODE */ } else if (subsystem == 0xbb) { #if EFI_PROD_CODE rebootNow(); diff --git a/firmware/hw_layer/ports/stm32/stm32_common.cpp b/firmware/hw_layer/ports/stm32/stm32_common.cpp index 2521b2f0a4..d7e3db6756 100644 --- a/firmware/hw_layer/ports/stm32/stm32_common.cpp +++ b/firmware/hw_layer/ports/stm32/stm32_common.cpp @@ -134,4 +134,25 @@ int getAdcChannelPin(adc_channel_e hwChannel) { return getHwPin("get_pin", brainPin); } +void jump_to_bootloader() { + // todo: this does not work yet + + RCC->CR &= RCC_CR_HSITRIM | RCC_CR_HSION; /* CR Reset value. */ + RCC->CFGR = 0; /* CFGR reset value. */ + sdStop (&SD2); +// sduStop (&SDU1); + usbStop (&USBD1); + __disable_irq(); + chSysDisable(); + SysTick->CTRL = SysTick->LOAD = SysTick->VAL = 0; + SYSCFG->MEMRMP = 0x01; + SCB->VTOR = 0; + SCB->ICSR = (0x1U << 27); //ICSR_PENDSVCLR; + const uint32_t p = (*((uint32_t *) 0x1FFF0000)); + __set_MSP(p); + void (*SysMemBootJump)(void); + SysMemBootJump = (void (*)(void)) (*((uint32_t *) 0x1FFF0004)); + SysMemBootJump(); +} + #endif /* HAL_USE_ADC */