Skip to content

Commit

Permalink
Merge pull request #5 from Churrosoft/update/master/06-01-2025
Browse files Browse the repository at this point in the history
Update/master/06 01 2025
  • Loading branch information
FDSoftware authored Jan 7, 2025
2 parents f0ed966 + 3271a4e commit 02840d7
Show file tree
Hide file tree
Showing 14 changed files with 248 additions and 160 deletions.
285 changes: 179 additions & 106 deletions reference/speeduino.ini

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions speeduino/TS_CommandButtonHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "sensors.h"
#include "storage.h"
#include "SD_logger.h"
#include "pages.h"
#ifdef USE_MC33810
#include "acc_mc33810.h"
#endif
Expand Down Expand Up @@ -306,9 +307,9 @@ bool TS_CommandButtonsHandler(uint16_t buttonCommand)
{
if(configPage2.vssMode == 1)
{
//Calculate the ratio of VSS reading from Aux input and actual VSS (assuming that actual VSS is really 60km/h).
//Calculate the ratio of VSS reading from Aux/CAN input and actual VSS (assuming that actual VSS is really 60km/h).
configPage2.vssPulsesPerKm = (currentStatus.canin[configPage2.vssAuxCh] / 60);
writeConfig(1); // Need to manually save the new config value as it will not trigger a burn in tunerStudio due to use of ControllerPriority
writeConfig(veSetPage); // Need to manually save the new config value as it will not trigger a burn in tunerStudio due to use of ControllerPriority
BIT_SET(currentStatus.status3, BIT_STATUS3_VSS_REFRESH); //Set the flag to trigger the UI reset
}
else
Expand All @@ -318,7 +319,7 @@ bool TS_CommandButtonsHandler(uint16_t buttonCommand)
if( calibrationGap > 0 )
{
configPage2.vssPulsesPerKm = MICROS_PER_MIN / calibrationGap;
writeConfig(1); // Need to manually save the new config value as it will not trigger a burn in tunerStudio due to use of ControllerPriority
writeConfig(veSetPage); // Need to manually save the new config value as it will not trigger a burn in tunerStudio due to use of ControllerPriority
BIT_SET(currentStatus.status3, BIT_STATUS3_VSS_REFRESH); //Set the flag to trigger the UI reset
}
}
Expand Down
2 changes: 1 addition & 1 deletion speeduino/board_stm32_official.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ STM32RTC& rtc = STM32RTC::getInstance();
#if ( STM32_CORE_VERSION_MAJOR < 2 )
Timer5.setMode(2, TIMER_OUTPUT_COMPARE);
#else //2.0 forward
Timer5.setMode(1, TIMER_OUTPUT_COMPARE_TOGGLE);
Timer5.setMode(2, TIMER_OUTPUT_COMPARE_TOGGLE);
#endif
Timer5.attachInterrupt(2, fuelSchedule6Interrupt);
#endif
Expand Down
47 changes: 22 additions & 25 deletions speeduino/board_stm32_official.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,13 @@ void jumpToBootloader();
* Schedules
* Timers Table for STM32F4
* TIMER1 | TIMER2 | TIMER3 | TIMER4 | TIMER5 | TIMER11
* 1 - FAN |1 - INJ1 |1 - IGN1 |1 - IGN5 |1 - INJ5 |1 - oneMSInterval
* 2 - BOOST |2 - INJ2 |2 - IGN2 |2 - IGN6 |2 - INJ6 |
* 3 - VVT |3 - INJ3 |3 - IGN3 |3 - IGN7 |3 - INJ7 |
* 4 - IDLE |4 - INJ4 |4 - IGN4 |4 - IGN8 |4 - INJ8 |
* 1 - FAN |1 - IGN1 |1 - INJ1 |1 - IGN5 |1 - INJ5 |1 - oneMSInterval
* 2 - BOOST |2 - IGN2 |2 - INJ2 |2 - IGN6 |2 - INJ6 |
* 3 - VVT |3 - IGN3 |3 - INJ3 |3 - IGN7 |3 - INJ7 |
* 4 - IDLE |4 - IGN4 |4 - INJ4 |4 - IGN8 |4 - INJ8 |
*/
#define MAX_TIMER_PERIOD 65535*4 //The longest period of time (in uS) that the timer can permit (IN this case it is 65535 * 4, as each timer tick is 4uS)
#define uS_TO_TIMER_COMPARE(uS) (uS>>2) //Converts a given number of uS into the required number of timer ticks until that time has passed.
#define MAX_TIMER_PERIOD 262140UL //The longest period of time (in uS) that the timer can permit (IN this case it is 65535 * 4, as each timer tick is 4uS)
#define uS_TO_TIMER_COMPARE(uS1) ((uS1) >> 2) //Converts a given number of uS into the required number of timer ticks until that time has passed

