diff --git a/platformio.ini b/platformio.ini index bd98b919..432f8aad 100644 --- a/platformio.ini +++ b/platformio.ini @@ -32,10 +32,9 @@ lib_deps = EEPROM, FlexCAN [env:genericSTM32F103RB] platform = ststm32@~4.5.0 framework = arduino -; framework-arduinoststm32 board = genericSTM32F103RB lib_deps = EEPROM -build_flags = -fpermissive -std=gnu++11 +build_flags = -fpermissive -std=gnu++11 -DCORE_STM32_OFFICIAL [env:genericSTM32F103RB_STM32GENERIC] ;platform = ststm32@~4.5.0 @@ -51,11 +50,13 @@ build_flags = -fpermissive -std=gnu++11 -UBOARD_NR_GPIO_PINS -DUSE_STM32GENERIC ;platform = ststm32@~4.5.0 platform = ststm32 framework = arduino -; framework-arduinoststm32 -board = genericSTM32F407VET6 +;board = genericSTM32F407VET6 +board = black_f407ve lib_deps = EEPROM -build_flags = -fpermissive -std=gnu++11 -UBOARD_NR_GPIO_PINS -DCORE_STM32_OFFICIAL -DMENU_USB_SERIAL -upload_protocol = dfu +board_build.core = stm32 +build_flags = -fpermissive -std=gnu++11 -UBOARD_NR_GPIO_PINS -DCORE_STM32_OFFICIAL -DSPI_AS_EEPROM + + [env:bluepill_f103c8] platform = ststm32 @@ -64,7 +65,7 @@ framework = arduino board = bluepill_f103c8 lib_deps = EEPROM ;build_flags = -fpermissive -std=gnu++11 -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -Wl,-Map,output.map -build_flags = -fpermissive -std=gnu++11 -Os -UBOARD_NR_GPIO_PINS +build_flags = -fpermissive -std=gnu++11 -Os -DCORE_STM32_OFFICIAL -UBOARD_NR_GPIO_PINS ;SAMD21 [env:samd21] diff --git a/speeduino/board_stm32_official.h b/speeduino/board_stm32_official.h index d259a545..78bf8233 100644 --- a/speeduino/board_stm32_official.h +++ b/speeduino/board_stm32_official.h @@ -1,9 +1,9 @@ #ifndef STM32F407VE_H #define STM32F407VE_H #if defined(CORE_STM32_OFFICIAL) - +#include #include -#include +#include "stm32f4xx_ll_tim.h" /* *********************************************************************************************************** * General @@ -11,8 +11,17 @@ #define PORT_TYPE uint32_t #define PINMASK_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() -#define EEPROM_LIB_H "src/BackupSram/BackupSramAsEEPROM.h" -#define digitalPinToInterrupt(p) (p) +#if defined(SRAM_AS_EEPROM) + #define EEPROM_LIB_H "src/BackupSram/BackupSramAsEEPROM.h" +#elif defined(SPI_AS_EEPROM) + #define EEPROM_LIB_H "src/SPIAsEEPROM/SPIAsEEPROM.h" +#else + #define EEPROM_LIB_H +#endif + +#ifndef LED_BUILTIN + #define LED_BUILTIN PA7 +#endif #define USE_SERIAL3 void initBoard(); diff --git a/speeduino/board_stm32_official.ino b/speeduino/board_stm32_official.ino index 401698c9..7dbfe65b 100644 --- a/speeduino/board_stm32_official.ino +++ b/speeduino/board_stm32_official.ino @@ -15,7 +15,6 @@ stimer_t HardwareTimers_4; stimer_t HardwareTimers_5; stimer_t HardwareTimers_8; - #define LED_BUILTIN PA7 //These should really be in the stm32GENERIC libs, but for somereason they only have timers 1-4 // #include // #include "src/HardwareTimers/HardwareTimer.h" @@ -78,15 +77,9 @@ *********************************************************************************************************** * Timers */ - #if defined(ARDUINO_BLACK_F407VE) || defined(STM32F4) || defined(_STM32F4_) + //#if defined(ARDUINO_BLACK_F407VE) || defined(STM32F4) || defined(_STM32F4_) TimerHandleInit(&HardwareTimers_8, 1000, 168); attachIntHandle(&HardwareTimers_8, oneMSIntervalIRQ); - #else - Timer4.setPeriod(1000); // Set up period - Timer4.setMode(1, TIMER_OUTPUT_COMPARE); - Timer4.attachInterrupt(1, oneMSInterval); - Timer4.resume(); //Start Timer - #endif pinMode(LED_BUILTIN, OUTPUT); //Visual WDT /* diff --git a/speeduino/globals.h b/speeduino/globals.h index 045e53a8..4e92b2f5 100644 --- a/speeduino/globals.h +++ b/speeduino/globals.h @@ -3,23 +3,27 @@ #include #include "table.h" -//These are configuration options for changing around the outputs that are used. THese are just the defaults and may be changed in the sections below based on the hardware in use. -#define INJ_CHANNELS 4 -#define IGN_CHANNELS 5 - #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) #define BOARD_DIGITAL_GPIO_PINS 54 #define BOARD_NR_GPIO_PINS 62 #define LED_BUILTIN 13 #define CORE_AVR #define BOARD_H "board_avr2560.h" + #define INJ_CHANNELS 4 + #define IGN_CHANNELS 5 //#define TIMER5_MICROS #elif defined(CORE_TEENSY) #define BOARD_H "board_teensy35.h" + #define INJ_CHANNELS 8 + #define IGN_CHANNELS 8 #elif defined(STM32_MCU_SERIES) || defined(ARDUINO_ARCH_STM32) || defined(__STM32F1__) || defined(STM32F4) || defined(STM32) + //These should be updated to 8 later, but there's bits missing currently + #define INJ_CHANNELS 4 + #define IGN_CHANNELS 5 + #ifndef word #define word(h, l) ((h << 8) | l) //word() function not defined for this platform in the main library #endif @@ -32,17 +36,11 @@ #elif defined(ARDUINO_BLACK_F407VE) || defined(STM32F4) #define BOARD_DIGITAL_GPIO_PINS 80 #define BOARD_NR_GPIO_PINS 80 - - //These boards always make 8/8 channels available - #undef INJ_CHANNELS - #undef IGN_CHANNELS - #define INJ_CHANNELS 8 - #define IGN_CHANNELS 8 #endif #if defined(CORE_STM32_OFFICIAL) //Need to identify the official core better - #define CORE_STM32_OFFICIAL + //#define CORE_STM32_OFFICIAL #define BOARD_H "board_stm32_official.h" #else #define CORE_STM32_GENERIC @@ -334,8 +332,10 @@ volatile uint8_t compositeLogHistory[TOOTH_LOG_BUFFER]; volatile bool fpPrimed = false; //Tracks whether or not the fuel pump priming has been completed yet volatile unsigned int toothHistoryIndex = 0; volatile byte toothHistorySerialIndex = 0; -byte primaryTriggerEdge; -byte secondaryTriggerEdge; + + byte primaryTriggerEdge; + byte secondaryTriggerEdge; + int CRANK_ANGLE_MAX = 720; int CRANK_ANGLE_MAX_IGN = 360; int CRANK_ANGLE_MAX_INJ = 360; //The number of crank degrees that the system track over. 360 for wasted / timed batch and 720 for sequential diff --git a/speeduino/scheduler.h b/speeduino/scheduler.h index f185181a..5487efc5 100644 --- a/speeduino/scheduler.h +++ b/speeduino/scheduler.h @@ -50,7 +50,7 @@ void setIgnitionSchedule8(void (*startCallback)(), unsigned long timeout, unsign static inline void refreshIgnitionSchedule1(unsigned long timeToEnd) __attribute__((always_inline)); //The ARM cores use seprate functions for their ISRs -#if defined(CORE_STM32) || defined(CORE_TEENSY) +#if defined(CORE_STM32_OFFICIAL) || defined(CORE_STM32_GENERIC) || defined(CORE_TEENSY) static inline void fuelSchedule1Interrupt(); static inline void fuelSchedule2Interrupt(); static inline void fuelSchedule3Interrupt(); diff --git a/speeduino/src/BackupSram/BackupSramAsEEPROM.cpp b/speeduino/src/BackupSram/BackupSramAsEEPROM.cpp index 022476d3..89806c63 100644 --- a/speeduino/src/BackupSram/BackupSramAsEEPROM.cpp +++ b/speeduino/src/BackupSram/BackupSramAsEEPROM.cpp @@ -1,6 +1,9 @@ -#if defined(ARDUINO_BLACK_F407VE) +//#if defined(ARDUINO_BLACK_F407VE) +#if defined(CORE_STM32_OFFICIAL) && defined(SRAM_AS_EEPROM) #include "BackupSramAsEEPROM.h" +#include "libmaple/rccF4.h" + BackupSramAsEEPROM::BackupSramAsEEPROM(){ //Enable the power interface clock RCC->APB1ENR |= RCC_APB1ENR_PWREN; diff --git a/speeduino/src/BackupSram/BackupSramAsEEPROM.h b/speeduino/src/BackupSram/BackupSramAsEEPROM.h index e376a2c9..b79da490 100644 --- a/speeduino/src/BackupSram/BackupSramAsEEPROM.h +++ b/speeduino/src/BackupSram/BackupSramAsEEPROM.h @@ -1,9 +1,6 @@ //Backup sram stores data in the battery backuped sram portion. //The backup battery is available on the ebay stm32F407VET6 black boards. - - - -#if defined(ARDUINO_BLACK_F407VE) +#if defined(CORE_STM32_OFFICIAL) && defined(SRAM_AS_EEPROM) //UGLY HACK TO PREVENT EEPROM LIBRARY BEING IMPORTED FIRST!! //Use with black_F407VE board diff --git a/speeduino/timers.h b/speeduino/timers.h index c172adc5..1deeff84 100644 --- a/speeduino/timers.h +++ b/speeduino/timers.h @@ -32,7 +32,7 @@ volatile uint16_t last250msLoopCount = 1000; //Set to effectively random number #if defined (CORE_TEENSY) IntervalTimer lowResTimer; void oneMSInterval(); -#elif defined(CORE_STM32) +#elif defined(CORE_STM32_OFFICIAL) || defined(CORE_STM32_GENERIC) void oneMSInterval(); #endif void initialiseTimers();