diff --git a/firmware/bootloader/readme.txt b/firmware/bootloader/readme.txt index ba384ca7a7..e9e66d9555 100644 --- a/firmware/bootloader/readme.txt +++ b/firmware/bootloader/readme.txt @@ -41,5 +41,5 @@ The bootloader executable works as follows: - Init ChibiOS and UART/Serial driver using tunerstudio_io code; - Create a thread to listen to UART (thBootloaderSerial), using dfuStartLoop(); - The PC 'stm32-flasher' software sends its request byte only once, so we don't wait for it - the bootloader sends an answer as soon as it starts (both the request & answer bytes are known consts); -- Ff the next command doesn't come immediately (<100 ms), we abort the bootloader dfu loop and run the application code - calling dfuJumpToApp() in main(). +- If the next command doesn't come immediately (<100 ms), we abort the bootloader dfu loop and run the application code - calling dfuJumpToApp() in main(). - Otherwise, if at least one command is received, we stay in the bootloader mode and process commands. diff --git a/firmware/bootloader/src/dfu.cpp b/firmware/bootloader/src/dfu.cpp index a79a8b5f33..2e55c78af2 100644 --- a/firmware/bootloader/src/dfu.cpp +++ b/firmware/bootloader/src/dfu.cpp @@ -129,7 +129,7 @@ bool dfuStartLoop(void) { break; } - // check if we have a correct command recieved + // check if we have a correct command received if (complement != complementByte(command)) { sendByte(DFU_NACK_BYTE); continue; @@ -141,7 +141,7 @@ bool dfuStartLoop(void) { // set normal (longer) timeout, we're not in a hurry anymore sr5Timeout = DFU_SR5_TIMEOUT_NORMAL; - // now execute it + // now execute it (see ST appnote "AN3155") switch (command) { case DFU_UART_CHECK: break; @@ -187,7 +187,7 @@ bool dfuStartLoop(void) { break; if (!getByte(&complement)) break; - // check if we have a correct byte recieved + // check if we have a correct byte received if (complement != complementByte(byte)) { sendByte(DFU_NACK_BYTE); break; diff --git a/firmware/bootloader/src/dfu.h b/firmware/bootloader/src/dfu.h index fb0fa884f6..9028bc0901 100644 --- a/firmware/bootloader/src/dfu.h +++ b/firmware/bootloader/src/dfu.h @@ -13,6 +13,10 @@ #define DFU_BUFFER_SIZE 258 // Max. 256 bytes at a time plus 2 bytes (numBytes+checksum) + +// DFU/USART Protocol is described in AN3155 document "Application note. USART protocol used in the STM32 bootloader" +// http://www.st.com/resource/en/application_note/cd00264342.pdf + #define DFU_UART_CHECK 0x7F // "UART handshake" escape byte #define DFU_GET_LIST_CMD 0x00 // "Get supported commands list" command diff --git a/firmware/controllers/electronic_throttle.cpp b/firmware/controllers/electronic_throttle.cpp index a173ffb0a8..6975bc48a7 100644 --- a/firmware/controllers/electronic_throttle.cpp +++ b/firmware/controllers/electronic_throttle.cpp @@ -184,6 +184,16 @@ void setDefaultEtbParameters(void) { engineConfiguration->etbFreq = 300; } +bool isETBRestartNeeded(void) { + /** + * We do not want any interruption in HW pin while adjusting other properties + */ + return engineConfiguration->bc.etbControlPin1 != activeConfiguration.bc.etbControlPin1 || + engineConfiguration->bc.etbControlPin2 != activeConfiguration.bc.etbControlPin2 || + engineConfiguration->bc.etbDirectionPin1 != activeConfiguration.bc.etbDirectionPin1 || + engineConfiguration->bc.etbDirectionPin2 != activeConfiguration.bc.etbDirectionPin2; +} + void stopETBPins(void) { unmarkPin(activeConfiguration.bc.etbControlPin1); unmarkPin(activeConfiguration.bc.etbControlPin2); diff --git a/firmware/controllers/electronic_throttle.h b/firmware/controllers/electronic_throttle.h index 3605929ca3..666be69cde 100644 --- a/firmware/controllers/electronic_throttle.h +++ b/firmware/controllers/electronic_throttle.h @@ -13,6 +13,7 @@ void initElectronicThrottle(void); void setDefaultEtbParameters(void); void setEtbPFactor(float value); void setEtbIFactor(float value); +bool isETBRestartNeeded(void); void stopETBPins(void); void startETBPins(void); void onConfigurationChangeElectronicThrottleCallback(engine_configuration_s *previousConfiguration); diff --git a/firmware/controllers/system/pwm_generator_logic.cpp b/firmware/controllers/system/pwm_generator_logic.cpp index 9b1a9e3c09..582cd9dd86 100644 --- a/firmware/controllers/system/pwm_generator_logic.cpp +++ b/firmware/controllers/system/pwm_generator_logic.cpp @@ -123,7 +123,7 @@ static efitimeus_t togglePwmState(PwmConfig *state) { efitimeus_t nextSwitchTimeUs = getNextSwitchTimeUs(state); #if DEBUG_PWM scheduleMsg(&logger, "%s: nextSwitchTime %d", state->name, nextSwitchTime); -#endif +#endif /* DEBUG_PWM */ // signed value is needed here // int64_t timeToSwitch = nextSwitchTimeUs - getTimeNowUs(); // if (timeToSwitch < 1) { diff --git a/firmware/hw_layer/hardware.cpp b/firmware/hw_layer/hardware.cpp index 719c07e14c..7f46721897 100644 --- a/firmware/hw_layer/hardware.cpp +++ b/firmware/hw_layer/hardware.cpp @@ -234,7 +234,10 @@ void applyNewHardwareSettings(void) { stopInjectionPins(); stopIgnitionPins(); stopCanPins(); - stopETBPins(); + bool etbRestartNeeded = isETBRestartNeeded(); + if (etbRestartNeeded) { + stopETBPins(); + } stopVSSPins(); stopAuxPins(); @@ -293,7 +296,9 @@ void applyNewHardwareSettings(void) { startInjectionPins(); startIgnitionPins(); startCanPins(); - startETBPins(); + if (etbRestartNeeded) { + startETBPins(); + } startVSSPins(); startAuxPins();