Generic SPI as EEPROM changes.

This commit is contained in:
Josh Stewart 2020-01-13 12:14:00 +10:00
parent 3a73508cc3
commit 106b75509d
7 changed files with 56 additions and 16 deletions

View File

@ -20,14 +20,14 @@ lib_deps = EEPROM
platform=teensy platform=teensy
board=teensy35 board=teensy35
framework=arduino framework=arduino
lib_deps = EEPROM, FlexCAN lib_deps = EEPROM, FlexCAN, SD
[env:DropBearT] [env:DropBearT]
platform=teensy platform=teensy
board=teensy35 board=teensy35
framework=arduino framework=arduino
lib_deps = EEPROM, FlexCAN lib_deps = EEPROM, FlexCAN, SD
build_flags = -DUSE_MC33810 build_flags = -DUSE_MC33810 -DUSE_SPI_EEPROM
[env:teensy40] [env:teensy40]
platform=teensy platform=teensy

View File

@ -16,7 +16,7 @@
#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 micros_safe() micros() //timer5 method is not used on anything but AVR, the micros_safe() macro is simply an alias for the normal micros()
#if defined(SRAM_AS_EEPROM) #if defined(SRAM_AS_EEPROM)
#define EEPROM_LIB_H "src/BackupSram/BackupSramAsEEPROM.h" #define EEPROM_LIB_H "src/BackupSram/BackupSramAsEEPROM.h"
#elif defined(SPIFLASH_AS_EEPROM) #elif defined(USE_SPI_FLASH)
#define EEPROM_LIB_H "src/SPIAsEEPROM/SPIAsEEPROM.h" #define EEPROM_LIB_H "src/SPIAsEEPROM/SPIAsEEPROM.h"
#else #else
#define EEPROM_LIB_H <EEPROM.h> #define EEPROM_LIB_H <EEPROM.h>

View File

@ -15,7 +15,11 @@
#define BOARD_DIGITAL_GPIO_PINS 34 #define BOARD_DIGITAL_GPIO_PINS 34
#define BOARD_NR_GPIO_PINS 34 #define BOARD_NR_GPIO_PINS 34
#define USE_SERIAL3 #define USE_SERIAL3
#ifdef USE_SPI_EEPROM
#define EEPROM_LIB_H "src/SPIAsEEPROM/SPIAsEEPROM.h"
#else
#define EEPROM_LIB_H <EEPROM.h> #define EEPROM_LIB_H <EEPROM.h>
#endif
#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 micros_safe() micros() //timer5 method is not used on anything but AVR, the micros_safe() macro is simply an alias for the normal micros()

View File

@ -1066,9 +1066,12 @@ byte pinFlex; //Pin with the flex sensor attached
byte pinBaro; //Pin that an external barometric pressure sensor is attached to (If used) byte pinBaro; //Pin that an external barometric pressure sensor is attached to (If used)
byte pinResetControl; // Output pin used control resetting the Arduino byte pinResetControl; // Output pin used control resetting the Arduino
#ifdef USE_MC33810 #ifdef USE_MC33810
//If the MC33810 IC\s are in use, these are the chip select pins //If the MC33810 IC\s are in use, these are the chip select pins
byte pinMC33810_1_CS; byte pinMC33810_1_CS;
byte pinMC33810_2_CS; byte pinMC33810_2_CS;
#endif
#ifdef USE_SPI_EEPROM
byte pinSPIFlash_CS;
#endif #endif
/* global variables */ // from speeduino.ino /* global variables */ // from speeduino.ino

View File

@ -1695,7 +1695,30 @@ void setPinMapping(byte boardID)
#ifdef USE_MC33810 #ifdef USE_MC33810
pinMC33810_1_CS = 10; pinMC33810_1_CS = 10;
pinMC33810_2_CS = 9; pinMC33810_2_CS = 9;
//Pin alignment to the MC33810 outputs
MC33810_BIT_INJ1 = 3;
MC33810_BIT_INJ2 = 1;
MC33810_BIT_INJ3 = 0;
MC33810_BIT_INJ4 = 2;
MC33810_BIT_IGN1 = 5;
MC33810_BIT_IGN2 = 6;
MC33810_BIT_IGN3 = 7;
MC33810_BIT_IGN4 = 8;
MC33810_BIT_INJ5 = 3;
MC33810_BIT_INJ6 = 1;
MC33810_BIT_INJ7 = 0;
MC33810_BIT_INJ8 = 2;
MC33810_BIT_IGN5 = 5;
MC33810_BIT_IGN6 = 6;
MC33810_BIT_IGN7 = 7;
MC33810_BIT_IGN8 = 8;
#endif #endif
#ifdef USE_SPI_EEPROM
pinSPIFlash_CS = 6;
#endif
#endif #endif
break; break;
@ -2094,6 +2117,11 @@ void setPinMapping(byte boardID)
initMC33810(); initMC33810();
#endif #endif
#ifdef USE_SPI_EEPROM
//We need to send the flash CS (SS) pin if we're using SPI flash. It cannot read from globals.h
EEPROM.begin(pinSPIFlash_CS);
#endif
tach_pin_port = portOutputRegister(digitalPinToPort(pinTachOut)); tach_pin_port = portOutputRegister(digitalPinToPort(pinTachOut));
tach_pin_mask = digitalPinToBitMask(pinTachOut); tach_pin_mask = digitalPinToBitMask(pinTachOut);
pump_pin_port = portOutputRegister(digitalPinToPort(pinFuelPump)); pump_pin_port = portOutputRegister(digitalPinToPort(pinFuelPump));

