Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
d00616 committed Jul 26, 2017
0 parents commit 8db6efe
Show file tree
Hide file tree
Showing 11 changed files with 718 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.bak
*~
66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
118 changes: 118 additions & 0 deletions boards.txt
Original file line number Diff line number Diff line change
@@ -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
Empty file added libraries/MyNRF5Board/dummy.h
Empty file.
97 changes: 97 additions & 0 deletions libraries/MyNRF5Board/examples/MyNRF5Board/MyNRF5Board.cpp
Original file line number Diff line number Diff line change
@@ -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 <variant.h>

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
Loading

0 comments on commit 8db6efe

Please sign in to comment.