Allow secondary serial interface to be set on a per board basis rather than MCU only

Fixes #1135
This commit is contained in:
Josh Stewart 2023-11-21 16:47:24 +11:00
parent 011a2ed906
commit 36d22b4832
12 changed files with 54 additions and 38 deletions

View File

@ -1,6 +1,7 @@
#include "globals.h"
#if defined(CORE_AVR)
#include "auxiliaries.h"
#include "comms_secondary.h"
// Prescaler values for timers 1-3-4-5. Refer to www.instructables.com/files/orig/F3T/TIKL/H3WSA4V7/F3TTIKLH3WSA4V7.jpg
#define TIMER_PRESCALER_OFF ((0<<CS12)|(0<<CS11)|(0<<CS10))
@ -22,6 +23,7 @@ void initBoard(void)
* General
*/
configPage9.intcan_available = 0; // AVR devices do NOT have internal canbus
pSecondarySerial = &Serial3;
/*
***********************************************************************************************************

View File

@ -159,6 +159,9 @@ static inline void IGN8_TIMER_DISABLE(void) { TIMSK3 &= ~(1 << OCIE3B); } //Repl
* CAN / Second serial
*/
#define secondarySerial_AVAILABLE
#define SECONDARY_SERIAL_T HardwareSerial
#endif //CORE_AVR
#endif //AVR2560_H

View File

@ -7,6 +7,7 @@
#include "scheduler.h"
#include "HardwareTimer.h"
#include "timers.h"
#include "comms_secondary.h"
#if HAL_CAN_MODULE_ENABLED
//This activates CAN1 interface on STM32, but it's named as Can0, because that's how Teensy implementation is done
@ -91,6 +92,11 @@ STM32RTC& rtc = STM32RTC::getInstance();
#endif
delay(10);
#ifndef HAVE_HWSERIAL2 //Hack to get the code to compile on BlackPills
#define Serial2 Serial1
#endif
pSecondarySerial = &Serial2;
/*
***********************************************************************************************************
* Real Time clock for datalogging/time stamping

View File

@ -388,5 +388,12 @@ void ignitionSchedule8Interrupt(HardwareTimer*);
extern STM32_CAN Can0;
#endif
#define secondarySerial_AVAILABLE
#if defined(STM32GENERIC) // STM32GENERIC core
#define SECONDARY_SERIAL_T SerialUART
#else //libmaple core aka STM32DUINO
#define SECONDARY_SERIAL_T HardwareSerial
#endif
#endif //CORE_STM32
#endif //STM32_H

View File

@ -6,6 +6,7 @@
#include "idle.h"
#include "scheduler.h"
#include "timers.h"
#include "comms_secondary.h"
#if defined(__MK64FX512__) // use for Teensy 3.5 only
FlexCAN_T4<CAN0, RX_SIZE_256, TX_SIZE_16> Can0;
@ -20,6 +21,7 @@ void initBoard()
***********************************************************************************************************
* General
*/
pSecondarySerial = &Serial2;
/*
***********************************************************************************************************

View File

@ -155,7 +155,10 @@
***********************************************************************************************************
* CAN / Second serial
*/
#define USE_SERIAL3 // Secondary serial port to use
#define USE_SERIAL3 // Secondary serial port to use
#define secondarySerial_AVAILABLE
#define SECONDARY_SERIAL_T HardwareSerial
#include <FlexCAN_T4.h>
#if defined(__MK64FX512__) // use for Teensy 3.5 only
extern FlexCAN_T4<CAN0, RX_SIZE_256, TX_SIZE_16> Can0;

View File

@ -5,6 +5,7 @@
#include "idle.h"
#include "scheduler.h"
#include "timers.h"
#include "comms_secondary.h"
FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> Can0;
FlexCAN_T4<CAN2, RX_SIZE_256, TX_SIZE_16> Can1;
@ -22,6 +23,7 @@ void initBoard()
***********************************************************************************************************
* General
*/
pSecondarySerial = &Serial2;
/*
Idle + Boost + VVT use the PIT timer. THIS IS ALSO USED BY THE INTERVAL TIMER THAT CALLS THE 1MS LOW RES TIMER!

View File

@ -168,6 +168,9 @@
* CAN / Second serial
*/
#define USE_SERIAL3
#define secondarySerial_AVAILABLE
#define SECONDARY_SERIAL_T HardwareSerial
#include <FlexCAN_T4.h>
extern FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> Can0;
extern FlexCAN_T4<CAN2, RX_SIZE_256, TX_SIZE_16> Can1;

View File

