diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..09ba154 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.bak +*~ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..0280362 --- /dev/null +++ b/README.md @@ -0,0 +1,66 @@ +# ArduinoHwNRF5 + +Arduino hardware definitions for Mysensors nRF5 boards + +## MyNRF5Board + +This repository allows managing the nRF5 pin mapping as part of your code. +You can use the method for any nRF51822 or nRF52832 board or module. + +Most components, like UART, SPI, Wire Bus, of the nRF5 series chips don't +have a fixed pin mapping. There are some pins with restrictions like analog +inputs, NFC or pins near the radio module. Please refer the latest +documentation about pin restrictions at http://infocenter.nordicsemi.com + +To use the custom pin mapping you have to do following steps: + + 1. Install "arduino-nrf5" like described at + https://github.com/sandeepmistry/arduino-nRF5/ + 2. Install the "My Sensors nRF5 Boards" with the board manager like + explained at https://github.com/mysensors/ArduinoBoards + 3. Copy the files "MyNRF5Board.cpp" and "MyNRF5Board.h" from + "MyNRF5Board" example into your sketch. + 4. Modify pin mappings in "MyNRF5Board.cpp" and "MyNRF5Board.h" to fit + your requirements. + 5. Select "MyNRF5Board nrf52832" or "MyNRF5Board nrf52822" as your board. + Choose the correct parameters and programmer in the Tools menu. + +### MyNRF5Board.h + +This file allows you to change the pins of internal hardware, like the +serial port, SPI bus or Wire bus. + +All pins referenced here are mapped via the "g_ADigitalPinMap" Array +defined in "MyNRF5Board.cpp" to pins of the MCU. + +As an example, if you have at the third position in "g_ADigitalPinMap" the +12, then all ports referenced in Arduino with 2 are mapped to P0.12. If you +don't change the "g_ADigitalPinMap" Array, the Arduino pins 0..31 are +translated to P0.00..P0..31. + +### MyNRF5Board.cpp + +This file allows you to change the relation between pins referenced in +the Arduino IDE (0..31) and pins of the nRF5 MCU (P0.00..P0.31). + +If you can live with addressing the GPIO pins by using the Arduino pins +0..31 instead of a custom mapping, don't change this file. If you have +a lot of Arduino code with fixed pin numbers and you need to map these +pins to specific pins of the nRF5 MCU; you need to change this file. + +If you fill the "g_ADigitalPinMap" Array with numbers between 0..31, +the Arduino pins 0..31 are assigned to pins P0.00..P0.31 of the MCU. + +As an example, if you need to change the pin mapping for Arduino pin 5 +to P0.12 of the MCU, you have to write the 12 into the sixth position +in the "g_ADigitalPinMap" Array. + +The pin mapping effects commands like "pinMode()", "digitalWrite()", +"analogRead()" and "analogWrite()". + +If you change the pin mapping, you have to modify the pins in +"MyNRF5Board.h". Especially the analog pin mapping must be replaced with +your pin numbers by replacing PIN_AIN0..7 with a number of your mapping +array. You can use the constants PIN_AIN0..7 in the "g_ADigitalPinMap" +Array if you want to reference analog ports MCU independent. You cannot +use the pins P0.00 and P0.01 for GPIO, when the 32kHz crystal is connected. diff --git a/boards.txt b/boards.txt new file mode 100644 index 0000000..ed5c3aa --- /dev/null +++ b/boards.txt @@ -0,0 +1,118 @@ +# Copyright (c) 2014-2015 Arduino LLC. All right reserved. +# Copyright (c) 2016 Sandeep Mistry All right reserved. +# Copyright (c) 2017 Frank Holtz 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 + +menu.chip=Chip +menu.bootcode=Bootloader/SD +menu.lfclk=Low Frequency Clock +menu.reset=Reset + +# MyNRF5Board nRF52832 +# Board definition is expected in +# MyBoard.cpp and MyBoard.h as part +# of the sketch +################################### + +MyBoard_nRF52832.name=MyNRF5Board nRF52832 + +MyBoard_nRF52832.bootloader.tool=sandeepmistry:openocd + +MyBoard_nRF52832.upload.tool=sandeepmistry:openocd +MyBoard_nRF52832.upload.target=nrf52 +MyBoard_nRF52832.upload.maximum_size=524288 + +MyBoard_nRF52832.build.mcu=cortex-m4 +MyBoard_nRF52832.build.f_cpu=16000000 +MyBoard_nRF52832.build.board=GENERIC +MyBoard_nRF52832.build.core=sandeepmistry:nRF5 +MyBoard_nRF52832.build.variant=MyNRF5Board +MyBoard_nRF52832.build.variant_system_lib= +# -I{build.path} and -DMYNRF5BOARD is only required by MyNRF5Board +MyBoard_nRF52832.build.extra_flags=-DNRF52 -DMYNRF5BOARD -I{build.path} +MyBoard_nRF52832.build.float_flags=-mfloat-abi=hard -mfpu=fpv4-sp-d16 +MyBoard_nRF52832.build.ldscript=nrf52_xxaa.ld + +MyBoard_nRF52832.menu.bootcode.none=None +MyBoard_nRF52832.menu.bootcode.none.softdevice=none +MyBoard_nRF52832.menu.bootcode.s132=S132 (SoftDevice) +MyBoard_nRF52832.menu.bootcode.s132.softdevice=s132 +MyBoard_nRF52832.menu.bootcode.s132.softdeviceversion=2.0.1 +MyBoard_nRF52832.menu.bootcode.s132.upload.maximum_size=409600 +MyBoard_nRF52832.menu.bootcode.s132.build.extra_flags=-DNRF52 -DS132 -DNRF51_S132 -DSOFTDEVICE_PRESENT +MyBoard_nRF52832.menu.bootcode.s132.build.ldscript=armgcc_s132_nrf52832_xxaa.ld + +MyBoard_nRF52832.menu.lfclk.lfxo=Crystal Oscillator +MyBoard_nRF52832.menu.lfclk.lfxo.build.lfclk_flags=-DUSE_LFXO +MyBoard_nRF52832.menu.lfclk.lfrc=RC Oscillator +MyBoard_nRF52832.menu.lfclk.lfrc.build.lfclk_flags=-DUSE_LFRC +MyBoard_nRF52832.menu.lfclk.lfsynt=Synthesized +MyBoard_nRF52832.menu.lfclk.lfsynt.build.lfclk_flags=-DUSE_LFSYNT + +MyBoard_nRF52832.menu.reset.notenable=Don't enable +MyBoard_nRF52832.menu.reset.enabled=Enable +MyBoard_nRF52832.menu.reset.enabled.build.reset_flags=-DCONFIG_GPIO_AS_PINRESET + + +# MyNRF5Board nRF51822 +# Board definition is expected in +# MyBoard.cpp and MyBoard.h as part +# of the sketch +################################### + +MyBoard_nRF51822.name=MyNRF5Board nRF51822 +MyBoard_nRF51822.bootloader.tool=sandeepmistry:openocd +MyBoard_nRF51822.upload.tool=sandeepmistry:openocd +MyBoard_nRF51822.upload.target=nrf51 +MyBoard_nRF51822.upload.maximum_size=262144 + +MyBoard_nRF51822.build.mcu=cortex-m0 +MyBoard_nRF51822.build.f_cpu=16000000 +MyBoard_nRF51822.build.board=GENERIC +MyBoard_nRF51822.build.core=sandeepmistry:nRF5 +MyBoard_nRF51822.build.variant=MyNRF5Board +MyBoard_nRF51822.build.variant_system_lib= +# -I{build.path} and -DMYNRF5BOARD is only required by MyNRF5Board +MyBoard_nRF51822.build.extra_flags=-DNRF51 -DMYNRF5BOARD -I{build.path} +MyBoard_nRF51822.build.float_flags= +MyBoard_nRF51822.build.ldscript=nrf51_{build.chip}.ld + +MyBoard_nRF51822.menu.chip.xxaa=16 kB RAM, 256 kB flash (xxaa) +MyBoard_nRF51822.menu.chip.xxaa.build.chip=xxaa +MyBoard_nRF51822.menu.chip.xxac=32 kB RAM, 256 kB flash (xxac) +MyBoard_nRF51822.menu.chip.xxac.build.chip=xxac + +MyBoard_nRF51822.menu.bootcode.none=None +MyBoard_nRF51822.menu.bootcode.none.softdevice=none +MyBoard_nRF51822.menu.bootcode.s110=S110 (SoftDevice) +MyBoard_nRF51822.menu.bootcode.s110.softdevice=s110 +MyBoard_nRF51822.menu.bootcode.s110.softdeviceversion=8.0.0 +MyBoard_nRF51822.menu.bootcode.s110.upload.maximum_size=151552 +MyBoard_nRF51822.menu.bootcode.s110.build.extra_flags=-DNRF51 -DS110 -DNRF51_S110 -DSOFTDEVICE_PRESENT +MyBoard_nRF51822.menu.bootcode.s110.build.ldscript=armgcc_s110_nrf51822_{build.chip}.ld +MyBoard_nRF51822.menu.bootcode.s130=S130 (SoftDevice) +MyBoard_nRF51822.menu.bootcode.s130.softdevice=s130 +MyBoard_nRF51822.menu.bootcode.s130.softdeviceversion=2.0.1 +MyBoard_nRF51822.menu.bootcode.s130.upload.maximum_size=151552 +MyBoard_nRF51822.menu.bootcode.s130.build.extra_flags=-DNRF51 -DS130 -DNRF51_S130 -DSOFTDEVICE_PRESENT +MyBoard_nRF51822.menu.bootcode.s130.build.ldscript=armgcc_s130_nrf51822_{build.chip}.ld + +MyBoard_nRF51822.menu.lfclk.lfxo=Crystal Oscillator +MyBoard_nRF51822.menu.lfclk.lfxo.build.lfclk_flags=-DUSE_LFXO +MyBoard_nRF51822.menu.lfclk.lfrc=RC Oscillator +MyBoard_nRF51822.menu.lfclk.lfrc.build.lfclk_flags=-DUSE_LFRC +MyBoard_nRF51822.menu.lfclk.lfsynt=Synthesized +MyBoard_nRF51822.menu.lfclk.lfsynt.build.lfclk_flags=-DUSE_LFSYNT diff --git a/libraries/MyNRF5Board/dummy.h b/libraries/MyNRF5Board/dummy.h new file mode 100644 index 0000000..e69de29 diff --git a/libraries/MyNRF5Board/examples/MyNRF5Board/MyNRF5Board.cpp b/libraries/MyNRF5Board/examples/MyNRF5Board/MyNRF5Board.cpp new file mode 100644 index 0000000..4be2b7c --- /dev/null +++ b/libraries/MyNRF5Board/examples/MyNRF5Board/MyNRF5Board.cpp @@ -0,0 +1,97 @@ +/* + If you don't use an nRF5 board, you can ignore this file. + + This file was part of the "My Sensors nRF5 Boards" board repository + available at https://github.com/mysensors/ArduinoBoards If you have + questions, please refer the documentation at + https://github.com/mysensors/ArduinoHwNRF5 first. + + This file is compatible with ArduinoHwNRF5 > 0.1.0 + + This file allows you to change the relation between pins referenced in + the Arduino IDE (0..31) and pins of the nRF5 MCU (P0.00..P0.31). + + If you can live with addressing the GPIO pins by using the Arduino pins + 0..31 instead of a custom mapping, don't change this file. If you have + a lot of Arduino code with fixed pin numbers and you need to map these + pins to specific pins of the nRF5 MCU; you need to change this file. + + If you fill the "g_ADigitalPinMap" Array with numbers between 0..31, + the Arduino pins 0..31 are assigned to pins P0.00..P0.31 of the MCU. + + As an example, if you need to change the pin mapping for Arduino pin 5 + to P0.12 of the MCU, you have to write the 12 into the sixth position + in the "g_ADigitalPinMap" Array. + + The pin mapping effects commands like "pinMode()", "digitalWrite()", + "analogRead()" and "analogWrite()". + + If you change the pin mapping, you have to modify the pins in + "MyNRF5Board.h". Especially the analog pin mapping must be replaced with + your pin numbers by replacing PIN_AIN0..7 with a number of your mapping + array. You can use the constants PIN_AIN0..7 in the "g_ADigitalPinMap" + Array if you want to reference analog ports MCU independent. You cannot + use the pins P0.00 and P0.01 for GPIO, when the 32kHz crystal is connected. + + + ########################################################################### + + Copyright (c) 2014-2015 Arduino LLC. All right reserved. + Copyright (c) 2016 Sandeep Mistry. All right reserved. + Copyright (c) 2017 Sensnology AB. 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 +*/ + + + +#ifdef MYNRF5BOARD +#include + +const uint32_t g_ADigitalPinMap[] = { + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23, + 24, + 25, + 26, + 27, + 28, + 29, + 30, + 31 +}; +#endif diff --git a/libraries/MyNRF5Board/examples/MyNRF5Board/MyNRF5Board.h b/libraries/MyNRF5Board/examples/MyNRF5Board/MyNRF5Board.h new file mode 100644 index 0000000..7834699 --- /dev/null +++ b/libraries/MyNRF5Board/examples/MyNRF5Board/MyNRF5Board.h @@ -0,0 +1,160 @@ +/* + If you don't use an nRF5 board, you can ignore this file. + + This file was part of the "My Sensors nRF5 Boards" board repository + available at https://github.com/mysensors/ArduinoBoards If you have + questions, please refer the documentation at + https://github.com/mysensors/ArduinoHwNRF5 first. + + This file is compatible with ArduinoHwNRF5 > 0.1.0 + + This file allows you to change the pins of internal hardware, like the + serial port, SPI bus or Wire bus. + + All pins referenced here are mapped via the "g_ADigitalPinMap" Array + defined in "MyNRF5Board.cpp" to pins of the MCU. + + As an example, if you have at the third position in "g_ADigitalPinMap" the + 12, then all ports referenced in Arduino with 2 are mapped to P0.12. If you + don't change the "g_ADigitalPinMap" Array, the Arduino pins 0..31 are + translated to P0.00..P0..31. + + ########################################################################### + + This file is compatible with ArduinoHwNRF5 > 0.1.0 + Copyright (c) 2014-2015 Arduino LLC. All right reserved. + Copyright (c) 2016 Sandeep Mistry. All right reserved. + Copyright (c) 2017 Sensnology AB. 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 _MYNRF5BOARD_H_ +#define _MYNRF5BOARD_H_ + +#ifdef __cplusplus +extern "C" +{ +#endif // __cplusplus + +// Number of pins defined in PinDescription array +#define PINS_COUNT (32u) +#define NUM_DIGITAL_PINS (32u) +#define NUM_ANALOG_INPUTS (8u) +#define NUM_ANALOG_OUTPUTS (8u) + +/* + * LEDs + * + * This is optional + * + * With My Sensors, you can use + * hwPinMode() instead of pinMode() + * hwPinMode() allows to use advanced modes like OUTPUT_H0H1 to drive LEDs. + * https://github.com/mysensors/MySensors/blob/development/drivers/NRF5/nrf5_wiring_constants.h + * + */ +#define PIN_LED1 (13) +// #define PIN_LED2 (9) +// #define PIN_LED3 (10) +// #define PIN_LED4 (11) +// #define PIN_LED5 (12) +// #define PIN_LED6 (14) +// #define PIN_LED7 (15) +// #define PIN_LED8 (16) +#define LED_BUILTIN PIN_LED1 + +/* + * Buttons + * + * This is optional + */ +// #define PIN_BUTTON1 (3) +// #define PIN_BUTTON2 (4) +// #define PIN_BUTTON3 (5) +// #define PIN_BUTTON4 (6) +// #define PIN_BUTTON5 (7) +// #define PIN_BUTTON6 (8) +// #define PIN_BUTTON7 (9) +// #define PIN_BUTTON8 (10) + +/* + * Analog ports + * + * If you change g_ADigitalPinMap, replace PIN_AIN0 with + * port numbers mapped by the g_ADigitalPinMap Array. + * You can add PIN_AIN0 to the g_ADigitalPinMap Array if + * you want provide analog ports MCU independed, you can add + * PIN_AIN0..PIN_AIN7 to your custom g_ADigitalPinMap Array + * defined in MyNRF5Board.cpp + */ +static const uint8_t A0 = PIN_AIN0; +static const uint8_t A1 = PIN_AIN1; +static const uint8_t A2 = PIN_AIN2; +static const uint8_t A3 = PIN_AIN3; +static const uint8_t A4 = PIN_AIN4; +static const uint8_t A5 = PIN_AIN5; +static const uint8_t A6 = PIN_AIN6; +static const uint8_t A7 = PIN_AIN7; + +/* + * Serial interfaces + * + * RX and TX are required. + * If you have no serial port, use unused pins + * CTS and RTS are optional. + */ +#define PIN_SERIAL_RX (2) +#define PIN_SERIAL_TX (3) +// #define PIN_SERIAL_CTS (4) +// #define PIN_SERIAL_RTS (5) + +/* + * SPI Interfaces + * + * This is optional + * + * If SPI is defined MISO, MOSI, SCK are required + * SS is optional and can be used in your sketch. + */ +#define SPI_INTERFACES_COUNT 1 + +#define PIN_SPI_MISO (22) +#define PIN_SPI_MOSI (23) +#define PIN_SPI_SCK (24) +#define PIN_SPI_SS (21) + +static const uint8_t SS = PIN_SPI_SS; +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 + * + * This is optional + */ +#define WIRE_INTERFACES_COUNT 1 + +#define PIN_WIRE_SDA (20u) +#define PIN_WIRE_SCL (21u) + +static const uint8_t SDA = PIN_WIRE_SDA; +static const uint8_t SCL = PIN_WIRE_SCL; + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/libraries/MyNRF5Board/examples/MyNRF5Board/MyNRF5Board.ino b/libraries/MyNRF5Board/examples/MyNRF5Board/MyNRF5Board.ino new file mode 100644 index 0000000..49c340d --- /dev/null +++ b/libraries/MyNRF5Board/examples/MyNRF5Board/MyNRF5Board.ino @@ -0,0 +1,28 @@ +/* + * This example sketch shows how you can manage the nRF5 pin mapping as part of your code. + * You can use the method for any nRF51822 or nRF52832 board or module. + * + * Most components, like UART, SPI, Wire Bus, of the nRF5 series chips don't + * have a fixed pin mapping. There are some pins with restrictions like analog + * inputs, NFC or pins near the radio module. Please refer the latest + * documentation about pin restrictions at http://infocenter.nordicsemi.com + * + * To use the custom pin mapping you have to do following steps: + * + * 1. Install "arduino-nrf5" like described at + * https://github.com/sandeepmistry/arduino-nRF5/ + * 2. Install the "My Sensors nRF5 Boards" with the board manager like + * explained at https://github.com/mysensors/ArduinoBoards + * 3. Copy the files "MyNRF5Board.cpp" and "MyNRF5Board.h" from + * "MyNRF5Board" example into your sketch. + * 4. Modify pin mappings in "MyNRF5Board.cpp" and "MyNRF5Board.h" to fit + * your requirements. + * 5. Select "MyNRF5Board nrf52832" or "MyNRF5Board nrf52822" as your board. + * Choose the correct parameters and programmer in the Tools menu. + */ + +void setup() { +} + +void loop() { +} diff --git a/platform.txt b/platform.txt new file mode 100644 index 0000000..f0cab4a --- /dev/null +++ b/platform.txt @@ -0,0 +1,137 @@ +# Copyright (c) 2014-2015 Arduino LLC. All right reserved. +# Copyright (c) 2016 Sandeep Mistry All right reserved. +# Copyright (c) 2017 Frank Holtz 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 + +name=MySensors nRF5 Boards +version=0.1.0 + +# Path calculation +################## + +arduino_nrf.path = {build.core.path} +nrf.sdk.path={arduino_nrf.path}/SDK + +# Compile variables +# ----------------- + +compiler.warning_flags=-w +compiler.warning_flags.none=-w +compiler.warning_flags.default= +compiler.warning_flags.more=-Wall +compiler.warning_flags.all=-Wall -Wextra + +compiler.path={runtime.tools.gcc-arm-none-eabi-5_2-2015q4.path}/bin/ +compiler.c.cmd=arm-none-eabi-gcc +compiler.c.flags=-mcpu={build.mcu} -mthumb -c -g -Os {compiler.warning_flags} {build.float_flags} -std=gnu11 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -MMD +compiler.c.elf.cmd=arm-none-eabi-gcc +compiler.c.elf.flags=-Os -Wl,--gc-sections -save-temps +compiler.S.cmd=arm-none-eabi-gcc +compiler.S.flags=-c -g -x assembler-with-cpp +compiler.cpp.cmd=arm-none-eabi-g++ +compiler.cpp.flags=-mcpu={build.mcu} -mthumb -c -g -Os {compiler.warning_flags} {build.float_flags} -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --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 +compiler.objcopy.eep.flags=-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 +compiler.elf2bin.flags=-O binary +compiler.elf2bin.cmd=arm-none-eabi-objcopy +compiler.elf2hex.flags=-O ihex +compiler.elf2hex.cmd=arm-none-eabi-objcopy +compiler.ldflags=-mcpu={build.mcu} -mthumb {build.float_flags} -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align +compiler.size.cmd=arm-none-eabi-size +compiler.define=-DARDUINO= + +# this can be overriden in boards.txt +build.extra_flags= +build.lfclk_flags= + + +compiler.nrf.flags=-DNRF5 "-I{nrf.sdk.path}/components/toolchain/" "-I{nrf.sdk.path}/components/toolchain/CMSIS/Include" "-I{nrf.sdk.path}/components/toolchain/gcc/" "-I{nrf.sdk.path}/components/device/" "-I{nrf.sdk.path}/components/drivers_nrf/delay/" "-I{nrf.sdk.path}/components/softdevice/{softdevice}/headers/" + +# These can be overridden in platform.local.txt +compiler.c.extra_flags= +compiler.c.elf.extra_flags= +compiler.cpp.extra_flags= +compiler.S.extra_flags= +compiler.ar.extra_flags= +compiler.elf2bin.extra_flags= +compiler.elf2hex.extra_flags= + + +# Compile patterns +# ---------------- + +## Compile c files +recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {compiler.nrf.flags} {build.lfclk_flags} {includes} "{source_file}" -o "{object_file}" + +## Compile c++ files +recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {compiler.nrf.flags} {build.lfclk_flags} {includes} "{source_file}" -o "{object_file}" + +## Compile S files +recipe.S.o.pattern="{compiler.path}{compiler.S.cmd}" {compiler.S.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.S.extra_flags} {build.extra_flags} {build.lfclk_flags} {includes} "{source_file}" -o "{object_file}" + +## Create archives +recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}" + +## Combine gc-sections, archives, and objects +recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" "-L{build.path}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} "-L{nrf.sdk.path}/components/toolchain/gcc/" "-L{nrf.sdk.path}/components/softdevice/{softdevice}/toolchain/armgcc/" "-T{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" --specs=nano.specs --specs=nosys.specs {compiler.ldflags} -o "{build.path}/{build.project_name}.elf" {object_files} -Wl,--start-group -lm "{build.path}/{archive_file}" -Wl,--end-group + +## Create output (bin file) +recipe.objcopy.bin.pattern="{compiler.path}{compiler.elf2bin.cmd}" {compiler.elf2bin.flags} {compiler.elf2bin.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.bin" + +## Create output (hex file) +recipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex" + +## Save bin +recipe.output.tmp_file_bin={build.project_name}.bin +recipe.output.save_file_bin={build.project_name}.save.bin + +## Save hex +recipe.output.tmp_file_hex={build.project_name}.hex +recipe.output.save_file_hex={build.project_name}.save.hex + +## Compute size +recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf" +recipe.size.regex=\.text\s+([0-9]+).* + +## Export Compiled Binary +recipe.output.tmp_file={build.project_name}.hex +recipe.output.save_file={build.project_name}.{build.variant}.hex + +# +# OpenOCD sketch upload +# + +tools.openocd.path={runtime.tools.openocd-0.10.0-dev.nrf5.path} +tools.openocd.cmd=bin/openocd +tools.openocd.cmd.windows=bin/openocd.exe + +tools.openocd.upload.params.verbose=-d2 +tools.openocd.upload.params.quiet=-d0 +tools.openocd.upload.pattern="{path}/{cmd}" {upload.verbose} -f interface/{upload.protocol}.cfg -c "{upload.setup_command}" -f target/{upload.target}.cfg -c "program {{{build.path}/{build.project_name}.hex}} verify reset; shutdown;" + +tools.openocd.program.params.verbose=-d2 +tools.openocd.program.params.quiet=-d0 +tools.openocd.program.pattern="{path}/{cmd}" {program.verbose} -f interface/{program.protocol}.cfg -c "{program.setup_command}" -f target/{upload.target}.cfg -c "program {{{build.path}/{build.project_name}.hex}} verify reset; shutdown;" + +tools.openocd.erase.params.verbose=-d3 +tools.openocd.erase.params.quiet=-d0 +tools.openocd.erase.pattern= + +tools.openocd.bootloader.params.verbose=-d2 +tools.openocd.bootloader.params.quiet=-d0 +tools.openocd.bootloader.pattern="{path}/{cmd}" {bootloader.verbose} -f interface/{program.protocol}.cfg -c "{program.setup_command}" -f target/{upload.target}.cfg -c "init; halt; nrf51 mass_erase; program {{{build.core.path}/SDK/components/softdevice/{softdevice}/hex/{softdevice}_{upload.target}_{softdeviceversion}_softdevice.hex}} verify reset; shutdown;" diff --git a/variants/MyNRF5Board/pins_arduino.h b/variants/MyNRF5Board/pins_arduino.h new file mode 100644 index 0000000..3ef4d4a --- /dev/null +++ b/variants/MyNRF5Board/pins_arduino.h @@ -0,0 +1,17 @@ +/* + Copyright (c) 2014-2015 Arduino LLC. 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" diff --git a/variants/MyNRF5Board/variant.cpp b/variants/MyNRF5Board/variant.cpp new file mode 100644 index 0000000..8801769 --- /dev/null +++ b/variants/MyNRF5Board/variant.cpp @@ -0,0 +1,20 @@ +/* + Copyright (c) 2014-2015 Arduino LLC. All right reserved. + Copyright (c) 2016 Sandeep Mistry 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 +*/ + +#include "variant.h" diff --git a/variants/MyNRF5Board/variant.h b/variants/MyNRF5Board/variant.h new file mode 100644 index 0000000..57c703a --- /dev/null +++ b/variants/MyNRF5Board/variant.h @@ -0,0 +1,73 @@ +/* + Copyright (c) 2014-2015 Arduino LLC. All right reserved. + Copyright (c) 2016 Sandeep Mistry 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_MYNRF5BOARD_ +#define _VARIANT_MYNRF5BOARD_ + +/*---------------------------------------------------------------------------- + * Headers + *----------------------------------------------------------------------------*/ + +#include "WVariant.h" + +#ifdef __cplusplus +extern "C" +{ +#endif // __cplusplus + +/** Master clock frequency */ +#ifdef NRF52 +#define VARIANT_MCK (64000000ul) +#else +#define VARIANT_MCK (16000000ul) +#endif + +/* + * Analog pins + */ +#ifdef NRF51 +#define PIN_AIN0 (26) +#define PIN_AIN1 (27) +#define PIN_AIN2 (1) +#define PIN_AIN3 (2) +#define PIN_AIN4 (3) +#define PIN_AIN5 (4) +#define PIN_AIN6 (5) +#define PIN_AIN7 (6) +#else +#define PIN_AIN0 (2) +#define PIN_AIN1 (3) +#define PIN_AIN2 (4) +#define PIN_AIN3 (5) +#define PIN_AIN4 (28) +#define PIN_AIN5 (29) +#define PIN_AIN6 (30) +#define PIN_AIN7 (31) +#endif + +#ifdef NRF52 +#define ADC_RESOLUTION 14 +#else +#define ADC_RESOLUTION 10 +#endif + +#ifdef __cplusplus +} +#endif // __cplusplus + +#include +#endif