diff --git a/speeduino/auxiliaries.h b/speeduino/auxiliaries.h index c3d582b8..1aae707d 100644 --- a/speeduino/auxiliaries.h +++ b/speeduino/auxiliaries.h @@ -25,17 +25,17 @@ void fanControl(); #define READ_N2O_ARM_PIN() ((*n2o_arming_pin_port & n2o_arming_pin_mask) ? true : false) volatile PORT_TYPE *boost_pin_port; -volatile byte boost_pin_mask; +volatile PINMAKS_TYPE boost_pin_mask; volatile PORT_TYPE *vvt_pin_port; -volatile byte vvt_pin_mask; +volatile PINMAKS_TYPE vvt_pin_mask; volatile PORT_TYPE *fan_pin_port; -volatile byte fan_pin_mask; +volatile PINMAKS_TYPE fan_pin_mask; volatile PORT_TYPE *n2o_stage1_pin_port; -volatile byte n2o_stage1_pin_mask; +volatile PINMAKS_TYPE n2o_stage1_pin_mask; volatile PORT_TYPE *n2o_stage2_pin_port; -volatile byte n2o_stage2_pin_mask; +volatile PINMAKS_TYPE n2o_stage2_pin_mask; volatile PORT_TYPE *n2o_arming_pin_port; -volatile byte n2o_arming_pin_mask; +volatile PINMAKS_TYPE n2o_arming_pin_mask; volatile bool boost_pwm_state; unsigned int boost_pwm_max_count; //Used for variable PWM frequency diff --git a/speeduino/board_stm32.h b/speeduino/board_stm32.h index 81835bca..937aa21d 100644 --- a/speeduino/board_stm32.h +++ b/speeduino/board_stm32.h @@ -1,21 +1,29 @@ #ifndef STM32_H #define STM32_H #if defined(CORE_STM32) +#include /* *********************************************************************************************************** * General */ - #define PORT_TYPE uint8_t + #define PORT_TYPE uint32_t + #define PINMAKS_TYPE uint32_t #define micros_safe() micros() //timer5 method is not used on anything but AVR, the micros_safe() macro is simply an alias for the normal micros() + #ifndef USE_SERIAL3 #define USE_SERIAL3 + #endif void initBoard(); uint16_t freeRam(); - #if defined(USE_STM32GENERIC) + #ifndef Serial #define Serial Serial1 #endif + #if defined(ARDUINO_BLACK_F407VE) || defined(STM32F4) || defined(_STM32F4_) + FramClass EEPROM(PB0, PB3, PB4, PB5, 15000000); + #endif + //Much of the below is not correct, but included to allow compilation //STM32F1/variants/.../board.cpp #if defined (STM32F4) @@ -59,12 +67,26 @@ /* *********************************************************************************************************** * Schedules +* Timers Table for STM32F1 +* TIMER1 TIMER2 TIMER3 TIMER4 +* 1 - 1 - INJ1 1 - IGN1 1 - oneMSInterval +* 2 - BOOST 2 - INJ2 2 - IGN2 2 - +* 3 - VVT 3 - INJ3 3 - IGN3 3 - +* 4 - IDLE 4 - INJ4 4 - IGN4 4 - +* +* Timers Table for STM32F4 +* TIMER1 TIMER2 TIMER3 TIMER4 TIMER5 TIMER8 +* 1 - 1 - INJ1 1 - IGN1 1 - IGN5 1 - INJ5 1 - oneMSInterval +* 2 - BOOST 2 - INJ2 2 - IGN2 2 - IGN6 2 - INJ6 2 - +* 3 - VVT 3 - INJ3 3 - IGN3 3 - IGN7 3 - INJ7 3 - +* 4 - IDLE 4 - INJ4 4 - IGN4 4 - IGN8 4 - INJ8 4 - +* */ - #define MAX_TIMER_PERIOD 131070 //The longest period of time (in uS) that the timer can permit (IN this case it is 65535 * 2, as each timer tick is 2uS) - #define MAX_TIMER_PERIOD_SLOW 131070 //The longest period of time (in uS) that the timer can permit (IN this case it is 65535 * 2, as each timer tick is 2uS) + #define MAX_TIMER_PERIOD 65535*2 //The longest period of time (in uS) that the timer can permit (IN this case it is 65535 * 2, as each timer tick is 2uS) + #define MAX_TIMER_PERIOD_SLOW 65535*2 //The longest period of time (in uS) that the timer can permit (IN this case it is 65535 * 2, as each timer tick is 2uS) #define uS_TO_TIMER_COMPARE(uS) (uS >> 1) //Converts a given number of uS into the required number of timer ticks until that time has passed. #define uS_TO_TIMER_COMPARE_SLOW(uS) (uS >> 1) //Converts a given number of uS into the required number of timer ticks until that time has passed. - #if defined(ARDUINO_ARCH_STM32) // STM32GENERIC core + #if defined(ARDUINO_ARCH_STM32) && !defined(_VARIANT_ARDUINO_STM32_) // STM32GENERIC core #define FUEL1_COUNTER (TIM2)->CNT #define FUEL2_COUNTER (TIM2)->CNT #define FUEL3_COUNTER (TIM2)->CNT @@ -238,7 +260,7 @@ *********************************************************************************************************** * Auxilliaries */ - #if defined(ARDUINO_ARCH_STM32) // STM32GENERIC core + #if defined(ARDUINO_ARCH_STM32) && !defined(_VARIANT_ARDUINO_STM32_) // STM32GENERIC core #define ENABLE_BOOST_TIMER() (TIM1)->CCER |= TIM_CCER_CC2E #define DISABLE_BOOST_TIMER() (TIM1)->CCER &= ~TIM_CCER_CC2E @@ -266,7 +288,7 @@ *********************************************************************************************************** * Idle */ - #if defined(ARDUINO_ARCH_STM32) // STM32GENERIC core + #if defined(ARDUINO_ARCH_STM32) && !defined(_VARIANT_ARDUINO_STM32_) // STM32GENERIC core #define IDLE_COUNTER (TIM1)->CNT #define IDLE_COMPARE (TIM1)->CCR4 diff --git a/speeduino/board_stm32.ino b/speeduino/board_stm32.ino index 0b9242e5..c72de14d 100644 --- a/speeduino/board_stm32.ino +++ b/speeduino/board_stm32.ino @@ -5,8 +5,8 @@ #include "idle.h" #include "scheduler.h" #include "HardwareTimer.h" -#if defined(STM32F4) - //These should really be in the stm32GENERIC libs, but for somereason they only have timers 1-4 +#if defined(ARDUINO_ARCH_STM32) && defined(STM32_CORE_VERSION) + //These should really be in the stm32 libmaple libs, but for somereason they only have timers 1-4 #include HardwareTimer Timer5(TIM5, chip_tim5, sizeof(chip_tim5) / sizeof(chip_tim5[0])); HardwareTimer Timer8(TIM8, chip_tim8, sizeof(chip_tim8) / sizeof(chip_tim8[0])); @@ -18,9 +18,10 @@ void initBoard() *********************************************************************************************************** * General */ - #define FLASH_LENGTH 8192 - - + #ifndef FLASH_LENGTH + #define FLASH_LENGTH 8192 + #endif + delay(10); /* *********************************************************************************************************** * Idle @@ -33,8 +34,7 @@ void initBoard() //This must happen at the end of the idle init Timer1.setMode(4, TIMER_OUTPUT_COMPARE); //timer_set_mode(TIMER1, 4, TIMER_OUTPUT_COMPARE; - if(idle_pwm_max_count > 0) { Timer1.attachInterrupt(4, idleInterrupt);} //on first flash the configPage4.iacAlgorithm is invalid - Timer1.resume(); + if(idle_pwm_max_count > 0) { Timer1.attachInterrupt(4, idleInterrupt); } //on first flash the configPage4.iacAlgorithm is invalid /* @@ -67,32 +67,23 @@ void initBoard() Timer1.setMode(3, TIMER_OUTPUT_COMPARE); if(boost_pwm_max_count > 0) { Timer1.attachInterrupt(2, boostInterrupt);} if(vvt_pwm_max_count > 0) { Timer1.attachInterrupt(3, vvtInterrupt);} - Timer1.resume(); /* *********************************************************************************************************** * Schedules */ - #if defined(ARDUINO_ARCH_STM32) // STM32GENERIC core - //see https://github.com/rogerclarkmelbourne/Arduino_STM32/blob/754bc2969921f1ef262bd69e7faca80b19db7524/STM32F1/system/libmaple/include/libmaple/timer.h#L444 - Timer1.setPrescaleFactor((HAL_RCC_GetHCLKFreq() * 2U)-1); //2us resolution - Timer2.setPrescaleFactor((HAL_RCC_GetHCLKFreq() * 2U)-1); //2us resolution - Timer3.setPrescaleFactor((HAL_RCC_GetHCLKFreq() * 2U)-1); //2us resolution - #else //libmaple core aka STM32DUINO - //see https://github.com/rogerclarkmelbourne/Arduino_STM32/blob/754bc2969921f1ef262bd69e7faca80b19db7524/STM32F1/system/libmaple/include/libmaple/timer.h#L444 - #if defined (STM32F1) || defined(__STM32F1__) - //(CYCLES_PER_MICROSECOND == 72, APB2 at 72MHz, APB1 at 36MHz). - //Timer2 to 4 is on APB1, Timer1 on APB2. http://www.st.com/resource/en/datasheet/stm32f103cb.pdf sheet 12 - Timer1.setPrescaleFactor((72 * 2U)-1); //2us resolution - Timer2.setPrescaleFactor((36 * 2U)-1); //2us resolution - Timer3.setPrescaleFactor((36 * 2U)-1); //2us resolution - #elif defined(STM32F4) - //(CYCLES_PER_MICROSECOND == 168, APB2 at 84MHz, APB1 at 42MHz). - //Timer2 to 14 is on APB1, Timers 1, 8, 9 and 10 on APB2. http://www.st.com/resource/en/datasheet/stm32f407vg.pdf sheet 120 - Timer1.setPrescaleFactor((84 * 2U)-1); //2us resolution - Timer2.setPrescaleFactor((42 * 2U)-1); //2us resolution - Timer3.setPrescaleFactor((42 * 2U)-1); //2us resolution - #endif + #if defined (STM32F1) || defined(__STM32F1__) + //(CYCLES_PER_MICROSECOND == 72, APB2 at 72MHz, APB1 at 36MHz). + //Timer2 to 4 is on APB1, Timer1 on APB2. http://www.st.com/resource/en/datasheet/stm32f103cb.pdf sheet 12 + Timer1.setPrescaleFactor((72 * 2)-1); //2us resolution + Timer2.setPrescaleFactor((36 * 2)-1); //2us resolution + Timer3.setPrescaleFactor((36 * 2)-1); //2us resolution + #elif defined(STM32F4) + //(CYCLES_PER_MICROSECOND == 168, APB2 at 84MHz, APB1 at 42MHz). + //Timer2 to 14 is on APB1, Timers 1, 8, 9 and 10 on APB2. http://www.st.com/resource/en/datasheet/stm32f407vg.pdf sheet 120 + Timer1.setPrescaleFactor((168 * 2)-1); //2us resolution + Timer2.setPrescaleFactor((84 * 2)-1); //2us resolution + Timer3.setPrescaleFactor((84 * 2)-1); //2us resolution #endif Timer2.setMode(1, TIMER_OUTPUT_COMPARE); Timer2.setMode(2, TIMER_OUTPUT_COMPARE); @@ -112,51 +103,56 @@ void initBoard() Timer2.attachInterrupt(3, fuelSchedule3Interrupt); Timer2.attachInterrupt(4, fuelSchedule4Interrupt); #if (INJ_CHANNELS >= 5) + Timer5.setMode(1, TIMER_OUTPUT_COMPARE); Timer5.attachInterrupt(1, fuelSchedule5Interrupt); #endif #if (INJ_CHANNELS >= 6) + Timer5.setMode(2, TIMER_OUTPUT_COMPARE); Timer5.attachInterrupt(2, fuelSchedule6Interrupt); #endif #if (INJ_CHANNELS >= 7) + Timer5.setMode(3, TIMER_OUTPUT_COMPARE); Timer5.attachInterrupt(3, fuelSchedule7Interrupt); #endif #if (INJ_CHANNELS >= 8) + Timer5.setMode(4, TIMER_OUTPUT_COMPARE); Timer5.attachInterrupt(4, fuelSchedule8Interrupt); #endif //Ignition - #if (IGN_CHANNELS >= 1) Timer3.attachInterrupt(1, ignitionSchedule1Interrupt); - #endif - #if (IGN_CHANNELS >= 2) Timer3.attachInterrupt(2, ignitionSchedule2Interrupt); - #endif - #if (IGN_CHANNELS >= 3) Timer3.attachInterrupt(3, ignitionSchedule3Interrupt); - #endif - #if (IGN_CHANNELS >= 4) Timer3.attachInterrupt(4, ignitionSchedule4Interrupt); - #endif #if (IGN_CHANNELS >= 5) + Timer4.setMode(1, TIMER_OUTPUT_COMPARE); Timer4.attachInterrupt(1, ignitionSchedule5Interrupt); #endif #if (IGN_CHANNELS >= 6) + Timer4.setMode(2, TIMER_OUTPUT_COMPARE); Timer4.attachInterrupt(2, ignitionSchedule6Interrupt); #endif #if (IGN_CHANNELS >= 7) + Timer4.setMode(3, TIMER_OUTPUT_COMPARE); Timer4.attachInterrupt(3, ignitionSchedule7Interrupt); #endif #if (IGN_CHANNELS >= 8) + Timer4.setMode(4, TIMER_OUTPUT_COMPARE); Timer4.attachInterrupt(4, ignitionSchedule8Interrupt); #endif + Timer1.setOverflow(0xFFFF); Timer1.resume(); + Timer2.setOverflow(0xFFFF); Timer2.resume(); + Timer3.setOverflow(0xFFFF); Timer3.resume(); #if (IGN_CHANNELS >= 5) + Timer4.setOverflow(0xFFFF); Timer4.resume(); #endif #if (INJ_CHANNELS >= 5) + Timer5.setOverflow(0xFFFF); Timer5.resume(); #endif } diff --git a/speeduino/cancomms.h b/speeduino/cancomms.h index 08ca00f3..db532e60 100644 --- a/speeduino/cancomms.h +++ b/speeduino/cancomms.h @@ -15,7 +15,7 @@ uint8_t Glow, Ghigh; #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) HardwareSerial &CANSerial = Serial3; #elif defined(CORE_STM32) - #if defined(ARDUINO_ARCH_STM32) // STM32GENERIC core + #if defined(ARDUINO_ARCH_STM32) && !defined(_VARIANT_ARDUINO_STM32_) // STM32GENERIC core SerialUART &CANSerial = Serial2; #else //libmaple core aka STM32DUINO HardwareSerial &CANSerial = Serial2; diff --git a/speeduino/comms.ino b/speeduino/comms.ino index eab3a49d..09b5717a 100644 --- a/speeduino/comms.ino +++ b/speeduino/comms.ino @@ -11,6 +11,7 @@ A full copy of the license may be found in the projects root directory #include "maths.h" #include "utils.h" #include "decoders.h" +#include "scheduledIO.h" /* Processes the data on the serial buffer. @@ -195,7 +196,7 @@ void command() break; case 'Q': // send code version - Serial.print(F("speeduino 201903-dev")); + Serial.print(F("speeduino 201902")); break; case 'r': //New format for the optimised OutputChannels @@ -225,7 +226,7 @@ void command() break; case 'S': // send code version - Serial.print(F("Speeduino 2019.03-dev")); + Serial.print(F("Speeduino 2019.02")); currentStatus.secl = 0; //This is required in TS3 due to its stricter timings break; @@ -1514,14 +1515,14 @@ void commandButtons() { case 256: // cmd is stop BIT_CLEAR(currentStatus.testOutputs, 1); - digitalWrite(pinInjector1, LOW); - digitalWrite(pinInjector2, LOW); - digitalWrite(pinInjector3, LOW); - digitalWrite(pinInjector4, LOW); - digitalWrite(pinCoil1, LOW); - digitalWrite(pinCoil2, LOW); - digitalWrite(pinCoil3, LOW); - digitalWrite(pinCoil4, LOW); + endCoil1Charge(); + endCoil2Charge(); + endCoil3Charge(); + endCoil4Charge(); + closeInjector1(); + closeInjector2(); + closeInjector3(); + closeInjector4(); break; case 257: // cmd is enable @@ -1529,10 +1530,10 @@ void commandButtons() BIT_SET(currentStatus.testOutputs, 1); break; case 513: // cmd group is for injector1 on actions - if( BIT_CHECK(currentStatus.testOutputs, 1) ){ digitalWrite(pinInjector1, HIGH); } + if( BIT_CHECK(currentStatus.testOutputs, 1) ){ openInjector1(); } break; case 514: // cmd group is for injector1 off actions - if( BIT_CHECK(currentStatus.testOutputs, 1) ){digitalWrite(pinInjector1, LOW);} + if( BIT_CHECK(currentStatus.testOutputs, 1) ){ closeInjector1(); } break; case 515: // cmd group is for injector1 50% dc actions //for (byte dcloop = 0; dcloop < 11; dcloop++) @@ -1544,64 +1545,64 @@ void commandButtons() //} break; case 516: // cmd group is for injector2 on actions - if( BIT_CHECK(currentStatus.testOutputs, 1) ){ digitalWrite(pinInjector2, HIGH); } + if( BIT_CHECK(currentStatus.testOutputs, 1) ){ openInjector2(); } break; case 517: // cmd group is for injector2 off actions - if( BIT_CHECK(currentStatus.testOutputs, 1) ){ digitalWrite(pinInjector2, LOW); } + if( BIT_CHECK(currentStatus.testOutputs, 1) ){ closeInjector2(); } break; case 518: // cmd group is for injector2 50%dc actions break; case 519: // cmd group is for injector3 on actions - if( BIT_CHECK(currentStatus.testOutputs, 1) ) { digitalWrite(pinInjector3, HIGH); } + if( BIT_CHECK(currentStatus.testOutputs, 1) ){ openInjector3(); } break; case 520: // cmd group is for injector3 off actions - if( BIT_CHECK(currentStatus.testOutputs, 1) ) { digitalWrite(pinInjector3, LOW); } + if( BIT_CHECK(currentStatus.testOutputs, 1) ){ closeInjector3(); } break; case 521: // cmd group is for injector3 50%dc actions break; case 522: // cmd group is for injector4 on actions - if( BIT_CHECK(currentStatus.testOutputs, 1) ){ digitalWrite(pinInjector4, HIGH); } + if( BIT_CHECK(currentStatus.testOutputs, 1) ){ openInjector4(); } break; case 523: // cmd group is for injector4 off actions - if( BIT_CHECK(currentStatus.testOutputs, 1) ){ digitalWrite(pinInjector4, LOW); } + if( BIT_CHECK(currentStatus.testOutputs, 1) ){ closeInjector4(); } break; case 524: // cmd group is for injector4 50% dc actions break; case 769: // cmd group is for spark1 on actions - if( BIT_CHECK(currentStatus.testOutputs, 1) ) { digitalWrite(pinCoil1, HIGH); } + if( BIT_CHECK(currentStatus.testOutputs, 1) ) { digitalWrite(pinCoil1, coilHIGH); } break; case 770: // cmd group is for spark1 off actions - if( BIT_CHECK(currentStatus.testOutputs, 1) ) { digitalWrite(pinCoil1, LOW); } + if( BIT_CHECK(currentStatus.testOutputs, 1) ) { digitalWrite(pinCoil1, coilLOW); } break; case 771: // cmd group is for spark1 50%dc actions break; case 772: // cmd group is for spark2 on actions - if( BIT_CHECK(currentStatus.testOutputs, 1) ) { digitalWrite(pinCoil2, HIGH); } + if( BIT_CHECK(currentStatus.testOutputs, 1) ) { digitalWrite(pinCoil2, coilHIGH); } break; case 773: // cmd group is for spark2 off actions - if( BIT_CHECK(currentStatus.testOutputs, 1) ) { digitalWrite(pinCoil2, LOW); } + if( BIT_CHECK(currentStatus.testOutputs, 1) ) { digitalWrite(pinCoil2, coilLOW); } break; case 774: // cmd group is for spark2 50%dc actions break; case 775: // cmd group is for spark3 on actions - if( BIT_CHECK(currentStatus.testOutputs, 1) ) { digitalWrite(pinCoil3, HIGH); } + if( BIT_CHECK(currentStatus.testOutputs, 1) ) { digitalWrite(pinCoil3, coilHIGH); } break; case 776: // cmd group is for spark3 off actions - if( BIT_CHECK(currentStatus.testOutputs, 1) ) { digitalWrite(pinCoil3, LOW); } + if( BIT_CHECK(currentStatus.testOutputs, 1) ) { digitalWrite(pinCoil3, coilLOW); } break; case 777: // cmd group is for spark3 50%dc actions break; case 778: // cmd group is for spark4 on actions - if( BIT_CHECK(currentStatus.testOutputs, 1) ) { digitalWrite(pinCoil4, HIGH); } + if( BIT_CHECK(currentStatus.testOutputs, 1) ) { digitalWrite(pinCoil4, coilHIGH); } break; case 779: // cmd group is for spark4 off actions - if( BIT_CHECK(currentStatus.testOutputs, 1) ) { digitalWrite(pinCoil4, LOW); } + if( BIT_CHECK(currentStatus.testOutputs, 1) ) { digitalWrite(pinCoil4, coilLOW); } break; case 780: // cmd group is for spark4 50%dc actions diff --git a/speeduino/globals.h b/speeduino/globals.h index 65c96384..f69ed260 100644 --- a/speeduino/globals.h +++ b/speeduino/globals.h @@ -48,11 +48,11 @@ #define SMALL_FLASH_MODE #endif + #if __GNUC__ < 7 //Already included on GCC 7 extern "C" char* sbrk(int incr); //Used to freeRam - #if defined(ARDUINO_ARCH_STM32) // STM32GENERIC core + #endif + #if !defined(_VARIANT_ARDUINO_STM32_) // STM32GENERIC core inline unsigned char digitalPinToInterrupt(unsigned char Interrupt_pin) { return Interrupt_pin; } //This isn't included in the stm32duino libs (yet) - #define portOutputRegister(port) (volatile byte *)( &(port->ODR) ) - #define portInputRegister(port) (volatile byte *)( &(port->IDR) ) #else //libmaple core aka STM32DUINO //These are defined in STM32F1/variants/generic_stm32f103c/variant.h but return a non byte* value #define portOutputRegister(port) (volatile byte *)( &(port->regs->ODR) ) @@ -252,48 +252,48 @@ struct table2D knockWindowDurationTable; //These are for the direct port manipulation of the injectors, coils and aux outputs volatile PORT_TYPE *inj1_pin_port; -volatile byte inj1_pin_mask; +volatile PINMAKS_TYPE inj1_pin_mask; volatile PORT_TYPE *inj2_pin_port; -volatile byte inj2_pin_mask; +volatile PINMAKS_TYPE inj2_pin_mask; volatile PORT_TYPE *inj3_pin_port; -volatile byte inj3_pin_mask; +volatile PINMAKS_TYPE inj3_pin_mask; volatile PORT_TYPE *inj4_pin_port; -volatile byte inj4_pin_mask; +volatile PINMAKS_TYPE inj4_pin_mask; volatile PORT_TYPE *inj5_pin_port; -volatile byte inj5_pin_mask; +volatile PINMAKS_TYPE inj5_pin_mask; volatile PORT_TYPE *inj6_pin_port; -volatile byte inj6_pin_mask; +volatile PINMAKS_TYPE inj6_pin_mask; volatile PORT_TYPE *inj7_pin_port; -volatile byte inj7_pin_mask; +volatile PINMAKS_TYPE inj7_pin_mask; volatile PORT_TYPE *inj8_pin_port; -volatile byte inj8_pin_mask; +volatile PINMAKS_TYPE inj8_pin_mask; volatile PORT_TYPE *ign1_pin_port; -volatile byte ign1_pin_mask; +volatile PINMAKS_TYPE ign1_pin_mask; volatile PORT_TYPE *ign2_pin_port; -volatile byte ign2_pin_mask; +volatile PINMAKS_TYPE ign2_pin_mask; volatile PORT_TYPE *ign3_pin_port; -volatile byte ign3_pin_mask; +volatile PINMAKS_TYPE ign3_pin_mask; volatile PORT_TYPE *ign4_pin_port; -volatile byte ign4_pin_mask; +volatile PINMAKS_TYPE ign4_pin_mask; volatile PORT_TYPE *ign5_pin_port; -volatile byte ign5_pin_mask; +volatile PINMAKS_TYPE ign5_pin_mask; volatile PORT_TYPE *ign6_pin_port; -volatile byte ign6_pin_mask; +volatile PINMAKS_TYPE ign6_pin_mask; volatile PORT_TYPE *ign7_pin_port; -volatile byte ign7_pin_mask; +volatile PINMAKS_TYPE ign7_pin_mask; volatile PORT_TYPE *ign8_pin_port; -volatile byte ign8_pin_mask; +volatile PINMAKS_TYPE ign8_pin_mask; volatile PORT_TYPE *tach_pin_port; -volatile byte tach_pin_mask; +volatile PINMAKS_TYPE tach_pin_mask; volatile PORT_TYPE *pump_pin_port; -volatile byte pump_pin_mask; +volatile PINMAKS_TYPE pump_pin_mask; volatile PORT_TYPE *triggerPri_pin_port; -volatile byte triggerPri_pin_mask; +volatile PINMAKS_TYPE triggerPri_pin_mask; volatile PORT_TYPE *triggerSec_pin_port; -volatile byte triggerSec_pin_mask; +volatile PINMAKS_TYPE triggerSec_pin_mask; //These need to be here as they are used in both speeduino.ino and scheduler.ino bool channel1InjEnabled = true; @@ -313,7 +313,6 @@ int ignition5EndAngle = 0; //These are variables used across multiple files bool initialisationComplete = false; //Tracks whether the setup() function has run completely -byte fpPrimeTime = 0; //The time (in seconds, based on currentStatus.secl) that the fuel pump started priming volatile uint16_t mainLoopCount; unsigned long revolutionTime; //The time in uS that one revolution would take at current speed (The time tooth 1 was last seen, minus the time it was seen prior to that) volatile unsigned long timer5_overflow_count = 0; //Increments every time counter 5 overflows. Used for the fast version of micros() diff --git a/speeduino/idle.h b/speeduino/idle.h index 243d6b0c..b5b164e1 100644 --- a/speeduino/idle.h +++ b/speeduino/idle.h @@ -42,9 +42,9 @@ unsigned int iacStepTime; unsigned int completedHomeSteps; volatile PORT_TYPE *idle_pin_port; -volatile byte idle_pin_mask; +volatile PINMAKS_TYPE idle_pin_mask; volatile PORT_TYPE *idle2_pin_port; -volatile byte idle2_pin_mask; +volatile PINMAKS_TYPE idle2_pin_mask; volatile bool idle_pwm_state; unsigned int idle_pwm_max_count; //Used for variable PWM frequency diff --git a/speeduino/init.ino b/speeduino/init.ino index 73ca81ef..3d5d2836 100644 --- a/speeduino/init.ino +++ b/speeduino/init.ino @@ -131,6 +131,15 @@ void initialiseAll() endCoil3Charge(); endCoil4Charge(); endCoil5Charge(); + #if (INJ_CHANNELS >= 6) + endCoil6Charge(); + #endif + #if (INJ_CHANNELS >= 7) + endCoil7Charge(); + #endif + #if (INJ_CHANNELS >= 8) + endCoil8Charge(); + #endif //Similar for injectors, make sure they're turned off closeInjector1(); @@ -138,6 +147,15 @@ void initialiseAll() closeInjector3(); closeInjector4(); closeInjector5(); + #if (IGN_CHANNELS >= 6) + closeInjector6(); + #endif + #if (IGN_CHANNELS >= 7) + closeInjector7(); + #endif + #if (IGN_CHANNELS >= 8) + closeInjector8(); + #endif //Set the tacho output default state digitalWrite(pinTachOut, HIGH); @@ -928,6 +946,7 @@ void setPinMapping(byte boardID) //PC8~PC12 SDio //PA13~PA15 & PB4 SWD(debug) pins //PB0 EEPROM CS pin + //PA9 & PD10 Serial1 //PD5 & PD6 Serial2 pinInjector1 = PE7; //Output pin injector 1 is on pinInjector2 = PE8; //Output pin injector 2 is on @@ -935,18 +954,18 @@ void setPinMapping(byte boardID) pinInjector4 = PE10; //Output pin injector 4 is on pinInjector5 = PE11; //Output pin injector 5 is on pinInjector6 = PE12; //Output pin injector 6 is on - pinCoil1 = PB5; //Pin for coil 1 - pinCoil2 = PB6; //Pin for coil 2 - pinCoil3 = PB7; //Pin for coil 3 - pinCoil4 = PB8; //Pin for coil 4 - pinCoil5 = PB9; //Pin for coil 5 + pinCoil1 = PD0; //Pin for coil 1 + pinCoil2 = PD1; //Pin for coil 2 + pinCoil3 = PD2; //Pin for coil 3 + pinCoil4 = PD3; //Pin for coil 4 + pinCoil5 = PD4; //Pin for coil 5 pinTPS = A0; //TPS input pin pinMAP = A1; //MAP sensor pin pinIAT = A2; //IAT sensor pin pinCLT = A3; //CLT sensor pin pinO2 = A4; //O2 Sensor pin pinBat = A5; //Battery reference voltage pin - pinBaro = A10; + pinBaro = A9; pinIdle1 = PB8; //Single wire idle control pinIdle2 = PB9; //2 wire idle control pinBoost = PE0; //Boost control @@ -956,8 +975,8 @@ void setPinMapping(byte boardID) pinStepperEnable = PD9; //Enable pin for DRV8825 pinDisplayReset = PE1; // OLED reset pin pinFan = PE2; //Pin for the fan output - pinFuelPump = PA6; //Fuel pump output - pinTachOut = PA7; //Tacho output pin + pinFuelPump = PC0; //Fuel pump output + pinTachOut = PC1; //Tacho output pin //external interrupt enabled pins //external interrupts could be enalbed in any pin, except same port numbers (PA4,PE4) pinFlex = PE2; // Flex sensor (Must be external interrupt enabled) @@ -1323,37 +1342,80 @@ void setPinMapping(byte boardID) #endif default: - #ifndef SMALL_FLASH_MODE //No support for bluepill here anyway - //Pin mappings as per the v0.2 shield - pinInjector1 = 8; //Output pin injector 1 is on - pinInjector2 = 9; //Output pin injector 2 is on - pinInjector3 = 10; //Output pin injector 3 is on - pinInjector4 = 11; //Output pin injector 4 is on - pinInjector5 = 12; //Output pin injector 5 is on - pinCoil1 = 28; //Pin for coil 1 - pinCoil2 = 24; //Pin for coil 2 - pinCoil3 = 40; //Pin for coil 3 - pinCoil4 = 36; //Pin for coil 4 - pinCoil5 = 34; //Pin for coil 5 PLACEHOLDER value for now - pinTrigger = 20; //The CAS pin - pinTrigger2 = 21; //The Cam Sensor pin - pinTPS = A2; //TPS input pin - pinMAP = A3; //MAP sensor pin - pinIAT = A0; //IAT sensor pin - pinCLT = A1; //CLS sensor pin - pinO2 = A8; //O2 Sensor pin - pinBat = A4; //Battery reference voltage pin - pinStepperDir = 16; //Direction pin for DRV8825 driver - pinStepperStep = 17; //Step pin for DRV8825 driver - pinDisplayReset = 48; // OLED reset pin - pinFan = 47; //Pin for the fan output - pinFuelPump = 4; //Fuel pump output - pinTachOut = 49; //Tacho output pin - pinFlex = 3; // Flex sensor (Must be external interrupt enabled) - pinBoost = 5; - pinIdle1 = 6; - pinResetControl = 43; //Reset control output - #endif + #if defined(STM32F4) + //Black F407VE http://wiki.stm32duino.com/index.php?title=STM32F407 + //PC8~PC12 SDio + //PA13~PA15 & PB4 SWD(debug) pins + //PB0 EEPROM CS pin + //PA9 & PD10 Serial1 + //PD5 & PD6 Serial2 + pinInjector1 = PE7; //Output pin injector 1 is on + pinInjector2 = PE8; //Output pin injector 2 is on + pinInjector3 = PE9; //Output pin injector 3 is on + pinInjector4 = PE10; //Output pin injector 4 is on + pinInjector5 = PE11; //Output pin injector 5 is on + pinInjector6 = PE12; //Output pin injector 6 is on + pinCoil1 = PD0; //Pin for coil 1 + pinCoil2 = PD1; //Pin for coil 2 + pinCoil3 = PD2; //Pin for coil 3 + pinCoil4 = PD3; //Pin for coil 4 + pinCoil5 = PD4; //Pin for coil 5 + pinTPS = A0; //TPS input pin + pinMAP = A1; //MAP sensor pin + pinIAT = A2; //IAT sensor pin + pinCLT = A3; //CLT sensor pin + pinO2 = A4; //O2 Sensor pin + pinBat = A5; //Battery reference voltage pin + pinBaro = A9; + pinIdle1 = PB8; //Single wire idle control + pinIdle2 = PB9; //2 wire idle control + pinBoost = PE0; //Boost control + pinVVT_1 = PE1; //Default VVT output + pinStepperDir = PD8; //Direction pin for DRV8825 driver + pinStepperStep = PB15; //Step pin for DRV8825 driver + pinStepperEnable = PD9; //Enable pin for DRV8825 + pinDisplayReset = PE1; // OLED reset pin + pinFan = PE2; //Pin for the fan output + pinFuelPump = PC0; //Fuel pump output + pinTachOut = PC1; //Tacho output pin + //external interrupt enabled pins + //external interrupts could be enalbed in any pin, except same port numbers (PA4,PE4) + pinFlex = PE2; // Flex sensor (Must be external interrupt enabled) + pinTrigger = PE3; //The CAS pin + pinTrigger2 = PE4; //The Cam Sensor pin + #else + #ifndef SMALL_FLASH_MODE //No support for bluepill here anyway + //Pin mappings as per the v0.2 shield + pinInjector1 = 8; //Output pin injector 1 is on + pinInjector2 = 9; //Output pin injector 2 is on + pinInjector3 = 10; //Output pin injector 3 is on + pinInjector4 = 11; //Output pin injector 4 is on + pinInjector5 = 12; //Output pin injector 5 is on + pinCoil1 = 28; //Pin for coil 1 + pinCoil2 = 24; //Pin for coil 2 + pinCoil3 = 40; //Pin for coil 3 + pinCoil4 = 36; //Pin for coil 4 + pinCoil5 = 34; //Pin for coil 5 PLACEHOLDER value for now + pinTrigger = 20; //The CAS pin + pinTrigger2 = 21; //The Cam Sensor pin + pinTPS = A2; //TPS input pin + pinMAP = A3; //MAP sensor pin + pinIAT = A0; //IAT sensor pin + pinCLT = A1; //CLS sensor pin + pinO2 = A8; //O2 Sensor pin + pinBat = A4; //Battery reference voltage pin + pinStepperDir = 16; //Direction pin for DRV8825 driver + pinStepperStep = 17; //Step pin for DRV8825 driver + pinDisplayReset = 48; // OLED reset pin + pinFan = 47; //Pin for the fan output + pinFuelPump = 4; //Fuel pump output + pinTachOut = 49; //Tacho output pin + pinFlex = 3; // Flex sensor (Must be external interrupt enabled) + pinBoost = 5; + pinIdle1 = 6; + pinResetControl = 43; //Reset control output + #endif + #endif break; } diff --git a/speeduino/scheduler.ino b/speeduino/scheduler.ino index 135ee229..84acd274 100644 --- a/speeduino/scheduler.ino +++ b/speeduino/scheduler.ino @@ -64,20 +64,28 @@ void initialiseSchedulers() fuelSchedule8.schedulesSet = 0; fuelSchedule1.counter = &FUEL1_COUNTER; + fuelSchedule1.compare = &FUEL1_COMPARE; fuelSchedule2.counter = &FUEL2_COUNTER; + fuelSchedule2.compare = &FUEL2_COMPARE; fuelSchedule3.counter = &FUEL3_COUNTER; + fuelSchedule3.compare = &FUEL3_COMPARE; fuelSchedule4.counter = &FUEL4_COUNTER; + fuelSchedule4.compare = &FUEL4_COMPARE; #if (INJ_CHANNELS >= 5) fuelSchedule5.counter = &FUEL5_COUNTER; + fuelSchedule5.compare = &FUEL5_COMPARE; #endif #if (INJ_CHANNELS >= 6) fuelSchedule5.counter = &FUEL6_COUNTER; + fuelSchedule6.compare = &FUEL6_COMPARE; #endif #if (INJ_CHANNELS >= 7) fuelSchedule5.counter = &FUEL7_COUNTER; + fuelSchedule7.compare = &FUEL7_COMPARE; #endif #if (INJ_CHANNELS >= 8) - fuelSchedule5.counter = &FUEL8_COUNTER; + fuelSchedule8.counter = &FUEL8_COUNTER; + fuelSchedule8.compare = &FUEL8_COMPARE; #endif ignitionSchedule1.Status = OFF; @@ -98,6 +106,31 @@ void initialiseSchedulers() ignitionSchedule7.schedulesSet = 0; ignitionSchedule8.schedulesSet = 0; + ignitionSchedule1.counter = &IGN1_COUNTER; + ignitionSchedule1.compare = &IGN1_COMPARE; + ignitionSchedule2.counter = &IGN2_COUNTER; + ignitionSchedule2.compare = &IGN2_COMPARE; + ignitionSchedule3.counter = &IGN3_COUNTER; + ignitionSchedule3.compare = &IGN3_COMPARE; + ignitionSchedule4.counter = &IGN4_COUNTER; + ignitionSchedule4.compare = &IGN4_COMPARE; + #if (INJ_CHANNELS >= 5) + ignitionSchedule5.counter = &IGN5_COUNTER; + ignitionSchedule5.compare = &IGN5_COMPARE; + #endif + #if (INJ_CHANNELS >= 6) + ignitionSchedule5.counter = &IGN6_COUNTER; + ignitionSchedule6.compare = &IGN6_COMPARE; + #endif + #if (INJ_CHANNELS >= 7) + ignitionSchedule5.counter = &IGN7_COUNTER; + ignitionSchedule7.compare = &IGN7_COMPARE; + #endif + #if (INJ_CHANNELS >= 8) + ignitionSchedule8.counter = &IGN8_COUNTER; + ignitionSchedule8.compare = &IGN8_COMPARE; + #endif + } /* diff --git a/speeduino/storage.ino b/speeduino/storage.ino index 9451e842..c4fcf492 100644 --- a/speeduino/storage.ino +++ b/speeduino/storage.ino @@ -10,22 +10,24 @@ A full copy of the license may be found in the projects root directory #include "comms.h" #if defined(CORE_SAMD21) #include "src/FlashStorage/FlashAsEEPROM.h" +#elif defined(CORE_STM32) + #include #else #include #endif #include "storage.h" void writeAllConfig() { - writeConfig(1); - if (eepromWritesPending == false) { writeConfig(2); } - if (eepromWritesPending == false) { writeConfig(3); } - if (eepromWritesPending == false) { writeConfig(4); } - if (eepromWritesPending == false) { writeConfig(5); } - if (eepromWritesPending == false) { writeConfig(6); } - if (eepromWritesPending == false) { writeConfig(7); } - if (eepromWritesPending == false) { writeConfig(8); } - if (eepromWritesPending == false) { writeConfig(9); } - if (eepromWritesPending == false) { writeConfig(10); } + writeConfig(veSetPage); + if (eepromWritesPending == false) { writeConfig(veMapPage); } + if (eepromWritesPending == false) { writeConfig(ignMapPage); } + if (eepromWritesPending == false) { writeConfig(ignSetPage); } + if (eepromWritesPending == false) { writeConfig(afrMapPage); } + if (eepromWritesPending == false) { writeConfig(afrSetPage); } + if (eepromWritesPending == false) { writeConfig(boostvvtPage); } + if (eepromWritesPending == false) { writeConfig(seqFuelPage); } + if (eepromWritesPending == false) { writeConfig(canbusPage); } + if (eepromWritesPending == false) { writeConfig(warmupPage); } } diff --git a/speeduino/timers.ino b/speeduino/timers.ino index 415f5235..0642bb94 100644 --- a/speeduino/timers.ino +++ b/speeduino/timers.ino @@ -95,7 +95,7 @@ void oneMSInterval() //Most ARM chips can simply call a function { loop250ms = 0; //Reset Counter BIT_SET(TIMER_mask, BIT_TIMER_4HZ); - #if defined(CORE_STM32) //debug purpose, only visal for running code + #if defined(CORE_STM32) //debug purpose, only visual for running code digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); #endif