diff --git a/README.md b/README.md index ccc2311ec3..d1038b0166 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ See https://rusefi.com/forum/viewtopic.php?f=5&t=9 | Release date | Revision | Details | | ------------ | --------- | ------- | +| 07/28/2018 | r19612 | improvement #809: software jump to DFU | | 04/25/2019 | r17317 | bugfix #775: electrical noise reboot during settings change causes with full tune loss | | 04/07/2019 | r17098 | improvement #714: TLE8888 Enable Outputs SPI integration | | 02/27/2019 | r16886 | bugfix #698: concurrency defect with single timer executor initialization | diff --git a/firmware/ChibiOS b/firmware/ChibiOS index 4012d627c9..1290cfd849 160000 --- a/firmware/ChibiOS +++ b/firmware/ChibiOS @@ -1 +1 @@ -Subproject commit 4012d627c92b0e60bdbfdfca4af823852c341e18 +Subproject commit 1290cfd8491a6e9a5ab4faa2af8f1debcca94e81 diff --git a/firmware/Makefile b/firmware/Makefile index 6fbcc609e8..6d32c60716 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -254,7 +254,8 @@ TCPPSRC = # List ASM source files here # List ASM source files here -ASMXSRC = $(STARTUPASM) $(PORTASM) $(OSALASM) +ASMXSRC = $(STARTUPASM) $(PORTASM) $(OSALASM) \ + $(RUSEFIASM) ifeq ($(CONFIGPATH),) CONFIGPATH=config/stm32f4ems diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index df01e2ee3c..7ec86db45f 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -812,6 +812,6 @@ int getRusEfiVersion(void) { if (initBootloader() != 0) return 123; #endif /* EFI_BOOTLOADER_INCLUDE_CODE */ - return 20190723; + return 20190728; } #endif /* EFI_UNIT_TEST */ diff --git a/firmware/hw_layer/backup_ram.cpp b/firmware/hw_layer/backup_ram.cpp index 78957ebc61..717dca1bb0 100644 --- a/firmware/hw_layer/backup_ram.cpp +++ b/firmware/hw_layer/backup_ram.cpp @@ -7,8 +7,8 @@ #include "backup_ram.h" uint32_t backupRamLoad(backup_ram_e idx) { - switch (idx) { #if HAL_USE_RTC + switch (idx) { case BACKUP_STEPPER_POS: return RTCD1.rtc->BKP0R & 0xffff; case BACKUP_IGNITION_SWITCH_COUNTER: @@ -17,16 +17,21 @@ uint32_t backupRamLoad(backup_ram_e idx) { return RTCD1.rtc->BKP1R & 0xffff; case BACKUP_CJ125_CALIBRATION_HEATER: return (RTCD1.rtc->BKP1R >> 16) & 0xffff; -#endif /* HAL_USE_RTC */ +// it is assembly code which reads this value +// case DFU_JUMP_REQUESTED: +// return RTCD1.rtc->BKP4R; default: - //scheduleMsg(logger, "Invalid backup ram idx %d", idx); + firmwareError(OBD_PCM_Processor_Fault, "Invalid backup ram idx %d", idx); return 0; } +#else + return 0; +#endif /* HAL_USE_RTC */ } void backupRamSave(backup_ram_e idx, uint32_t value) { - switch (idx) { #if HAL_USE_RTC + switch (idx) { case BACKUP_STEPPER_POS: RTCD1.rtc->BKP0R = (RTCD1.rtc->BKP0R & ~0x0000ffff) | (value & 0xffff); break; @@ -39,9 +44,13 @@ void backupRamSave(backup_ram_e idx, uint32_t value) { case BACKUP_CJ125_CALIBRATION_HEATER: RTCD1.rtc->BKP1R = (RTCD1.rtc->BKP1R & ~0xffff0000) | ((value & 0xffff) << 16); break; -#endif /* HAL_USE_RTC */ +// todo: start using this code + case DFU_JUMP_REQUESTED: + RTCD1.rtc->BKP4R = value; + break; default: - //scheduleMsg(logger, "Invalid backup ram idx %d, value 0x08x", idx, value); + firmwareError(OBD_PCM_Processor_Fault, "Invalid backup ram idx %d, value 0x08x", idx, value); break; } +#endif /* HAL_USE_RTC */ } diff --git a/firmware/hw_layer/backup_ram.h b/firmware/hw_layer/backup_ram.h index 84bb7e5949..7392cc55b4 100644 --- a/firmware/hw_layer/backup_ram.h +++ b/firmware/hw_layer/backup_ram.h @@ -33,6 +33,8 @@ typedef enum { * CJ125 Calibration data (16bit) */ BACKUP_CJ125_CALIBRATION_HEATER, + + DFU_JUMP_REQUESTED, } backup_ram_e; diff --git a/firmware/hw_layer/ports/stm32/rusEfiStartup.S b/firmware/hw_layer/ports/stm32/rusEfiStartup.S new file mode 100644 index 0000000000..c256501c9b --- /dev/null +++ b/firmware/hw_layer/ports/stm32/rusEfiStartup.S @@ -0,0 +1,45 @@ +/** + * @file rusEfiStartup.S + * rusEfi startup assembly + * + * We have ChibiOS '_crt0_entry' jumping here and then we jump back. + * There is probably no stack at this point to invoke a method. + */ + +// todo: I have no idea which lines are doing what +// todo: one of these is resolving 'Error: lo register required -- `ldr SP,[R0,#0]'' :) + .syntax unified + .cpu cortex-m3 + .thumb + .align 2 + .thumb_func +// end of 'I have no idea' + + .global rusEfiAsboluteStartupMethod +rusEfiAsboluteStartupMethod: +// [rusefi][DFU][start] +// Clive Two.Zero is the God of ST community forum +// Device specific, if in doubt RTFM +LDR R0, =0x2001FFF0 // End of SRAM for your CPU +LDR R1, =0xDEADBEEF // magic value +LDR R2, [R0, #0] +STR R0, [R0, #0] // Invalidate +CMP R2, R1 +BEQ UseDFU + // DFU bootloader not needed, jump back to normal ChibiOS startup + bl rusEfiAsboluteStartupMethodReturnPoint +UseDFU: + // AN2606 Application note + // STM32 microcontroller system memory boot mode +LDR R0, =0x40023844 // RCC_APB2ENR +LDR R1, =0x00004000 // ENABLE SYSCFG CLOCK +STR R1, [R0, #0] +LDR R0, =0x40013800 // SYSCFG_MEMRMP +LDR R1, =0x00000001 // MAP ROM AT ZERO +STR R1, [R0, #0] +LDR R0, =0x1FFF0000 // ROM BASE +LDR SP,[R0, #0] // SP @ +0 +LDR R0,[R0, #4] // PC @ +4 +BX R0 // this jumps to DFU bootloader + // I believe we are never executing this line +// [rusefi][DFU][end] diff --git a/firmware/hw_layer/ports/stm32/stm32_common.cpp b/firmware/hw_layer/ports/stm32/stm32_common.cpp index 8cb6cd02d4..a41f550b7b 100644 --- a/firmware/hw_layer/ports/stm32/stm32_common.cpp +++ b/firmware/hw_layer/ports/stm32/stm32_common.cpp @@ -14,7 +14,7 @@ #endif /* EFI_PIN_ADC9 */ #if EFI_PROD_CODE -#include "usbconsole.h" +#include "backup_ram.h" extern ioportid_t PORTS[]; #if defined(STM32F4XX) || defined(STM32F7XX) ioportid_t PORTS[] = { GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG, GPIOH }; @@ -134,44 +134,14 @@ int getAdcChannelPin(adc_channel_e hwChannel) { return getHwPin("get_pin", brainPin); } -#if HAL_USE_SERIAL_USB -extern SerialUSBDriver SDU1; -#endif /* HAL_USE_SERIAL_USB */ - -void jump_to_bootloader() { - // AN2606 Application note - // STM32 microcontroller system memory boot mode - - // todo: this does not work yet - - // Switch to the HSI clock source - no PLL - RCC->CR &= RCC_CR_HSITRIM | RCC_CR_HSION; /* CR Reset value. */ - RCC->CFGR = 0; /* CFGR reset value. */ - -#if HAL_USE_SERIAL_USB - usbDisconnectBus(&USBD1); - chThdSleepMilliseconds(1500); - - sdStop (&USB_SERIAL_DRIVER); - sduStop (&SDU1); - usbStop (&USBD1); -#endif /* HAL_USE_SERIAL_USB */ - __disable_irq(); - chSysDisable(); - // reset the Systick Timer - SysTick->CTRL = SysTick->LOAD = SysTick->VAL = 0; - SYSCFG->MEMRMP = 0x01; - SCB->VTOR = 0; - SCB->ICSR = (0x1U << 27); //ICSR_PENDSVCLR; - - - // set the main stack pointer to its default value - __set_MSP(0x20001000); - - void (*SysMemBootJump)(void); - SysMemBootJump = (void (*)(void)) (*((uint32_t *) 0x1FFF0004)); - - SysMemBootJump(); -} - #endif /* HAL_USE_ADC */ + + +#if EFI_PROD_CODE +void jump_to_bootloader() { + // leave DFU breadcrumb which assmebly startup code would check, see [rusefi][DFU] section in assembly code + *((unsigned long *)0x2001FFF0) = 0xDEADBEEF; // End of RAM + // and now reboot + NVIC_SystemReset(); +} +#endif /* EFI_PROD_CODE */ diff --git a/firmware/hw_layer/ports/stm32/stm32f4/hw_ports.mk b/firmware/hw_layer/ports/stm32/stm32f4/hw_ports.mk index 1dc371ab53..bde8506727 100644 --- a/firmware/hw_layer/ports/stm32/stm32f4/hw_ports.mk +++ b/firmware/hw_layer/ports/stm32/stm32f4/hw_ports.mk @@ -5,4 +5,5 @@ HW_LAYER_EMS += $(PROJECT_DIR)/hw_layer/ports/stm32/flash.c \ HW_LAYER_EMS_CPP += $(PROJECT_DIR)/hw_layer/ports/stm32/stm32f4/mpu_util.cpp \ $(PROJECT_DIR)/hw_layer/ports/stm32/stm32_pins.cpp \ $(PROJECT_DIR)/hw_layer/ports/stm32/stm32_common.cpp - \ No newline at end of file + +RUSEFIASM = $(PROJECT_DIR)/hw_layer/ports/stm32/rusEfiStartup.S diff --git a/firmware/hw_layer/ports/stm32/stm32f7/hw_ports.mk b/firmware/hw_layer/ports/stm32/stm32f7/hw_ports.mk index 31c5f29db8..5b27b96faa 100644 --- a/firmware/hw_layer/ports/stm32/stm32f7/hw_ports.mk +++ b/firmware/hw_layer/ports/stm32/stm32f7/hw_ports.mk @@ -5,4 +5,6 @@ HW_LAYER_EMS += $(PROJECT_DIR)/hw_layer/ports/stm32/flash.c \ HW_LAYER_EMS_CPP += $(PROJECT_DIR)/hw_layer/ports/stm32/stm32f7/mpu_util.cpp \ $(PROJECT_DIR)/hw_layer/ports/stm32/stm32_pins.cpp \ $(PROJECT_DIR)/hw_layer/ports/stm32/stm32_common.cpp + +RUSEFIASM = $(PROJECT_DIR)/hw_layer/ports/stm32/rusEfiStartup.S \ No newline at end of file diff --git a/firmware/svnversion.h b/firmware/svnversion.h index cc17aec754..017b3fc25d 100644 --- a/firmware/svnversion.h +++ b/firmware/svnversion.h @@ -1,12 +1,12 @@ // This file was generated by Version2Header -// Sat Jul 06 19:47:46 EDT 2019 +// Sun Jul 28 12:21:48 EDT 2019 #ifndef GIT_HASH -#define GIT_HASH "550ba208eb9da3a42cf881cba125f26a390cf162" +#define GIT_HASH "339603229e48bd6b1290a5d148ddf597eb2fd2eb" #endif #ifndef VCS_VERSION -#define VCS_VERSION "19465" +#define VCS_VERSION "19612" #endif