@ -24,23 +24,10 @@ sendcancommand is called when a command is to be sent either to serial3
#include "comms_legacy.h"
#include "logger.h"
#include "page_crc.h"
#include BOARD_H
uint8_t currentSecondaryCommand;
#if ( defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) )
HardwareSerial &secondarySerial = Serial3;
#elif defined(CORE_STM32)
#ifndef HAVE_HWSERIAL2 //Hack to get the code to compile on BlackPills
#define Serial2 Serial1
#endif
#if defined(STM32GENERIC) // STM32GENERIC core
SerialUART &secondarySerial = Serial2;
#else //libmaple core aka STM32DUINO
HardwareSerial &secondarySerial = Serial2;
#endif
#elif defined(CORE_TEENSY)
HardwareSerial &secondarySerial = Serial2;
#endif
SECONDARY_SERIAL_T* pSecondarySerial;
void secondserial_Command(void)
{

View File

@ -10,23 +10,8 @@
#define SECONDARY_SERIAL_PROTO_MSDROID 3
#define SECONDARY_SERIAL_PROTO_REALDASH 4
#if ( defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) )
#define secondarySerial_AVAILABLE
extern HardwareSerial &secondarySerial;
#elif defined(CORE_STM32)
#define secondarySerial_AVAILABLE
#ifndef HAVE_HWSERIAL2 //Hack to get the code to compile on BlackPills
#define Serial2 Serial1
#endif
#if defined(STM32GENERIC) // STM32GENERIC core
extern SerialUART &secondarySerial;
#else //libmaple core aka STM32DUINO
extern HardwareSerial &secondarySerial;
#endif
#elif defined(CORE_TEENSY)
#define secondarySerial_AVAILABLE
extern HardwareSerial &secondarySerial;
#endif
extern SECONDARY_SERIAL_T *pSecondarySerial;
#define secondarySerial (*pSecondarySerial)
void secondserial_Command(void);//This is the heart of the Command Line Interpreter. All that needed to be done was to make it human readable.
void sendCancommand(uint8_t cmdtype , uint16_t canadddress, uint8_t candata1, uint8_t candata2, uint16_t sourcecanAddress);

View File

@ -117,10 +117,7 @@ void initialiseAll(void)
#endif
Serial.begin(115200);
BIT_SET(currentStatus.status4, BIT_STATUS4_ALLOW_LEGACY_COMMS); //Flag legacy comms as being allowed on startip
#if defined(secondarySerial_AVAILABLE)
if (configPage9.enable_secondarySerial == 1) { secondarySerial.begin(115200); }
#endif
BIT_SET(currentStatus.status4, BIT_STATUS4_ALLOW_LEGACY_COMMS); //Flag legacy comms as being allowed on startup
//Repoint the 2D table structs to the config pages that were just loaded
taeTable.valueSize = SIZE_BYTE; //Set this table to use byte values
@ -320,6 +317,11 @@ void initialiseAll(void)
Can0.setTX(DEF);
#endif
//Must come after setPinMapping() as secondary serial can be changed on a per board basis
#if defined(secondarySerial_AVAILABLE)
if (configPage9.enable_secondarySerial == 1) { secondarySerial.begin(115200); }
#endif
//End all coil charges to ensure no stray sparks on startup
endCoil1Charge();
endCoil2Charge();
@ -2333,9 +2335,21 @@ void setPinMapping(byte boardID)
pinInjector3 = 12; //MISO
pinInjector4 = 10; //CS for MC33810 1
pinInjector5 = 9; //CS for MC33810 2
pinInjector6 = 9; //CS for MC33810 3
//Dummy pins, without thes pin 0 (Serial1 RX) gets overwritten
pinCoil1 = 40;
pinCoil2 = 41;
/*
pinCoil3 = 55;
pinCoil4 = 55;
pinCoil5 = 55;
pinCoil6 = 55;
*/
pinTrigger = 19; //The CAS pin
pinTrigger2 = 18; //The Cam Sensor pin
pinTrigger3 = 22; //Uses one of the protected spare digitial inputs. This must be set or Serial1 (Pin 0) gets broken
pinFlex = A16; // Flex sensor
pinMAP = A1; //MAP sensor pin
pinBaro = A0; //Baro sensor pin
@ -2369,6 +2383,8 @@ void setPinMapping(byte boardID)
pinCLT = A20; //CLS sensor pin
pinO2 = A21; //O2 Sensor pin
pinO2_2 = A18; //Spare 2
pSecondarySerial = &Serial1; //Header that is broken out on Dropbear boards is attached to Serial1
#endif
#if defined(CORE_TEENSY41)

View File

@ -111,7 +111,7 @@ void loop(void)
//if can or secondary serial interface is enabled then check for requests.
if (configPage9.enable_secondarySerial == 1) //secondary serial interface enabled
{
if ( ((mainLoopCount & 31) == 1) or (secondarySerial.available() > SERIAL_BUFFER_THRESHOLD) )
if ( ((mainLoopCount & 31) == 1) || (secondarySerial.available() > SERIAL_BUFFER_THRESHOLD) )
{
if (secondarySerial.available() > 0) { secondserial_Command(); }
}