Added link to the DFU protocol appnote
This commit is contained in:
commit
0b13607efd
|
@ -41,5 +41,5 @@ The bootloader executable works as follows:
|
||||||
- Init ChibiOS and UART/Serial driver using tunerstudio_io code;
|
- Init ChibiOS and UART/Serial driver using tunerstudio_io code;
|
||||||
- Create a thread to listen to UART (thBootloaderSerial), using dfuStartLoop();
|
- 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);
|
- 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.
|
- Otherwise, if at least one command is received, we stay in the bootloader mode and process commands.
|
||||||
|
|
|
@ -129,7 +129,7 @@ bool dfuStartLoop(void) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if we have a correct command recieved
|
// check if we have a correct command received
|
||||||
if (complement != complementByte(command)) {
|
if (complement != complementByte(command)) {
|
||||||
sendByte(DFU_NACK_BYTE);
|
sendByte(DFU_NACK_BYTE);
|
||||||
continue;
|
continue;
|
||||||
|
@ -141,7 +141,7 @@ bool dfuStartLoop(void) {
|
||||||
// set normal (longer) timeout, we're not in a hurry anymore
|
// set normal (longer) timeout, we're not in a hurry anymore
|
||||||
sr5Timeout = DFU_SR5_TIMEOUT_NORMAL;
|
sr5Timeout = DFU_SR5_TIMEOUT_NORMAL;
|
||||||
|
|
||||||
// now execute it
|
// now execute it (see ST appnote "AN3155")
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case DFU_UART_CHECK:
|
case DFU_UART_CHECK:
|
||||||
break;
|
break;
|
||||||
|
@ -187,7 +187,7 @@ bool dfuStartLoop(void) {
|
||||||
break;
|
break;
|
||||||
if (!getByte(&complement))
|
if (!getByte(&complement))
|
||||||
break;
|
break;
|
||||||
// check if we have a correct byte recieved
|
// check if we have a correct byte received
|
||||||
if (complement != complementByte(byte)) {
|
if (complement != complementByte(byte)) {
|
||||||
sendByte(DFU_NACK_BYTE);
|
sendByte(DFU_NACK_BYTE);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -13,6 +13,10 @@
|
||||||
|
|
||||||
#define DFU_BUFFER_SIZE 258 // Max. 256 bytes at a time plus 2 bytes (numBytes+checksum)
|
#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_UART_CHECK 0x7F // "UART handshake" escape byte
|
||||||
|
|
||||||
#define DFU_GET_LIST_CMD 0x00 // "Get supported commands list" command
|
#define DFU_GET_LIST_CMD 0x00 // "Get supported commands list" command
|
||||||
|
|
|
@ -184,6 +184,16 @@ void setDefaultEtbParameters(void) {
|
||||||
engineConfiguration->etbFreq = 300;
|
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) {
|
void stopETBPins(void) {
|
||||||
unmarkPin(activeConfiguration.bc.etbControlPin1);
|
unmarkPin(activeConfiguration.bc.etbControlPin1);
|
||||||
unmarkPin(activeConfiguration.bc.etbControlPin2);
|
unmarkPin(activeConfiguration.bc.etbControlPin2);
|
||||||
|
|
|
@ -13,6 +13,7 @@ void initElectronicThrottle(void);
|
||||||
void setDefaultEtbParameters(void);
|
void setDefaultEtbParameters(void);
|
||||||
void setEtbPFactor(float value);
|
void setEtbPFactor(float value);
|
||||||
void setEtbIFactor(float value);
|
void setEtbIFactor(float value);
|
||||||
|
bool isETBRestartNeeded(void);
|
||||||
void stopETBPins(void);
|
void stopETBPins(void);
|
||||||
void startETBPins(void);
|
void startETBPins(void);
|
||||||
void onConfigurationChangeElectronicThrottleCallback(engine_configuration_s *previousConfiguration);
|
void onConfigurationChangeElectronicThrottleCallback(engine_configuration_s *previousConfiguration);
|
||||||
|
|
|
@ -123,7 +123,7 @@ static efitimeus_t togglePwmState(PwmConfig *state) {
|
||||||
efitimeus_t nextSwitchTimeUs = getNextSwitchTimeUs(state);
|
efitimeus_t nextSwitchTimeUs = getNextSwitchTimeUs(state);
|
||||||
#if DEBUG_PWM
|
#if DEBUG_PWM
|
||||||
scheduleMsg(&logger, "%s: nextSwitchTime %d", state->name, nextSwitchTime);
|
scheduleMsg(&logger, "%s: nextSwitchTime %d", state->name, nextSwitchTime);
|
||||||
#endif
|
#endif /* DEBUG_PWM */
|
||||||
// signed value is needed here
|
// signed value is needed here
|
||||||
// int64_t timeToSwitch = nextSwitchTimeUs - getTimeNowUs();
|
// int64_t timeToSwitch = nextSwitchTimeUs - getTimeNowUs();
|
||||||
// if (timeToSwitch < 1) {
|
// if (timeToSwitch < 1) {
|
||||||
|
|
|
@ -234,7 +234,10 @@ void applyNewHardwareSettings(void) {
|
||||||
stopInjectionPins();
|
stopInjectionPins();
|
||||||
stopIgnitionPins();
|
stopIgnitionPins();
|
||||||
stopCanPins();
|
stopCanPins();
|
||||||
|
bool etbRestartNeeded = isETBRestartNeeded();
|
||||||
|
if (etbRestartNeeded) {
|
||||||
stopETBPins();
|
stopETBPins();
|
||||||
|
}
|
||||||
stopVSSPins();
|
stopVSSPins();
|
||||||
stopAuxPins();
|
stopAuxPins();
|
||||||
|
|
||||||
|
@ -293,7 +296,9 @@ void applyNewHardwareSettings(void) {
|
||||||
startInjectionPins();
|
startInjectionPins();
|
||||||
startIgnitionPins();
|
startIgnitionPins();
|
||||||
startCanPins();
|
startCanPins();
|
||||||
|
if (etbRestartNeeded) {
|
||||||
startETBPins();
|
startETBPins();
|
||||||
|
}
|
||||||
startVSSPins();
|
startVSSPins();
|
||||||
startAuxPins();
|
startAuxPins();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue