From bc930debfaf654f7c230a1ddbf18dc100e3a19e2 Mon Sep 17 00:00:00 2001 From: chiararuggeri Date: Tue, 30 May 2017 13:14:47 +0200 Subject: [PATCH 1/4] Added Primo Core Platform to nrf52 core --- boards.txt | 30 +++ cores/arduino/WVariant.h | 2 + cores/arduino/wiring_analog.c | 7 +- cores/arduino/wiring_digital.c | 23 ++- libraries/CIR/cir.h | 4 + libraries/SPI/SPI.cpp | 15 ++ libraries/SPI/SPI.h | 8 +- .../BarometricPressureSensor.ino | 9 + .../DigitalPotControl/DigitalPotControl.ino | 13 +- .../SPI/examples/MasterSend/MasterSend.ino | 10 + .../examples/SlaveReceive/SlaveReceive.ino | 11 ++ .../linker_scripts/gcc/flash.ld | 177 ++++++++++++++++++ .../gcc/flash_without_softdevice.ld | 177 ++++++++++++++++++ .../openocd_scripts/arduino_primo.cfg | 6 + variants/arduino_primo_core/pins_arduino.h | 20 ++ variants/arduino_primo_core/variant.cpp | 143 ++++++++++++++ variants/arduino_primo_core/variant.h | 120 ++++++++++++ 17 files changed, 770 insertions(+), 5 deletions(-) create mode 100644 variants/arduino_primo_core/linker_scripts/gcc/flash.ld create mode 100644 variants/arduino_primo_core/linker_scripts/gcc/flash_without_softdevice.ld create mode 100644 variants/arduino_primo_core/openocd_scripts/arduino_primo.cfg create mode 100644 variants/arduino_primo_core/pins_arduino.h create mode 100644 variants/arduino_primo_core/variant.cpp create mode 100644 variants/arduino_primo_core/variant.h diff --git a/boards.txt b/boards.txt index 04f4ce0..661db88 100644 --- a/boards.txt +++ b/boards.txt @@ -38,4 +38,34 @@ primo.build.pid=0x805a #primo.bootloader.file= primo.firmware.softdevice.file=primo/softdevice/s132_nrf52_2.0.0_softdevice.hex + ##################################### +########### ARDUINO PRIMO ########### + +primo_core.name=Arduino Primo Core + +#primo_core.menu.upload.serial=via Serial +#primo_core.menu.upload.bluetooth=via Bluetooth +#primo_core.menu.upload.bluetooth.upload.tool=otable + +primo_core.upload.tool=openocd +primo_core.upload.protocol=sam-ba +primo_core.upload.maximum_size=409600 +primo_core.upload.use_1200bps_touch=false +primo_core.upload.speed=115200 +primo_core.upload.wait_for_upload_port=false + +primo_core.build.mcu=cortex-m4 +primo_core.build.f_cpu=64000000L +primo_core.build.usb_product="Arduino Primo Core" +primo_core.build.board=NRF52_PRIMO_CORE +primo_core.build.core=arduino +primo_core.build.extra_flags=-mthumb +primo_core.build.ldscript=linker_scripts/gcc/flash.ld +primo_core.build.openocdscript=openocd_scripts/arduino_primo.cfg +primo_core.build.variant=arduino_primo_core +primo_core.build.components=components + +#new defined attributes +#primo_core.bootloader.file= +primo_core.firmware.softdevice.file=primo/softdevice/s132_nrf52_2.0.0_softdevice.hex diff --git a/cores/arduino/WVariant.h b/cores/arduino/WVariant.h index 3a53647..6aefb23 100644 --- a/cores/arduino/WVariant.h +++ b/cores/arduino/WVariant.h @@ -20,6 +20,8 @@ typedef enum _EAnalogChannel ADC_A3=SAADC_CH_PSELP_PSELP_AnalogInput5, ADC_A4=SAADC_CH_PSELP_PSELP_AnalogInput6, ADC_A5=SAADC_CH_PSELP_PSELP_AnalogInput7, + ADC_A6=SAADC_CH_PSELP_PSELP_AnalogInput0, + ADC_A7=SAADC_CH_PSELP_PSELP_AnalogInput3 } EAnalogChannel ; typedef enum _ETCChannel diff --git a/cores/arduino/wiring_analog.c b/cores/arduino/wiring_analog.c index 98ac994..cef30e3 100644 --- a/cores/arduino/wiring_analog.c +++ b/cores/arduino/wiring_analog.c @@ -87,11 +87,16 @@ void analogReference( uint8_t ulMode ) uint32_t analogRead( uint32_t ulPin ){ static int16_t valueRead[1]; +#ifdef ARDUINO_NRF52_PRIMO if((ulPin >= 0) && (ulPin <= 5)) ulPin = ulPin + 14; - //no analogRead for digital pin + // no analogRead for digital pin else if(ulPin<=13) return 0; +#elif defined ARDUINO_NRF52_PRIMO_CORE + if(ulPin > 7) + return 0; +#endif //enable ADC NRF_SAADC->ENABLE = SAADC_ENABLE_ENABLE_Enabled << SAADC_ENABLE_ENABLE_Pos; diff --git a/cores/arduino/wiring_digital.c b/cores/arduino/wiring_digital.c index 817518e..941131e 100755 --- a/cores/arduino/wiring_digital.c +++ b/cores/arduino/wiring_digital.c @@ -47,7 +47,7 @@ uint8_t read_char[] = {0,0}; bool transmissionBegun; uint8_t suspended=0; - +#ifdef ARDUINO_NRF52_PRIMO void TwoWire_begin(void) { //Master Mode _TWIInstance=NRF_TWIM1; @@ -225,11 +225,14 @@ int TwoWire_read(void) } } +#endif //ARDUINO_NRF52_PRIMO /////////////////////////////////////////////////////////////////////// void pinMode( uint32_t ulPin, uint32_t ulMode ) { +#ifdef ARDUINO_NRF52_PRIMO + if ( (ulPin == 34) && (ulMode == STM32_IT) ) { nrf_delay_ms(15); @@ -249,6 +252,8 @@ void pinMode( uint32_t ulPin, uint32_t ulMode ) TwoWire_endTransmission(); return ; } + +#endif //ARDUINO_NRF52_PRIMO if ( g_APinDescription[ulPin].ulPinType == PIO_NOT_A_PIN ) { @@ -285,6 +290,15 @@ void pinMode( uint32_t ulPin, uint32_t ulMode ) void digitalWrite( uint32_t ulPin, uint32_t ulVal ) { + +// in Primo Core leds have an inverted logic. Reverse ulVal in order to restore the normal logic +#ifdef ARDUINO_NRF52_PRIMO_CORE + if(ulPin == 10 || ulPin == 11 || ulPin == 12 || ulPin == 13) + ulVal = !ulVal; +#endif //ARDUINO_NRF52_PRIMO_CORE + +#ifdef ARDUINO_NRF52_PRIMO + switch ( ulPin ) { case 38: @@ -382,6 +396,8 @@ void digitalWrite( uint32_t ulPin, uint32_t ulVal ) break ; } +#endif //ARDUINO_NRF52_PRIMO + if ( ulPin >= 38 && ulPin <= 42) { return ; @@ -403,6 +419,9 @@ void digitalWrite( uint32_t ulPin, uint32_t ulVal ) int digitalRead( uint32_t ulPin ) { + +#ifdef ARDUINO_NRF52_PRIMO + switch ( ulPin ) { case 44: @@ -428,6 +447,8 @@ int digitalRead( uint32_t ulPin ) break ; } +#endif //ARDUINO_NRF52_PRIMO + /* Handle the case the pin isn't usable as PIO */ if ( g_APinDescription[ulPin].ulPinType == PIO_NOT_A_PIN ) { diff --git a/libraries/CIR/cir.h b/libraries/CIR/cir.h index 98b6da9..5c249a6 100644 --- a/libraries/CIR/cir.h +++ b/libraries/CIR/cir.h @@ -27,6 +27,10 @@ #ifndef __CIR_H__ #define __CIR_H__ +#ifdef ARDUINO_NRF52_PRIMO_CORE +#error "CIR library is not compatible with Arduino Primo Core" +#endif //ARDUINO_NRF52_PRIMO_CORE + #include #include #include "Arduino.h" diff --git a/libraries/SPI/SPI.cpp b/libraries/SPI/SPI.cpp index b166129..4f5ecfc 100644 --- a/libraries/SPI/SPI.cpp +++ b/libraries/SPI/SPI.cpp @@ -27,6 +27,19 @@ SPIClass::SPIClass(NRF_SPI_Type *SPIInstance, uint8_t uc_pinMISO, uint8_t uc_pin _uc_pinMosi = g_APinDescription[uc_pinMOSI].ulPin; } +#ifdef ARDUINO_NRF52_PRIMO_CORE + +SPIClass::SPIClass(int uc_pinMISO, int uc_pinMOSI, int uc_pinSCK){ + _SPIInstance = NRF_SPI2; + + _uc_pinMiso = g_APinDescription[uc_pinMISO].ulPin; + _uc_pinSCK = g_APinDescription[uc_pinSCK].ulPin; + _uc_pinMosi = g_APinDescription[uc_pinMOSI].ulPin; +} + +#endif //ARDUINO_NRF52_PRIMO_CORE + + void SPIClass::begin() { pinMode(_uc_pinSCK, OUTPUT); @@ -334,4 +347,6 @@ void SPIClass::detachInterrupt(void) // Should be disableInterrupt() } +#ifdef ARDUINO_NRF52_PRIMO SPIClass SPI(NRF_SPI2, PIN_SPI_MISO, PIN_SPI_SCK, PIN_SPI_MOSI); +#endif //ARDUINO_NRF52_PRIMO \ No newline at end of file diff --git a/libraries/SPI/SPI.h b/libraries/SPI/SPI.h index a76557e..f015544 100644 --- a/libraries/SPI/SPI.h +++ b/libraries/SPI/SPI.h @@ -83,6 +83,10 @@ class SPIClass { public: SPIClass(NRF_SPI_Type *SPIInstance, uint8_t uc_pinMISO, uint8_t uc_pinSCK, uint8_t uc_pinMOSI); +#ifdef ARDUINO_NRF52_PRIMO_CORE + SPIClass(int uc_pinMISO, int uc_pinMOSI, int uc_pinSCK); +#endif + byte transfer(uint8_t data); void transfer(void *data, size_t count); byte read(void); @@ -117,6 +121,8 @@ class SPIClass { uint8_t inTransactionFlag; }; +#ifdef ARDUINO_NRF52_PRIMO extern SPIClass SPI; +#endif //ARDUINO_NRF52_PRIMO -#endif +#endif //_SPI_H_INCLUDED \ No newline at end of file diff --git a/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino b/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino index 8104fcb..c463655 100644 --- a/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino +++ b/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino @@ -25,6 +25,15 @@ // the sensor communicates using SPI, so include the library: #include +#ifdef ARDUINO_NRF52_PRIMO_CORE + // Arduino Primo Core doesn't have fixed SPI pins. You can choose whatever pins you prefer. + #define MISO 3 + #define MOSI 4 + #define SCK 5 + + SPIClass SPI(MISO, MOSI, SCK); +#endif //ARDUINO_NRF52_PRIMO_CORE + //Sensor's memory register addresses: const int PRESSURE = 0x1F; //3 most significant bits of pressure const int PRESSURE_LSB = 0x20; //16 least significant bits of pressure diff --git a/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino b/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino index b135a74..fcdd6bc 100644 --- a/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino +++ b/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino @@ -30,9 +30,18 @@ // inslude the SPI library: #include +#ifdef ARDUINO_NRF52_PRIMO_CORE + // Arduino Primo Core doesn't have fixed SPI pins. You can choose whatever pins you prefer. + #define MISO 4 + #define MOSI 5 + #define SCK 6 -// set pin 10 as the slave select for the digital pot: -const int slaveSelectPin = 10; + SPIClass SPI(MISO, MOSI, SCK); +#endif //ARDUINO_NRF52_PRIMO_CORE + + +// set pin 7 as the slave select for the digital pot: +const int slaveSelectPin = 7; void setup() { // set the slaveSelectPin as an output: diff --git a/libraries/SPI/examples/MasterSend/MasterSend.ino b/libraries/SPI/examples/MasterSend/MasterSend.ino index d014fed..49c7079 100644 --- a/libraries/SPI/examples/MasterSend/MasterSend.ino +++ b/libraries/SPI/examples/MasterSend/MasterSend.ino @@ -9,6 +9,16 @@ GND -> GND #include +#ifdef ARDUINO_NRF52_PRIMO_CORE + // Arduino Primo Core doesn't have fixed SPI pins. You can choose whatever pins you prefer. + #define MISO 4 + #define MOSI 5 + #define SCK 6 + #define SS 7 + + SPIClass SPI(MISO, MOSI, SCK); +#endif //ARDUINO_NRF52_PRIMO_CORE + #define DIM 11 void setup() { diff --git a/libraries/SPI/examples/SlaveReceive/SlaveReceive.ino b/libraries/SPI/examples/SlaveReceive/SlaveReceive.ino index f729395..c49f6f2 100644 --- a/libraries/SPI/examples/SlaveReceive/SlaveReceive.ino +++ b/libraries/SPI/examples/SlaveReceive/SlaveReceive.ino @@ -9,6 +9,17 @@ GND -> GND #include +#ifdef ARDUINO_NRF52_PRIMO_CORE + // Arduino Primo Core doesn't have fixed SPI pins. You can choose whatever pins you prefer. + #define MISO 4 + #define MOSI 5 + #define SCK 6 + #define SS 7 + + SPIClass SPI(MISO, MOSI, SCK); +#endif //ARDUINO_NRF52_PRIMO_CORE + + #define DIM 11 uint8_t data[DIM]; diff --git a/variants/arduino_primo_core/linker_scripts/gcc/flash.ld b/variants/arduino_primo_core/linker_scripts/gcc/flash.ld new file mode 100644 index 0000000..e3d443f --- /dev/null +++ b/variants/arduino_primo_core/linker_scripts/gcc/flash.ld @@ -0,0 +1,177 @@ +/* Linker script for Nordic Semiconductor nRF51 devices + * + * Version: Sourcery G++ 4.5-1 + * Support: https://support.codesourcery.com/GNUToolchain/ + * + * Copyright (c) 2007, 2008, 2009, 2010 CodeSourcery, Inc. + * + * The authors hereby grant permission to use, copy, modify, distribute, + * and license this software and its documentation for any purpose, provided + * that existing copyright notices are retained in all copies and that this + * notice is included verbatim in any distributions. No written agreement, + * license, or royalty fee is required for any of the authorized uses. + * Modifications to this software may be copyrighted by their authors + * and need not follow the licensing terms described here, provided that + * the new terms are clearly indicated on the first page of each file where + * they apply. + */ +OUTPUT_FORMAT ("elf32-littlearm", "elf32-bigarm", "elf32-littlearm") + +/* Linker script to place sections and symbol values. + * It references following symbols, which must be defined in code: + * Reset_Handler : Entry of reset handler + * + * It defines following symbols, which code can use without definition: + * __exidx_start + * __exidx_end + * __etext + * __data_start__ + * __preinit_array_start + * __preinit_array_end + * __init_array_start + * __init_array_end + * __fini_array_start + * __fini_array_end + * __data_end__ + * __bss_start__ + * __bss_end__ + * __end__ + * end + * __HeapLimit + * __StackLimit + * __StackTop + * __stack + */ + +SEARCH_DIR(.) +GROUP(-lgcc -lc -lnosys) + +MEMORY +{ + FLASH (rx) : ORIGIN = 0x1c000, LENGTH = 0x64000 + RAM (rwx) : ORIGIN = 0x20004000, LENGTH = 0xc000 +} + +ENTRY(Reset_Handler) + +SECTIONS +{ + .text : + { + KEEP(*(.isr_vector)) + *(.text*) + + KEEP(*(.init)) + KEEP(*(.fini)) + + /* .ctors */ + *crtbegin.o(.ctors) + *crtbegin?.o(.ctors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) + *(SORT(.ctors.*)) + *(.ctors) + + /* .dtors */ + *crtbegin.o(.dtors) + *crtbegin?.o(.dtors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) + *(SORT(.dtors.*)) + *(.dtors) + + *(.rodata*) + + KEEP(*(.eh_frame*)) + } > FLASH + + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > FLASH + + __exidx_start = .; + .ARM.exidx : + { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + } > FLASH + __exidx_end = .; + + __etext = .; + + .data : AT (__etext) + { + __data_start__ = .; + *(vtable) + *(.data*) + + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP(*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + + . = ALIGN(4); + /* init data */ + PROVIDE_HIDDEN (__init_array_start = .); + KEEP(*(SORT(.init_array.*))) + KEEP(*(.init_array)) + PROVIDE_HIDDEN (__init_array_end = .); + + + . = ALIGN(4); + /* finit data */ + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP(*(SORT(.fini_array.*))) + KEEP(*(.fini_array)) + PROVIDE_HIDDEN (__fini_array_end = .); + + KEEP(*(.jcr*)) + . = ALIGN(4); + /* All data end */ + __data_end__ = .; + + } > RAM + + .fs_data : + { + PROVIDE(__start_fs_data = .); + KEEP(*(.fs_data)) + PROVIDE(__stop_fs_data = .); + } > RAM + + .bss : + { + . = ALIGN(4); + __bss_start__ = .; + *(.bss*) + *(COMMON) + . = ALIGN(4); + __bss_end__ = .; + } > RAM + + .heap (COPY): + { + __end__ = .; + PROVIDE(end = .); + *(.heap*) + __HeapLimit = .; + } > RAM + + /* .stack_dummy section doesn't contains any symbols. It is only + * used for linker to calculate size of stack sections, and assign + * values to stack symbols later */ + .stack_dummy (COPY): + { + *(.stack*) + } > RAM + + /* Set stack top to end of RAM, and stack limit move down by + * size of stack_dummy section */ + __StackTop = ORIGIN(RAM) + LENGTH(RAM); + __StackLimit = __StackTop - SIZEOF(.stack_dummy); + PROVIDE(__stack = __StackTop); + + __ram_end__ = ORIGIN(RAM) + LENGTH(RAM) -1 ; + + /* Check if data + heap + stack exceeds RAM limit */ + ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack") +} diff --git a/variants/arduino_primo_core/linker_scripts/gcc/flash_without_softdevice.ld b/variants/arduino_primo_core/linker_scripts/gcc/flash_without_softdevice.ld new file mode 100644 index 0000000..80152a3 --- /dev/null +++ b/variants/arduino_primo_core/linker_scripts/gcc/flash_without_softdevice.ld @@ -0,0 +1,177 @@ +/* Linker script for Nordic Semiconductor nRF51 devices + * + * Version: Sourcery G++ 4.5-1 + * Support: https://support.codesourcery.com/GNUToolchain/ + * + * Copyright (c) 2007, 2008, 2009, 2010 CodeSourcery, Inc. + * + * The authors hereby grant permission to use, copy, modify, distribute, + * and license this software and its documentation for any purpose, provided + * that existing copyright notices are retained in all copies and that this + * notice is included verbatim in any distributions. No written agreement, + * license, or royalty fee is required for any of the authorized uses. + * Modifications to this software may be copyrighted by their authors + * and need not follow the licensing terms described here, provided that + * the new terms are clearly indicated on the first page of each file where + * they apply. + */ +OUTPUT_FORMAT ("elf32-littlearm", "elf32-bigarm", "elf32-littlearm") + +/* Linker script to place sections and symbol values. + * It references following symbols, which must be defined in code: + * Reset_Handler : Entry of reset handler + * + * It defines following symbols, which code can use without definition: + * __exidx_start + * __exidx_end + * __etext + * __data_start__ + * __preinit_array_start + * __preinit_array_end + * __init_array_start + * __init_array_end + * __fini_array_start + * __fini_array_end + * __data_end__ + * __bss_start__ + * __bss_end__ + * __end__ + * end + * __HeapLimit + * __StackLimit + * __StackTop + * __stack + */ + +SEARCH_DIR(.) +GROUP(-lgcc -lc -lnosys) + +MEMORY +{ + FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00080000 + RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00010000 +} + +ENTRY(Reset_Handler) + +SECTIONS +{ + .text : + { + KEEP(*(.isr_vector)) + *(.text*) + + KEEP(*(.init)) + KEEP(*(.fini)) + + /* .ctors */ + *crtbegin.o(.ctors) + *crtbegin?.o(.ctors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) + *(SORT(.ctors.*)) + *(.ctors) + + /* .dtors */ + *crtbegin.o(.dtors) + *crtbegin?.o(.dtors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) + *(SORT(.dtors.*)) + *(.dtors) + + *(.rodata*) + + KEEP(*(.eh_frame*)) + } > FLASH + + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > FLASH + + __exidx_start = .; + .ARM.exidx : + { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + } > FLASH + __exidx_end = .; + + __etext = .; + + .data : AT (__etext) + { + __data_start__ = .; + *(vtable) + *(.data*) + + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP(*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + + . = ALIGN(4); + /* init data */ + PROVIDE_HIDDEN (__init_array_start = .); + KEEP(*(SORT(.init_array.*))) + KEEP(*(.init_array)) + PROVIDE_HIDDEN (__init_array_end = .); + + + . = ALIGN(4); + /* finit data */ + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP(*(SORT(.fini_array.*))) + KEEP(*(.fini_array)) + PROVIDE_HIDDEN (__fini_array_end = .); + + KEEP(*(.jcr*)) + . = ALIGN(4); + /* All data end */ + __data_end__ = .; + + } > RAM + + .fs_data : + { + PROVIDE(__start_fs_data = .); + KEEP(*(.fs_data)) + PROVIDE(__stop_fs_data = .); + } > RAM + + .bss : + { + . = ALIGN(4); + __bss_start__ = .; + *(.bss*) + *(COMMON) + . = ALIGN(4); + __bss_end__ = .; + } > RAM + + .heap (COPY): + { + __end__ = .; + PROVIDE(end = .); + *(.heap*) + __HeapLimit = .; + } > RAM + + /* .stack_dummy section doesn't contains any symbols. It is only + * used for linker to calculate size of stack sections, and assign + * values to stack symbols later */ + .stack_dummy (COPY): + { + *(.stack*) + } > RAM + + /* Set stack top to end of RAM, and stack limit move down by + * size of stack_dummy section */ + __StackTop = ORIGIN(RAM) + LENGTH(RAM); + __StackLimit = __StackTop - SIZEOF(.stack_dummy); + PROVIDE(__stack = __StackTop); + + __ram_end__ = ORIGIN(RAM) + LENGTH(RAM) -1 ; + + /* Check if data + heap + stack exceeds RAM limit */ + ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack") +} diff --git a/variants/arduino_primo_core/openocd_scripts/arduino_primo.cfg b/variants/arduino_primo_core/openocd_scripts/arduino_primo.cfg new file mode 100644 index 0000000..845bc5f --- /dev/null +++ b/variants/arduino_primo_core/openocd_scripts/arduino_primo.cfg @@ -0,0 +1,6 @@ +# +# Arduino Primo board (nRF52832) +# + +source [find interface/cmsis-dap.cfg] +source [find target/nrf52.cfg] diff --git a/variants/arduino_primo_core/pins_arduino.h b/variants/arduino_primo_core/pins_arduino.h new file mode 100644 index 0000000..b7d6e84 --- /dev/null +++ b/variants/arduino_primo_core/pins_arduino.h @@ -0,0 +1,20 @@ +/* + Copyright (c) 2016 Arduino Srl. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +// API compatibility +#include "variant.h" \ No newline at end of file diff --git a/variants/arduino_primo_core/variant.cpp b/variants/arduino_primo_core/variant.cpp new file mode 100644 index 0000000..9790397 --- /dev/null +++ b/variants/arduino_primo_core/variant.cpp @@ -0,0 +1,143 @@ +/* + Copyright (c) 2016 Arduino Srl. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +/* + * + * | Pin number | PRIMO Board pin | PIN | Label/Name | + * +------------+------------------+--------+-----------------+ + * | | Digital | | | + * +------------+------------------+--------+-----------------+ + * | 0 | D0 | P031 | | + * | 1 | D1 | P030 | | + * | 2 | D2 | P029 | | + * | 3 | D3 | P028 | | + * | 4 | D4 | P002 | | + * | 5 | D5 | P003 | | + * | 6 | D6 | P004 | | + * | 7 | D7 | P005 | | + * | 8 | D8 | P023 | | + * | 9 | D9 | P022 | | + * +------------+------------------+--------+-----------------+ + * | | LEDs | | | + * +------------+------------------+--------+-----------------+ + * | 10 | 8 | P008 | USER LED | + * | 11 | 9 | P025 | RED LED | + * | 12 | 10 | P026 | GREEN LED | + * | 13 | 11 | P027 | BLUE LED | + * +------------+------------------+--------+-----------------+ + * | | UART | | | + * +------------+------------------+--------+-----------------+ + * | 14 | TX | P011 | | + * | 15 | RX | P012 | | + * +------------+------------------+--------+-----------------+ + * | | I2C | | | + * +------------+------------------+--------+-----------------+ + * | 16 | SDA | P013 | | + * | 17 | SCL | P014 | | + * | 18 | SDA1(SDA2) | P015 | | + * | 19 | SCL1(SCL2) | P016 | | + * +------------+------------------+--------+-----------------+ + * | | INT | | | + * +------------+------------------+--------+-----------------+ + * | 20 | INT | P024 | | + * | 21 | INT1 | P020 | | + * | 22 | INT2 | P019 | | + * | 23 | INT3 | P006 | | + * | 24 | INT4 | P007 | | + * +------------+------------------+--------+-----------------+ + * | | TEST POINT | | | + * +------------+------------------+--------+-----------------+ + * | 25 | | P017 | TP4 | + * | 26 | | P018 | TP5 | + * +------------+------------------+--------+-----------------+ + * | | NFC | | | + * +------------+------------------+--------+-----------------+ + * | 27 | | P009 | NFC1 | + * | 28 | | P010 | NFC2 | + * +------------+------------------+--------+-----------------+ + * | | 32.768KHz Crystal| | | + * +------------+------------------+--------+-----------------+ + * | | | P000 | XL1 | + * | | | P001 | XL2 | + * +------------+------------------+--------+-----------------+ + */ + +#include "variant.h" + +/* + * Pins descriptions + */ +const PinDescription g_APinDescription[]= +{ + // 0 .. 9 - Digital pins + // ---------------------- + // 0..9 + { PORT0, 31, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A5, PWM0, NOT_ON_TIMER}, + { PORT0, 30, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A4, PWM1, NOT_ON_TIMER}, + { PORT0, 29, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A3, PWM2, NOT_ON_TIMER}, + { PORT0, 28, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A2, PWM3, NOT_ON_TIMER}, + { PORT0, 2, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A6, PWM4, NOT_ON_TIMER}, + { PORT0, 3, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A0, PWM5, NOT_ON_TIMER}, + { PORT0, 4, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A1, PWM6, NOT_ON_TIMER}, + { PORT0, 5, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A7, PWM7, NOT_ON_TIMER}, + { PORT0, 23, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM8, NOT_ON_TIMER}, + { PORT0, 22, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM9, NOT_ON_TIMER}, + + // 10 .. 13 - LEDs + // -------------------- + { PORT0, 8, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM10, NOT_ON_TIMER}, //USER_LED + { PORT0, 25, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM11, NOT_ON_TIMER}, //RED_LED + { PORT0, 26, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM11, NOT_ON_TIMER}, //GREEN_LED + { PORT0, 27, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM11, NOT_ON_TIMER}, //BLUE_LED + + // 14..15 - UART (Serial) + // -------------------- + { PORT0, 11, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // TX + { PORT0, 12, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // RX + + // 16..17 I2C pins (SDA/SCL) + // ---------------------- + { PORT0, 13, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // SDA + { PORT0, 14, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // SCL + + // 18..19 I2C pins (SDA1/SCL1) + // ---------------------- + { PORT0, 15, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // SDA1 + { PORT0, 16, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // SCL1 + + // 20..24 - INT + // -------------------- + { PORT0, 24, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // INT + { PORT0, 20, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // INT1 + { PORT0, 19, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // INT2 + { PORT0, 6, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // INT3 + { PORT0, 7, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // INT4 + + // 25..26 - TEST POINT + // -------------------- + { PORT0, 17, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // TP4 + { PORT0, 18, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // TP5 + + //27..28 - NFC + // -------------------- + { PORT0, 9, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, // NFC1 + { PORT0, 10, PIO_DIGITAL, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER} // NFC2 + +} ; + +Uart Serial(14, 15); diff --git a/variants/arduino_primo_core/variant.h b/variants/arduino_primo_core/variant.h new file mode 100644 index 0000000..24bb2db --- /dev/null +++ b/variants/arduino_primo_core/variant.h @@ -0,0 +1,120 @@ +/* + Copyright (c) 2016 Arduino Srl. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef _VARIANT_ARDUINO_PRIMO_CORE_ +#define _VARIANT_ARDUINO_PRIMO_CORE_ + +/*---------------------------------------------------------------------------- + * Definitions + *----------------------------------------------------------------------------*/ + + +/** Frequency of the board main oscillator */ +#define VARIANT_MAINOSC (32768ul) + +/** Master clock frequency */ +#define VARIANT_MCK (64000000ul) + +/*---------------------------------------------------------------------------- + * Headers + *----------------------------------------------------------------------------*/ + +#include "WVariant.h" + +#ifdef __cplusplus + #include "Uart.h" +#endif // __cplusplus + + #ifdef __cplusplus +extern "C"{ +#endif // __cplusplus + +/** + * Libc porting layers + */ +#if defined ( __GNUC__ ) +# include /** RedHat Newlib minimal stub */ +#endif + +/*---------------------------------------------------------------------------- + * Pins + *----------------------------------------------------------------------------*/ + +// Number of pins defined in PinDescription array +#define PINS_COUNT (16u) +#define NUM_DIGITAL_PINS (8u) + +#define digitalPinToPort(P) ( NRF_P0 ) +#define digitalPinToBitMask(P) ( 1 << g_APinDescription[P].ulPin ) +#define digitalPinToTimer(P) ( ) +#define portOutputRegister(port) ( &(port->OUT) ) +#define portInputRegister(port) ( &(port->IN) ) +#define portModeRegister(port) ( &(port->DIR) ) +#define analogInPinToBit(P) ( g_APinDescription[P].ulPin ) +#define digitalPinHasPWM(P) ( g_APinDescription[P].ulPWMChannel != NOT_ON_PWM ) +#define digitalPinToInterrupt(P) ( P ) + +#define USER_LED (10u) +#define RED_LED (11u) +#define GREEN_LED (12u) +#define BLUE_LED (13u) + +#define LED_BUILTIN USER_LED +#define BLE_LED BLUE_LED +/* + * Wire Interfaces + */ +#define WIRE_INTERFACES_COUNT 2 + +#define PIN_WIRE_SDA (16u) +#define PIN_WIRE_SCL (17u) + +#define PIN_WIRE_SDA1 (18u) +#define PIN_WIRE_SCL1 (19u) + +/* + * Analog pins + */ +static const uint8_t A0 = 0; +static const uint8_t A1 = 1; +static const uint8_t A2 = 2; +static const uint8_t A3 = 3; +static const uint8_t A4 = 4; +static const uint8_t A5 = 5; +static const uint8_t A6 = 6; +static const uint8_t A7 = 7; + + + +#ifdef __cplusplus +} +#endif + + +/*---------------------------------------------------------------------------- + * Arduino objects - C++ only + *----------------------------------------------------------------------------*/ +#ifdef __cplusplus + +extern Uart Serial; + +#endif + +#define SERIAL_PORT_MONITOR Serial + +#endif /* _VARIANT_ARDUINO_PRIMO_CORE_ */ From 8a86065c1f5c1e69c4a1393dd353437127b1885c Mon Sep 17 00:00:00 2001 From: chiararuggeri Date: Wed, 31 May 2017 13:20:14 +0200 Subject: [PATCH 2/4] Tured LEDs off after pinMode set to output because of the reverse logic on LEDs --- cores/arduino/wiring_digital.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cores/arduino/wiring_digital.c b/cores/arduino/wiring_digital.c index 941131e..2bdedd6 100755 --- a/cores/arduino/wiring_digital.c +++ b/cores/arduino/wiring_digital.c @@ -279,12 +279,19 @@ void pinMode( uint32_t ulPin, uint32_t ulMode ) case OUTPUT: // Set pin to output mode - nrf_gpio_pin_dir_set(g_APinDescription[ulPin].ulPin, NRF_GPIO_PIN_DIR_OUTPUT); - break ; + nrf_gpio_pin_dir_set(g_APinDescription[ulPin].ulPin, NRF_GPIO_PIN_DIR_OUTPUT); + + #ifdef ARDUINO_NRF52_PRIMO_CORE + // LEDs on Core work with reverse logic. Turn them off if output mode is selected + if(ulPin == 10 || ulPin == 11 || ulPin == 12 || ulPin == 13) + digitalWrite(ulPin, LOW); + #endif //ARDUINO_NRF52_PRIMO_CORE + break ; default: // do nothing break ; + } } From 993eb265abd8862e8af9a4a4c1905ef7c9c65625 Mon Sep 17 00:00:00 2001 From: chiararuggeri Date: Wed, 31 May 2017 15:38:33 +0200 Subject: [PATCH 3/4] Added MOSI (4), MISO (5), SCK (6) and SS (7) default pins and added a begin function in SPI library to override this configuration --- libraries/SPI/SPI.cpp | 104 +++++++++++++----- libraries/SPI/SPI.h | 28 ++++- .../BarometricPressureSensor.ino | 9 -- .../DigitalPotControl/DigitalPotControl.ino | 10 -- .../SPI/examples/MasterSend/MasterSend.ino | 10 -- .../examples/SlaveReceive/SlaveReceive.ino | 11 -- variants/arduino_primo_core/variant.h | 16 +++ 7 files changed, 115 insertions(+), 73 deletions(-) diff --git a/libraries/SPI/SPI.cpp b/libraries/SPI/SPI.cpp index 4f5ecfc..aea3723 100644 --- a/libraries/SPI/SPI.cpp +++ b/libraries/SPI/SPI.cpp @@ -22,23 +22,11 @@ SPIClass::SPIClass(NRF_SPI_Type *SPIInstance, uint8_t uc_pinMISO, uint8_t uc_pin { _SPIInstance = SPIInstance; - _uc_pinMiso = g_APinDescription[uc_pinMISO].ulPin; - _uc_pinSCK = g_APinDescription[uc_pinSCK].ulPin; - _uc_pinMosi = g_APinDescription[uc_pinMOSI].ulPin; + _uc_pinMiso = uc_pinMISO; + _uc_pinSCK = uc_pinSCK; + _uc_pinMosi = uc_pinMOSI; } -#ifdef ARDUINO_NRF52_PRIMO_CORE - -SPIClass::SPIClass(int uc_pinMISO, int uc_pinMOSI, int uc_pinSCK){ - _SPIInstance = NRF_SPI2; - - _uc_pinMiso = g_APinDescription[uc_pinMISO].ulPin; - _uc_pinSCK = g_APinDescription[uc_pinSCK].ulPin; - _uc_pinMosi = g_APinDescription[uc_pinMOSI].ulPin; -} - -#endif //ARDUINO_NRF52_PRIMO_CORE - void SPIClass::begin() { @@ -46,9 +34,9 @@ void SPIClass::begin() pinMode(_uc_pinMosi, OUTPUT); pinMode(_uc_pinMiso, INPUT); - _SPIInstance->PSELSCK = _uc_pinSCK; - _SPIInstance->PSELMOSI = _uc_pinMosi; - _SPIInstance->PSELMISO = _uc_pinMiso; + _SPIInstance->PSELSCK = g_APinDescription[_uc_pinSCK].ulPin; + _SPIInstance->PSELMOSI = g_APinDescription[_uc_pinMosi].ulPin; + _SPIInstance->PSELMISO = g_APinDescription[_uc_pinMiso].ulPin; // Default speed set to 4Mhz, SPI mode set to MODE 0 and Bit order set to MSB first. _SPIInstance->FREQUENCY = (SPI_FREQUENCY_FREQUENCY_M4 << SPI_FREQUENCY_FREQUENCY_Pos); @@ -67,9 +55,10 @@ void SPIClass::beginSlave() pinMode(_uc_pinMiso, INPUT); - _SPIInstance->PSELSCK = _uc_pinSCK; - _SPIInstance->PSELMOSI = _uc_pinMosi; - _SPIInstance->PSELMISO = _uc_pinMiso; + _SPIInstance->PSELSCK = g_APinDescription[_uc_pinSCK].ulPin; + _SPIInstance->PSELMOSI = g_APinDescription[_uc_pinMosi].ulPin; + _SPIInstance->PSELMISO = g_APinDescription[_uc_pinMiso].ulPin; + setDataMode(SPI_MODE0); setBitOrder(MSBFIRST); @@ -84,6 +73,56 @@ void SPIClass::end() _SPIInstance->ENABLE &= ~(SPI_ENABLE_ENABLE_Enabled << SPI_ENABLE_ENABLE_Pos); } +#ifdef ARDUINO_NRF52_PRIMO_CORE + +void SPIClass::begin(int uc_pinMISO, int uc_pinMOSI, int uc_pinSCK) +{ + _uc_pinMiso = uc_pinMISO; + _uc_pinSCK = uc_pinSCK; + _uc_pinMosi = uc_pinMOSI; + + pinMode(_uc_pinSCK, OUTPUT); + pinMode(_uc_pinMosi, OUTPUT); + pinMode(_uc_pinMiso, INPUT); + + _SPIInstance->PSELSCK = g_APinDescription[_uc_pinSCK].ulPin; + _SPIInstance->PSELMOSI = g_APinDescription[_uc_pinMosi].ulPin; + _SPIInstance->PSELMISO = g_APinDescription[_uc_pinMiso].ulPin; + + // Default speed set to 4Mhz, SPI mode set to MODE 0 and Bit order set to MSB first. + _SPIInstance->FREQUENCY = (SPI_FREQUENCY_FREQUENCY_M4 << SPI_FREQUENCY_FREQUENCY_Pos); + setDataMode(SPI_MODE0); + setBitOrder(MSBFIRST); + _order=MSBFIRST; + + _SPIInstance->ENABLE = (SPI_ENABLE_ENABLE_Enabled << SPI_ENABLE_ENABLE_Pos); +} + + +void SPIClass::beginSlave(int uc_pinMISO, int uc_pinMOSI, int uc_pinSCK) +{ + _uc_pinMiso = uc_pinMISO; + _uc_pinSCK = uc_pinSCK; + _uc_pinMosi = uc_pinMOSI; + + pinMode(_uc_pinSCK, INPUT); + pinMode(_uc_pinMosi, OUTPUT); + pinMode(_uc_pinMiso, INPUT); + + + _SPIInstance->PSELSCK = g_APinDescription[_uc_pinSCK].ulPin; + _SPIInstance->PSELMOSI = g_APinDescription[_uc_pinMosi].ulPin; + _SPIInstance->PSELMISO = g_APinDescription[_uc_pinMiso].ulPin; + + + setDataMode(SPI_MODE0); + setBitOrder(MSBFIRST); + _order=MSBFIRST; + + _SPIInstance->ENABLE = (SPI_ENABLE_ENABLE_Enabled << SPI_ENABLE_ENABLE_Pos); +} +#endif //ARDUINO_NRF52_PRIMO_CORE + void SPIClass::beginTransaction(SPISettings settings) { uint8_t bitOrder; @@ -93,14 +132,27 @@ void SPIClass::beginTransaction(SPISettings settings) noInterrupts(); end(); - + pinMode(_uc_pinSCK, OUTPUT); pinMode(_uc_pinMosi, OUTPUT); pinMode(_uc_pinMiso, INPUT); - _SPIInstance->PSELSCK = _uc_pinSCK; - _SPIInstance->PSELMOSI = _uc_pinMosi; - _SPIInstance->PSELMISO = _uc_pinMiso; + _SPIInstance->PSELSCK = g_APinDescription[_uc_pinSCK].ulPin; + _SPIInstance->PSELMOSI = g_APinDescription[_uc_pinMosi].ulPin; + _SPIInstance->PSELMISO = g_APinDescription[_uc_pinMiso].ulPin; + +#ifdef ARDUINO_NRF52_PRIMO_CORE + if(settings._uc_pinMiso != 0 && settings._uc_pinMosi != 0 && settings._uc_pinSCK != 0){ + // override configuration with pins selected by user + pinMode(settings._uc_pinSCK, OUTPUT); + pinMode(settings._uc_pinMosi, OUTPUT); + pinMode(settings._uc_pinMiso, INPUT); + + _SPIInstance->PSELSCK = g_APinDescription[settings._uc_pinSCK].ulPin; + _SPIInstance->PSELMOSI = g_APinDescription[settings._uc_pinMosi].ulPin; + _SPIInstance->PSELMISO = g_APinDescription[settings._uc_pinMiso].ulPin; + } +#endif //ARDUINO_NRF52_PRIMO_CORE if(settings.interface_clock < 182000) setClockDivider(SPI_CLOCK_DIV128); @@ -347,6 +399,4 @@ void SPIClass::detachInterrupt(void) // Should be disableInterrupt() } -#ifdef ARDUINO_NRF52_PRIMO SPIClass SPI(NRF_SPI2, PIN_SPI_MISO, PIN_SPI_SCK, PIN_SPI_MOSI); -#endif //ARDUINO_NRF52_PRIMO \ No newline at end of file diff --git a/libraries/SPI/SPI.h b/libraries/SPI/SPI.h index f015544..8001806 100644 --- a/libraries/SPI/SPI.h +++ b/libraries/SPI/SPI.h @@ -65,6 +65,18 @@ class SPISettings { data_mode = dataMode; } + #ifdef ARDUINO_NRF52_PRIMO_CORE + SPISettings(uint32_t clock, uint8_t bitOrder, uint8_t dataMode, int uc_pinMISO, int uc_pinMOSI, int uc_pinSCK) + { + interface_clock = clock; + bit_order = bitOrder; + data_mode = dataMode; + _uc_pinMiso = uc_pinMISO; + _uc_pinSCK = uc_pinSCK; + _uc_pinMosi = uc_pinMOSI; + } + #endif //ARDUINO_NRF52_PRIMO_CORE + SPISettings(void) { interface_clock = 4000000; @@ -75,6 +87,11 @@ class SPISettings { uint32_t interface_clock; uint8_t bit_order; uint8_t data_mode; + #ifdef ARDUINO_NRF52_PRIMO_CORE + uint8_t _uc_pinMiso = 0; + uint8_t _uc_pinMosi = 0; + uint8_t _uc_pinSCK = 0; + #endif //ARDUINO_NRF52_PRIMO_CORE friend class SPIClass; }; @@ -83,10 +100,6 @@ class SPIClass { public: SPIClass(NRF_SPI_Type *SPIInstance, uint8_t uc_pinMISO, uint8_t uc_pinSCK, uint8_t uc_pinMOSI); -#ifdef ARDUINO_NRF52_PRIMO_CORE - SPIClass(int uc_pinMISO, int uc_pinMOSI, int uc_pinSCK); -#endif - byte transfer(uint8_t data); void transfer(void *data, size_t count); byte read(void); @@ -105,6 +118,11 @@ class SPIClass { void beginSlave(); void end(void); +#ifdef ARDUINO_NRF52_PRIMO_CORE + void begin(int uc_pinMISO, int uc_pinMOSI, int uc_pinSCK); + void beginSlave(int uc_pinMISO, int uc_pinMOSI, int uc_pinSCK); +#endif + void setBitOrder(BitOrder order); void setDataMode(uint8_t uc_mode); void setClockDivider(uint16_t uc_div); @@ -121,8 +139,6 @@ class SPIClass { uint8_t inTransactionFlag; }; -#ifdef ARDUINO_NRF52_PRIMO extern SPIClass SPI; -#endif //ARDUINO_NRF52_PRIMO #endif //_SPI_H_INCLUDED \ No newline at end of file diff --git a/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino b/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino index c463655..8104fcb 100644 --- a/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino +++ b/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino @@ -25,15 +25,6 @@ // the sensor communicates using SPI, so include the library: #include -#ifdef ARDUINO_NRF52_PRIMO_CORE - // Arduino Primo Core doesn't have fixed SPI pins. You can choose whatever pins you prefer. - #define MISO 3 - #define MOSI 4 - #define SCK 5 - - SPIClass SPI(MISO, MOSI, SCK); -#endif //ARDUINO_NRF52_PRIMO_CORE - //Sensor's memory register addresses: const int PRESSURE = 0x1F; //3 most significant bits of pressure const int PRESSURE_LSB = 0x20; //16 least significant bits of pressure diff --git a/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino b/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino index fcdd6bc..433169c 100644 --- a/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino +++ b/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino @@ -30,16 +30,6 @@ // inslude the SPI library: #include -#ifdef ARDUINO_NRF52_PRIMO_CORE - // Arduino Primo Core doesn't have fixed SPI pins. You can choose whatever pins you prefer. - #define MISO 4 - #define MOSI 5 - #define SCK 6 - - SPIClass SPI(MISO, MOSI, SCK); -#endif //ARDUINO_NRF52_PRIMO_CORE - - // set pin 7 as the slave select for the digital pot: const int slaveSelectPin = 7; diff --git a/libraries/SPI/examples/MasterSend/MasterSend.ino b/libraries/SPI/examples/MasterSend/MasterSend.ino index 49c7079..d014fed 100644 --- a/libraries/SPI/examples/MasterSend/MasterSend.ino +++ b/libraries/SPI/examples/MasterSend/MasterSend.ino @@ -9,16 +9,6 @@ GND -> GND #include -#ifdef ARDUINO_NRF52_PRIMO_CORE - // Arduino Primo Core doesn't have fixed SPI pins. You can choose whatever pins you prefer. - #define MISO 4 - #define MOSI 5 - #define SCK 6 - #define SS 7 - - SPIClass SPI(MISO, MOSI, SCK); -#endif //ARDUINO_NRF52_PRIMO_CORE - #define DIM 11 void setup() { diff --git a/libraries/SPI/examples/SlaveReceive/SlaveReceive.ino b/libraries/SPI/examples/SlaveReceive/SlaveReceive.ino index c49f6f2..f729395 100644 --- a/libraries/SPI/examples/SlaveReceive/SlaveReceive.ino +++ b/libraries/SPI/examples/SlaveReceive/SlaveReceive.ino @@ -9,17 +9,6 @@ GND -> GND #include -#ifdef ARDUINO_NRF52_PRIMO_CORE - // Arduino Primo Core doesn't have fixed SPI pins. You can choose whatever pins you prefer. - #define MISO 4 - #define MOSI 5 - #define SCK 6 - #define SS 7 - - SPIClass SPI(MISO, MOSI, SCK); -#endif //ARDUINO_NRF52_PRIMO_CORE - - #define DIM 11 uint8_t data[DIM]; diff --git a/variants/arduino_primo_core/variant.h b/variants/arduino_primo_core/variant.h index 24bb2db..ac4c776 100644 --- a/variants/arduino_primo_core/variant.h +++ b/variants/arduino_primo_core/variant.h @@ -76,6 +76,22 @@ extern "C"{ #define LED_BUILTIN USER_LED #define BLE_LED BLUE_LED + +/* + * SPI Interfaces + */ +#define SPI_INTERFACES_COUNT 1 + +// pins' definition can be overwritten using SPI library +#define PIN_SPI_MOSI (4u) +#define PIN_SPI_MISO (5u) +#define PIN_SPI_SCK (6u) + +static const uint8_t SS = 7; +static const uint8_t MOSI = PIN_SPI_MOSI; +static const uint8_t MISO = PIN_SPI_MISO; +static const uint8_t SCK = PIN_SPI_SCK; + /* * Wire Interfaces */ From 42cebebfc9cdc9295826d0007d0924a70bad6169 Mon Sep 17 00:00:00 2001 From: Sergio Tomasello Date: Mon, 5 Jun 2017 10:57:13 +0200 Subject: [PATCH 4/4] Update boards.txt --- boards.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boards.txt b/boards.txt index 661db88..65e5279 100644 --- a/boards.txt +++ b/boards.txt @@ -40,7 +40,7 @@ primo.firmware.softdevice.file=primo/softdevice/s132_nrf52_2.0.0_softdevice.hex ##################################### -########### ARDUINO PRIMO ########### +######## ARDUINO PRIMO CORE ######### primo_core.name=Arduino Primo Core