#define FUEL1_COUNTER (TIM3)->CNT
#define FUEL2_COUNTER (TIM3)->CNT
Expand Down Expand Up @@ -239,16 +239,15 @@ static inline void FUEL2_TIMER_DISABLE(void) {(TIM3)->DIER &= ~TIM_DIER_CC2IE;}
static inline void FUEL3_TIMER_DISABLE(void) {(TIM3)->DIER &= ~TIM_DIER_CC3IE;}
static inline void FUEL4_TIMER_DISABLE(void) {(TIM3)->DIER &= ~TIM_DIER_CC4IE;}

static inline void IGN1_TIMER_ENABLE(void) {(TIM2)->CR1 |= TIM_CR1_CEN; (TIM2)->SR = ~TIM_FLAG_CC1; (TIM2)->DIER |= TIM_DIER_CC1IE;}
static inline void IGN2_TIMER_ENABLE(void) {(TIM2)->CR1 |= TIM_CR1_CEN; (TIM2)->SR = ~TIM_FLAG_CC2; (TIM2)->DIER |= TIM_DIER_CC2IE;}
static inline void IGN3_TIMER_ENABLE(void) {(TIM2)->CR1 |= TIM_CR1_CEN; (TIM2)->SR = ~TIM_FLAG_CC3; (TIM2)->DIER |= TIM_DIER_CC3IE;}
static inline void IGN4_TIMER_ENABLE(void) {(TIM2)->CR1 |= TIM_CR1_CEN; (TIM2)->SR = ~TIM_FLAG_CC4; (TIM2)->DIER |= TIM_DIER_CC4IE;}

static inline void IGN1_TIMER_DISABLE(void) {(TIM2)->DIER &= ~TIM_DIER_CC1IE;}
static inline void IGN2_TIMER_DISABLE(void) {(TIM2)->DIER &= ~TIM_DIER_CC2IE;}
static inline void IGN3_TIMER_DISABLE(void) {(TIM2)->DIER &= ~TIM_DIER_CC3IE;}
static inline void IGN4_TIMER_DISABLE(void) {(TIM2)->DIER &= ~TIM_DIER_CC4IE;}
static inline void IGN1_TIMER_ENABLE(void) {(TIM2)->CR1 |= TIM_CR1_CEN; (TIM2)->SR = ~TIM_FLAG_CC1; (TIM2)->DIER |= TIM_DIER_CC1IE;}
static inline void IGN2_TIMER_ENABLE(void) {(TIM2)->CR1 |= TIM_CR1_CEN; (TIM2)->SR = ~TIM_FLAG_CC2; (TIM2)->DIER |= TIM_DIER_CC2IE;}
static inline void IGN3_TIMER_ENABLE(void) {(TIM2)->CR1 |= TIM_CR1_CEN; (TIM2)->SR = ~TIM_FLAG_CC3; (TIM2)->DIER |= TIM_DIER_CC3IE;}
static inline void IGN4_TIMER_ENABLE(void) {(TIM2)->CR1 |= TIM_CR1_CEN; (TIM2)->SR = ~TIM_FLAG_CC4; (TIM2)->DIER |= TIM_DIER_CC4IE;}

static inline void IGN1_TIMER_DISABLE(void) {(TIM2)->DIER &= ~TIM_DIER_CC1IE;}
static inline void IGN2_TIMER_DISABLE(void) {(TIM2)->DIER &= ~TIM_DIER_CC2IE;}
static inline void IGN3_TIMER_DISABLE(void) {(TIM2)->DIER &= ~TIM_DIER_CC3IE;}
static inline void IGN4_TIMER_DISABLE(void) {(TIM2)->DIER &= ~TIM_DIER_CC4IE;}

static inline void FUEL5_TIMER_ENABLE(void) {(TIM5)->CR1 |= TIM_CR1_CEN; (TIM5)->CR1 |= TIM_CR1_CEN; (TIM5)->SR = ~TIM_FLAG_CC1; (TIM5)->DIER |= TIM_DIER_CC1IE;}
static inline void FUEL6_TIMER_ENABLE(void) {(TIM5)->CR1 |= TIM_CR1_CEN; (TIM5)->CR1 |= TIM_CR1_CEN; (TIM5)->SR = ~TIM_FLAG_CC2; (TIM5)->DIER |= TIM_DIER_CC2IE;}
Expand All @@ -260,17 +259,15 @@ static inline void FUEL6_TIMER_DISABLE(void) {(TIM5)->DIER &= ~TIM_DIER_CC2IE;}
static inline void FUEL7_TIMER_DISABLE(void) {(TIM5)->DIER &= ~TIM_DIER_CC3IE;}
static inline void FUEL8_TIMER_DISABLE(void) {(TIM5)->DIER &= ~TIM_DIER_CC4IE;}

static inline void IGN5_TIMER_ENABLE(void) {(TIM4)->CR1 |= TIM_CR1_CEN; (TIM4)->SR = ~TIM_FLAG_CC1; (TIM4)->DIER |= TIM_DIER_CC1IE;}
static inline void IGN6_TIMER_ENABLE(void) {(TIM4)->CR1 |= TIM_CR1_CEN; (TIM4)->SR = ~TIM_FLAG_CC2; (TIM4)->DIER |= TIM_DIER_CC2IE;}
static inline void IGN7_TIMER_ENABLE(void) {(TIM4)->CR1 |= TIM_CR1_CEN; (TIM4)->SR = ~TIM_FLAG_CC3; (TIM4)->DIER |= TIM_DIER_CC3IE;}
static inline void IGN8_TIMER_ENABLE(void) {(TIM4)->CR1 |= TIM_CR1_CEN; (TIM4)->SR = ~TIM_FLAG_CC4; (TIM4)->DIER |= TIM_DIER_CC4IE;}

static inline void IGN5_TIMER_DISABLE(void) {(TIM4)->DIER &= ~TIM_DIER_CC1IE;}
static inline void IGN6_TIMER_DISABLE(void) {(TIM4)->DIER &= ~TIM_DIER_CC2IE;}
static inline void IGN7_TIMER_DISABLE(void) {(TIM4)->DIER &= ~TIM_DIER_CC3IE;}
static inline void IGN8_TIMER_DISABLE(void) {(TIM4)->DIER &= ~TIM_DIER_CC4IE;}
static inline void IGN5_TIMER_ENABLE(void) {(TIM4)->CR1 |= TIM_CR1_CEN; (TIM4)->SR = ~TIM_FLAG_CC1; (TIM4)->DIER |= TIM_DIER_CC1IE;}
static inline void IGN6_TIMER_ENABLE(void) {(TIM4)->CR1 |= TIM_CR1_CEN; (TIM4)->SR = ~TIM_FLAG_CC2; (TIM4)->DIER |= TIM_DIER_CC2IE;}
static inline void IGN7_TIMER_ENABLE(void) {(TIM4)->CR1 |= TIM_CR1_CEN; (TIM4)->SR = ~TIM_FLAG_CC3; (TIM4)->DIER |= TIM_DIER_CC3IE;}
static inline void IGN8_TIMER_ENABLE(void) {(TIM4)->CR1 |= TIM_CR1_CEN; (TIM4)->SR = ~TIM_FLAG_CC4; (TIM4)->DIER |= TIM_DIER_CC4IE;}


static inline void IGN5_TIMER_DISABLE(void) {(TIM4)->DIER &= ~TIM_DIER_CC1IE;}
static inline void IGN6_TIMER_DISABLE(void) {(TIM4)->DIER &= ~TIM_DIER_CC2IE;}
static inline void IGN7_TIMER_DISABLE(void) {(TIM4)->DIER &= ~TIM_DIER_CC3IE;}
static inline void IGN8_TIMER_DISABLE(void) {(TIM4)->DIER &= ~TIM_DIER_CC4IE;}


/*
Expand Down
16 changes: 16 additions & 0 deletions speeduino/board_teensy41.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,4 +326,20 @@ void setTriggerHysteresis()
*(p->mux) = 5 | 0x10;
}

/*
* The default Teensy41 serial.begin() has a timeout of 750ms, which is both too long to wait on startup and longer than it needs to be
* This function is a copy of the default serial.begin() but with the timeout lowered to 100ms
*/
void teensy41_customSerialBegin()
{
uint32_t millis_begin = systick_millis_count;
while (!Serial)
{
uint32_t elapsed = systick_millis_count - millis_begin;
//Wait up to 100ms for this.
if (elapsed > 100) break;
yield();
}
}

