diff --git a/README.md b/README.md index 2faab39e..6429a74d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,24 @@ -# Arduino Core for SAM3X CPU +# Enhanced Arduino Core for SAM3X CPU + +This repository is based from the [Arduio Sam SDK for cortex-m3](https://github.com/arduino/ArduinoCore-sam). The sdk was modified to include the following features which are not supported by the main repository: + +- Attachment of a callback function to the IRQ handler of USART/UART peripherals. This comes handy when you need to process data in real-time. +- Addition of USART2 as Serial4. +- Updated GCC to version 11.2.1. +- Using by default C++20 and C17 + +## Installation + +Add the following url to your Arduino package manager + +``` +https://raw.githubusercontent.com/vChavezB/ArduinoBoards/master/SAM3X/package_vchavezb_sam-enhanced.json +``` + +--- +The rest of this readme has been kept unmodified and is as-is from the original repo. + +--- This repository contains the source code and configuration files of the Arduino Core for Atmel's SAM3X processor (used on the [Arduino Due](https://www.arduino.cc/en/Main/ArduinoBoardDue) board). diff --git a/boards.txt b/boards.txt index 55037861..2708af7c 100644 --- a/boards.txt +++ b/boards.txt @@ -1,5 +1,5 @@ -arduino_due_x_dbg.name=Arduino Due (Programming Port) +arduino_due_x_dbg.name=Arduino Due Enhanced (Programming Port) arduino_due_x_dbg.vid.0=0x2341 arduino_due_x_dbg.pid.0=0x003d arduino_due_x_dbg.vid.1=0x2A03 @@ -23,7 +23,7 @@ arduino_due_x_dbg.build.variant_system_lib=libsam_sam3x8e_gcc_rel.a arduino_due_x_dbg.build.vid=0x2341 arduino_due_x_dbg.build.pid=0x003e -arduino_due_x.name=Arduino Due (Native USB Port) +arduino_due_x.name=Arduino Due Enhanced (Native USB Port) arduino_due_x.vid.0=0x2341 arduino_due_x.pid.0=0x003e arduino_due_x.vid.1=0x2A03 diff --git a/cores/arduino/UARTClass.cpp b/cores/arduino/UARTClass.cpp index 36de1358..9efbe083 100644 --- a/cores/arduino/UARTClass.cpp +++ b/cores/arduino/UARTClass.cpp @@ -66,7 +66,7 @@ void UARTClass::init(const uint32_t dwBaudRate, const uint32_t modeReg) // Configure interrupts _pUart->UART_IDR = 0xFFFFFFFF; _pUart->UART_IER = UART_IER_RXRDY | UART_IER_OVRE | UART_IER_FRAME; - + // Enable UART interrupt in NVIC NVIC_EnableIRQ(_dwIrq); @@ -172,7 +172,14 @@ void UARTClass::IrqHandler( void ) // Did we receive data? if ((status & UART_SR_RXRDY) == UART_SR_RXRDY) - _rx_buffer->store_char(_pUart->UART_RHR); + { + uint8_t uart_rx_frame=_pUart->UART_RHR; + _rx_buffer->store_char(uart_rx_frame); + if(pRx_irq_cb != nullptr) + { + pRx_irq_cb(uart_rx_frame,rx_irq_args); + } + } // Do we need to keep sending data? if ((status & UART_SR_TXRDY) == UART_SR_TXRDY) @@ -196,3 +203,8 @@ void UARTClass::IrqHandler( void ) } } +void UARTClass::attachRxIrq(rx_irq_cb cb,void * args) +{ + pRx_irq_cb = cb; + rx_irq_args = args; +} diff --git a/cores/arduino/UARTClass.h b/cores/arduino/UARTClass.h index 3747d8be..a85fc384 100644 --- a/cores/arduino/UARTClass.h +++ b/cores/arduino/UARTClass.h @@ -59,7 +59,10 @@ class UARTClass : public HardwareSerial uint32_t getInterruptPriority(); void IrqHandler(void); - + typedef void (*rx_irq_cb)(uint8_t frame,void * args); + + void attachRxIrq(rx_irq_cb cb,void * args); + operator bool() { return true; }; // UART always active protected: @@ -69,6 +72,8 @@ class UARTClass : public HardwareSerial RingBuffer *_tx_buffer; Uart* _pUart; + rx_irq_cb pRx_irq_cb; + void * rx_irq_args; IRQn_Type _dwIrq; uint32_t _dwId; diff --git a/cores/arduino/new.cpp b/cores/arduino/new.cpp index f1897758..746bc338 100644 --- a/cores/arduino/new.cpp +++ b/cores/arduino/new.cpp @@ -34,3 +34,14 @@ void operator delete[](void * ptr) { free(ptr); } +/* +Fix for C++>14 +https://forum.arduino.cc/t/undefined-reference-to-operator-delete-void-unsigned-int/620428 +*/ +void operator delete(void* ptr, std::size_t) _GLIBCXX_USE_NOEXCEPT { + delete ptr; +} + +void operator delete[](void* ptr, std::size_t) _GLIBCXX_USE_NOEXCEPT { + delete[] ptr; +} diff --git a/platform.txt b/platform.txt index 5a330240..cab922ef 100644 --- a/platform.txt +++ b/platform.txt @@ -17,15 +17,15 @@ compiler.warning_flags.default= compiler.warning_flags.more=-Wall compiler.warning_flags.all=-Wall -Wextra -compiler.path={runtime.tools.arm-none-eabi-gcc-4.8.3-2014q1.path}/bin/ +compiler.path={runtime.tools.arm-none-eabi-gcc-11.2.1-xpack.path}/bin/ compiler.c.cmd=arm-none-eabi-gcc -compiler.c.flags=-c -g -Os {compiler.warning_flags} -std=gnu11 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -Dprintf=iprintf -MMD +compiler.c.flags=-c -g -Os {compiler.warning_flags} -std=gnu17 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -Dprintf=iprintf -MMD compiler.c.elf.cmd=arm-none-eabi-gcc compiler.c.elf.flags=-Os -Wl,--gc-sections compiler.S.cmd=arm-none-eabi-gcc compiler.S.flags=-c -g -x assembler-with-cpp -MMD compiler.cpp.cmd=arm-none-eabi-g++ -compiler.cpp.flags=-c -g -Os {compiler.warning_flags} -std=gnu++11 -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD +compiler.cpp.flags=-c -g -Os {compiler.warning_flags} -std=gnu++20 -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD compiler.ar.cmd=arm-none-eabi-ar compiler.ar.flags=rcs compiler.objcopy.cmd=arm-none-eabi-objcopy diff --git a/variants/arduino_due_x/variant.cpp b/variants/arduino_due_x/variant.cpp index 7a0de80a..34ad3096 100644 --- a/variants/arduino_due_x/variant.cpp +++ b/variants/arduino_due_x/variant.cpp @@ -286,12 +286,12 @@ extern const PinDescription g_APinDescription[]= { PIOA, PIO_PA1A_CANRX0|PIO_PA0A_CANTX0, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_COMBO), NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // 91 - CAN1 all pins { PIOB, PIO_PB15A_CANRX1|PIO_PB14A_CANTX1, ID_PIOB, PIO_PERIPH_A, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_COMBO), NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, - + // 92 - USART2 (Serial4) all pins + { PIOB, PIO_PB20A_TXD2|PIO_PB21A_RXD2, ID_PIOB, PIO_PERIPH_A, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_COMBO), NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER }, // END { NULL, 0, 0, PIO_NOT_A_PIN, PIO_DEFAULT, 0, NO_ADC, NO_ADC, NOT_ON_PWM, NOT_ON_TIMER } } ; - uint8_t g_pinStatus[PINS_COUNT] = {0}; #ifdef __cplusplus @@ -321,9 +321,11 @@ void UART_Handler(void) RingBuffer rx_buffer2; RingBuffer rx_buffer3; RingBuffer rx_buffer4; +RingBuffer rx_buffer5; RingBuffer tx_buffer2; RingBuffer tx_buffer3; RingBuffer tx_buffer4; +RingBuffer tx_buffer5; USARTClass Serial1(USART0, USART0_IRQn, ID_USART0, &rx_buffer2, &tx_buffer2); void serialEvent1() __attribute__((weak)); @@ -334,6 +336,9 @@ void serialEvent2() { } USARTClass Serial3(USART3, USART3_IRQn, ID_USART3, &rx_buffer4, &tx_buffer4); void serialEvent3() __attribute__((weak)); void serialEvent3() { } +USARTClass Serial4(USART2, USART2_IRQn, ID_USART2, &rx_buffer5, &tx_buffer5); +void serialEvent4() __attribute__((weak)); +void serialEvent4() { } // IT handlers void USART0_Handler(void) @@ -351,6 +356,11 @@ void USART3_Handler(void) Serial3.IrqHandler(); } +void USART2_Handler(void) +{ + Serial4.IrqHandler(); +} + // ---------------------------------------------------------------------------- void serialEventRun(void) @@ -359,6 +369,7 @@ void serialEventRun(void) if (Serial1.available()) serialEvent1(); if (Serial2.available()) serialEvent2(); if (Serial3.available()) serialEvent3(); + if (Serial4.available()) serialEvent4(); } // ---------------------------------------------------------------------------- @@ -415,6 +426,12 @@ void init( void ) g_APinDescription[PINS_USART3].ulPinType, g_APinDescription[PINS_USART3].ulPin, g_APinDescription[PINS_USART3].ulPinConfiguration); + + PIO_Configure( + g_APinDescription[PINS_USART2].pPort, + g_APinDescription[PINS_USART2].ulPinType, + g_APinDescription[PINS_USART2].ulPin, + g_APinDescription[PINS_USART2].ulPinConfiguration); // Initialize USB pins PIO_Configure( diff --git a/variants/arduino_due_x/variant.h b/variants/arduino_due_x/variant.h index 922b40b4..ad43b9e8 100644 --- a/variants/arduino_due_x/variant.h +++ b/variants/arduino_due_x/variant.h @@ -170,7 +170,8 @@ static const uint8_t SCL1 = PIN_WIRE1_SCL; #define PINS_USART1 (83u) // Serial3 #define PINS_USART3 (84u) - +// Serial4 +#define PINS_USART2 (92u) /* * USB Interfaces */ @@ -252,7 +253,7 @@ extern UARTClass Serial; extern USARTClass Serial1; extern USARTClass Serial2; extern USARTClass Serial3; - +extern USARTClass Serial4; #endif // These serial port names are intended to allow libraries and architecture-neutral