From fc1663e5d3845a183a3066ec0000cfcc47347e9f Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Thu, 21 May 2020 15:42:02 +1000 Subject: [PATCH] Fix compiling for atmega2561 and add profile for it --- .travis.yml | 2 +- platformio.ini | 10 +++++++++ speeduino/cancomms.h | 5 ++++- speeduino/cancomms.ino | 45 +++++++++++++++++++++++------------------ speeduino/comms.ino | 4 +++- speeduino/globals.h | 13 ++++++++++++ speeduino/idle.ino | 2 +- speeduino/init.ino | 2 +- speeduino/speeduino.ino | 28 +++++++++++++------------ 9 files changed, 73 insertions(+), 38 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9723a008..baa78e3d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -58,7 +58,7 @@ script: - cd noisymime/speeduino - platformio update # Run the builds (Mega must be last so that the hex file isn't cleaned up) - - platformio run -e teensy35 -e teensy40 -e megaatmega2560 + - platformio run -e teensy35 -e teensy40 -e megaatmega2561 -e megaatmega2560 # Run the remote unit tests (only on master) - 'if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then platformio remote test --environment megaatmega2560; fi' # Uploading the firmware to speeduino.com (Only on master) diff --git a/platformio.ini b/platformio.ini index 715dff8d..118c11e7 100644 --- a/platformio.ini +++ b/platformio.ini @@ -16,6 +16,16 @@ build_unflags = -Os build_flags = -O3 -ffast-math -Wall -Wextra -std=c99 lib_deps = EEPROM test_build_project_src = true +debug_tool = simavr + +[env:megaatmega2561] +platform=atmelavr +board=atmega2561 +framework=arduino +build_unflags = -Os +build_flags = -O3 -ffast-math -Wall -Wextra -std=c99 +lib_deps = EEPROM +test_build_project_src = true [env:teensy35] platform=teensy diff --git a/speeduino/cancomms.h b/speeduino/cancomms.h index 3f59bfac..8d1a11fa 100644 --- a/speeduino/cancomms.h +++ b/speeduino/cancomms.h @@ -14,9 +14,11 @@ uint8_t Gdata[9]; uint8_t Glow, Ghigh; bool canCmdPending = false; -#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) +#if ( defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) ) + #define CANSerial_AVAILABLE HardwareSerial &CANSerial = Serial3; #elif defined(CORE_STM32) + #define CANSerial_AVAILABLE #ifndef Serial2 #define Serial2 Serial1 #endif @@ -26,6 +28,7 @@ bool canCmdPending = false; HardwareSerial &CANSerial = Serial2; #endif #elif defined(CORE_TEENSY) + #define CANSerial_AVAILABLE HardwareSerial &CANSerial = Serial2; #endif diff --git a/speeduino/cancomms.ino b/speeduino/cancomms.ino index 1214ffc8..fcd6bdbf 100644 --- a/speeduino/cancomms.ino +++ b/speeduino/cancomms.ino @@ -23,6 +23,7 @@ sendcancommand is called when a command is to be sent either to serial3 void secondserial_Command() { + #if defined(CANSerial_AVAILABLE) if (! canCmdPending) { currentsecondserialCommand = CANSerial.read(); } switch (currentsecondserialCommand) @@ -81,27 +82,27 @@ void secondserial_Command() canlisten = CANSerial.read(); if (canlisten == 0) - { + { //command request failed and/or data/device was not available break; - } + } - while (CANSerial.available() == 0) { } - Llength= CANSerial.read(); // next the number of bytes expected value + while (CANSerial.available() == 0) { } + Llength= CANSerial.read(); // next the number of bytes expected value - for (uint8_t Lcount = 0; Lcount = 6) { @@ -118,7 +119,7 @@ void secondserial_Command() length = word(CANSerial.read(), tmp); sendcanValues(offset, length,Cmd, 1); canCmdPending = false; -//Serial.print(Cmd); + //Serial.print(Cmd); } else { @@ -129,12 +130,11 @@ void secondserial_Command() { canCmdPending = true; } - break; case 's': // send the "a" stream code version CANSerial.print(F("Speeduino csx02019.8")); - break; + break; case 'S': // send code version CANSerial.print(F("Speeduino 2019.08-ser")); @@ -155,6 +155,7 @@ void secondserial_Command() default: break; } + #endif } void sendcanValues(uint16_t offset, uint16_t packetLength, byte cmd, byte portType) { @@ -271,11 +272,13 @@ void sendcanValues(uint16_t offset, uint16_t packetLength, byte cmd, byte portTy for(byte x=0; x SERIAL_BUFFER_THRESHOLD) ) { - if ( ((mainLoopCount & 31) == 1) or (CANSerial.available() > SERIAL_BUFFER_THRESHOLD) ) - { - if (CANSerial.available() > 0) { secondserial_Command(); } - } + if (CANSerial.available() > 0) { secondserial_Command(); } } - #if defined(CORE_TEENSY) + } + #endif + #if defined(CORE_TEENSY) //currentStatus.canin[12] = configPage9.enable_intcan; if (configPage9.enable_intcan == 1) // use internal can module { //check local can module // if ( BIT_CHECK(LOOP_TIMER, BIT_TIMER_15HZ) or (CANbus0.available()) while (Can0.read(inMsg) ) - { - can_Command(); - //Can0.read(inMsg); - //currentStatus.canin[12] = inMsg.buf[5]; - //currentStatus.canin[13] = inMsg.id; - } + { + can_Command(); + //Can0.read(inMsg); + //currentStatus.canin[12] = inMsg.buf[5]; + //currentStatus.canin[13] = inMsg.id; + } } #endif