#endif
1 change: 1 addition & 0 deletions speeduino/board_teensy41.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
void doSystemReset();
void jumpToBootloader();
void setTriggerHysteresis();
void teensy41_customSerialBegin();
time_t getTeensy3Time();
#define PORT_TYPE uint32_t //Size of the port variables
#define PINMASK_TYPE uint32_t
Expand Down
8 changes: 4 additions & 4 deletions speeduino/comms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ static constexpr uint8_t SEND_OUTPUT_CHANNELS = 48U; //!< Code for the "send out
/// @{
static constexpr byte serialVersion[] PROGMEM = {SERIAL_RC_OK, '0', '0', '2'};
static constexpr byte canId[] PROGMEM = {SERIAL_RC_OK, 0};
static constexpr byte codeVersion[] PROGMEM = { SERIAL_RC_OK, 's','p','e','e','d','u','i','n','o',' ','2','0','2','4','0','5','-','d','e','v'} ; //Note no null terminator in array and status variable at the start
static constexpr byte productString[] PROGMEM = { SERIAL_RC_OK, 'S', 'p', 'e', 'e', 'd', 'u', 'i', 'n', 'o', ' ', '2', '0', '2', '4', '.', '0', '5', '-', 'd', 'e', 'v'};
//static constexpr byte codeVersion[] PROGMEM = { SERIAL_RC_OK, 's','p','e','e','d','u','i','n','o',' ','2','0','2','4','0','2'} ; //Note no null terminator in array and status variable at the start
//static constexpr byte productString[] PROGMEM = { SERIAL_RC_OK, 'S', 'p', 'e', 'e', 'd', 'u', 'i', 'n', 'o', ' ', '2', '0', '2', '4', '.', '0', '2'};
//static constexpr byte codeVersion[] PROGMEM = { SERIAL_RC_OK, 's','p','e','e','d','u','i','n','o',' ','2','0','2','4','0','5','-','d','e','v'} ; //Note no null terminator in array and status variable at the start
//static constexpr byte productString[] PROGMEM = { SERIAL_RC_OK, 'S', 'p', 'e', 'e', 'd', 'u', 'i', 'n', 'o', ' ', '2', '0', '2', '4', '.', '0', '5', '-', 'd', 'e', 'v'};
static constexpr byte codeVersion[] PROGMEM = { SERIAL_RC_OK, 's','p','e','e','d','u','i','n','o',' ','2','0','2','5','0','1'} ; //Note no null terminator in array and status variable at the start
static constexpr byte productString[] PROGMEM = { SERIAL_RC_OK, 'S', 'p', 'e', 'e', 'd', 'u', 'i', 'n', 'o', ' ', '2', '0', '2', '5', '.', '0', '1'};
static constexpr byte testCommsResponse[] PROGMEM = { SERIAL_RC_OK, 255 };
/// @}

Expand Down
5 changes: 2 additions & 3 deletions speeduino/comms_legacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,7 @@ void legacySerialHandler(byte cmd, Stream &targetPort, SerialStatus &targetStatu
break;

case 'Q': // send code version
//targetPort.print(F("speeduino 202402"));
targetPort.print(F("speeduino 202405-dev"));
targetPort.print(F("speeduino 202501"));
break;

case 'r': //New format for the optimised OutputChannels
Expand Down Expand Up @@ -676,7 +675,7 @@ void legacySerialHandler(byte cmd, Stream &targetPort, SerialStatus &targetStatu
break;

case 'S': // send code version
targetPort.print(F("Speeduino 2024.05-dev"));
targetPort.print(F("Speeduino 2025.01"));
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion speeduino/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ struct config6 {
byte iacFastTemp; //Fast idle temp when using a simple on/off valve

byte iacStepHome; //When using a stepper motor, the number of steps to be taken on startup to home the motor
byte iacStepHyster; //Hysteresis temperature (*10). Eg 2.2C = 22
byte iacStepHyster; //Number of hysteresis steps

byte fanInv : 1; // Fan output inversion bit
byte fanUnused : 1;
Expand Down
4 changes: 2 additions & 2 deletions speeduino/idle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ static inline byte checkForStepping(void)
idleStepper.stepperStatus = SOFF;
if(configPage9.iacStepperPower == STEPPER_POWER_WHEN_ACTIVE)
{
//Disable the DRV8825, but only if we're at the final step in this cycle.
if ( (idleStepper.targetIdleStep > (idleStepper.curIdleStep - configPage6.iacStepHyster)) && (idleStepper.targetIdleStep < (idleStepper.curIdleStep + configPage6.iacStepHyster)) ) //Hysteresis check
//Disable the DRV8825, but only if we're at the final step in this cycle or within the hysteresis range.
if ( (idleStepper.curIdleStep >= (idleStepper.targetIdleStep - configPage6.iacStepHyster)) && (idleStepper.curIdleStep <= (idleStepper.targetIdleStep + configPage6.iacStepHyster))) //Hysteresis check
{
digitalWrite(pinStepperEnable, HIGH);
}
Expand Down
2 changes: 2 additions & 0 deletions speeduino/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ void initialiseAll(void)
//Teensy 4.1 does not require .begin() to be called. This introduces a 700ms delay on startup time whilst USB is enumerated if it is called
#ifndef CORE_TEENSY41
Serial.begin(115200);
#else
teensy41_customSerialBegin();
#endif
pPrimarySerial = &Serial; //Default to standard Serial interface
BIT_SET(currentStatus.status4, BIT_STATUS4_ALLOW_LEGACY_COMMS); //Flag legacy comms as being allowed on startup
Expand Down
3 changes: 2 additions & 1 deletion speeduino/schedule_calcs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ static inline uint32_t calculateInjectorTimeout(const FuelSchedule &schedule, in
uint32_t tempTimeout = 0;
int16_t delta = openAngle - crankAngle;

if ( (schedule.Status == RUNNING) || (schedule.Status == OFF))
if(delta > 0) { tempTimeout = angleToTimeMicroSecPerDegree((uint16_t)delta); }
else if ( (schedule.Status == RUNNING) || (schedule.Status == OFF))
{
while(delta < 0) { delta += CRANK_ANGLE_MAX_INJ; }
tempTimeout = angleToTimeMicroSecPerDegree((uint16_t)delta);
Expand Down
24 changes: 11 additions & 13 deletions speeduino/speeduino.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1701,21 +1701,19 @@ void checkLaunchAndFlatShift()

if (configPage6.launchEnabled && currentStatus.clutchTrigger && (currentStatus.clutchEngagedRPM < ((unsigned int)(configPage6.flatSArm) * 100)) && (currentStatus.TPS >= configPage10.lnchCtrlTPS) )
{
//If VSS is used, make sure we're not above the speed limit
if ( (configPage2.vssMode > 0) && (currentStatus.vss >= configPage10.lnchCtrlVss) )
//Only enable if VSS is not used or if it is, make sure we're not above the speed limit
if( (configPage2.vssMode == 0) || ((configPage2.vssMode > 0) && (currentStatus.vss < configPage10.lnchCtrlVss)) )
{
return;
}

//Check whether RPM is above the launch limit
uint16_t launchRPMLimit = (configPage6.lnchHardLim * 100);
if( (configPage2.hardCutType == HARD_CUT_ROLLING) ) { launchRPMLimit += (configPage15.rollingProtRPMDelta[0] * 10); } //Add the rolling cut delta if enabled (Delta is a negative value)
//Check whether RPM is above the launch limit
uint16_t launchRPMLimit = (configPage6.lnchHardLim * 100);
if( (configPage2.hardCutType == HARD_CUT_ROLLING) ) { launchRPMLimit += (configPage15.rollingProtRPMDelta[0] * 10); } //Add the rolling cut delta if enabled (Delta is a negative value)

if(currentStatus.RPM > launchRPMLimit)
{
//HardCut rev limit for 2-step launch control.
currentStatus.launchingHard = true;
BIT_SET(currentStatus.status2, BIT_STATUS2_HLAUNCH);
if(currentStatus.RPM > launchRPMLimit)
{
//HardCut rev limit for 2-step launch control.
currentStatus.launchingHard = true;
BIT_SET(currentStatus.status2, BIT_STATUS2_HLAUNCH);
}
}
}
else
Expand Down
2 changes: 1 addition & 1 deletion speeduino/updates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ void doUpdates(void)

if(readEEPROMVersion() == 23)
{
//202405
//202501
configPage10.knock_mode = KNOCK_MODE_OFF;

//Change the CAN Broadcast settings to be a selection
Expand Down

0 comments on commit 02840d7

Please sign in to comment.