View File

@ -26,23 +26,26 @@
* <http://www.gnu.org/licenses/>. * <http://www.gnu.org/licenses/>.
*/ */
#if defined(CORE_STM32_OFFICIAL) && defined(SPIFLASH_AS_EEPROM) //#if defined(CORE_STM32_OFFICIAL) && defined(SPIFLASH_AS_EEPROM)
#if defined(USE_SPI_EEPROM)
#include "SPIAsEEPROM.h" #include "SPIAsEEPROM.h"
#include "SPI.h" #include "SPI.h"
//#include "globals.h"
SPIAsEEPROM::SPIAsEEPROM() SPIAsEEPROM::SPIAsEEPROM()
{ {
pinMode(PB0, OUTPUT); //pinMode(PB0, OUTPUT);
magicbuf[0] = MAGICNUMBER1; magicbuf[0] = MAGICNUMBER1;
magicbuf[1] = MAGICNUMBER2; magicbuf[1] = MAGICNUMBER2;
magicbuf[2] = MAGICNUMBER3; magicbuf[2] = MAGICNUMBER3;
magicbuf[3] = 0x00; magicbuf[3] = 0x00;
} }
uint8_t SPIAsEEPROM::begin() { uint8_t SPIAsEEPROM::begin(uint8_t pinSPIFlash_CS=6)
{
SpiFlashAvialable = winbondSPIFlash.begin(_W25Q16,SPI,PB0); pinMode(pinSPIFlash_CS, OUTPUT);
SpiFlashAvialable = winbondSPIFlash.begin(_W25Q16,SPI, pinSPIFlash_CS);
uint8_t formatted = 0; uint8_t formatted = 0;
if(SpiFlashAvialable){ if(SpiFlashAvialable){
//check for magic numbers //check for magic numbers

View File

@ -29,7 +29,8 @@
#ifndef SPI_AS_EEPROM_H #ifndef SPI_AS_EEPROM_H
#define SPI_AS_EEPROM_H #define SPI_AS_EEPROM_H
#if defined(CORE_STM32_OFFICIAL) && defined(SPIFLASH_AS_EEPROM) //#if defined(CORE_STM32_OFFICIAL) && defined(SPIFLASH_AS_EEPROM)
#if defined(USE_SPI_EEPROM)
#define FLASHSIZEUSED 1757184 //must be a multiple of sectorsize //1757184 = 6006 bytes of EEPROM #define FLASHSIZEUSED 1757184 //must be a multiple of sectorsize //1757184 = 6006 bytes of EEPROM
#define BYTESPERSECTOR 14 #define BYTESPERSECTOR 14
@ -63,11 +64,12 @@ class SPIAsEEPROM {
uint32_t infoFlashAddress; uint32_t infoFlashAddress;
uint8_t writeMagicNumber(uint16_t sectorNumber); uint8_t writeMagicNumber(uint16_t sectorNumber);
uint16_t count(uint8_t buf[FLASH_PAGESIZE/BITS_PER_BYTE]); uint16_t count(uint8_t buf[FLASH_PAGESIZE/BITS_PER_BYTE]);
uint8_t pinSPIFlash_CS;
public: public:
SPIAsEEPROM(); SPIAsEEPROM();
uint8_t begin(); uint8_t begin(uint8_t pinSPIFlash_CS);
uint8_t formatFlashForUse(); uint8_t formatFlashForUse();
uint8_t read(uint16_t addressEEPROM); uint8_t read(uint16_t addressEEPROM);
int8_t write(uint16_t addressEEPROM, uint8_t val); int8_t write(uint16_t addressEEPROM, uint8_t val);