10000 ports/nrf/boards: SUPERMINI_NRF52840 board definition. · micropython/micropython@788c208 · GitHub
[go: up one dir, main page]

Skip to content

Commit 788c208

Browse files
committed
ports/nrf/boards: SUPERMINI_NRF52840 board definition.
The Supermini NRF52840 is a clone of the NiceNano board. The board definition includes a machine_bitstream driver to drive NeoPixel leds. Signed-off-by: Joerg Korte <joerg.korte@gmail.com>
1 parent 0dd25a3 commit 788c208

File tree

8 files changed

+338
-0
lines changed

8 files changed

+338
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"deploy": [
3+
"deploy.md"
4+
],
5+
"docs": "",
6+
"features": [
7+
"BLE",
8+
"Battery Charging",
9+
"USB-C"
10+
],
11+
"images": [],
12+
"mcu": "nrf52",
13+
"product": "SuperMini / Nice!Nano nRF52840",
14+
"thumbnail": "",
15+
"url": "https://wiki.icbbuy.com/doku.php?id=developmentboard:nrf52840",
16+
"vendor": ""
17+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* GNU linker script for Adafruit nrf52840 Bootloader */
2+
3+
_bootloader_head_size = 0x1000; /* MBR */
4+
_bootloader_tail_size = 0xC000; /* Bootloader start address 0x000F4000 */
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
The steps below let you create and install the firmware file. For
2+
a .uf2 type file taken from the MicroPython downloads source only
3+
step 4 is needed. For the .hex version of the firmware file, steps
4+
1, 3 and 4 are required.
5+
6+
1. Download and install u2fconv.py. It is available e.g. in the tools
7+
directory of MicroPython.
8+
9+
2. Create a firmware for the SuperMini/Nice!Nano nrf52840 if needed, with the command
10+
11+
`make BOARD=SUPERMINI_NRF52840`
12+
13+
in the directory build-SUPERMINI_NRF52840-s140. The firmware file will have the
14+
name firmware.uf2.
15+
16+
3. Create the .uf2 file if needed in the build directory with the command:
17+
18+
`uf2conv.py -c -f 0xADA52840 -o firmware.uf2 firmware.hex`
19+
20+
It must report the start address as 0x26000. (see https://github.com/adafruit/Adafruit_nRF52_Bootloader for details). If you omit the -o option,
21+
the output file will have the name flash.uf2.
22+
23+
4. Enable the upload mode by connecting RST to GND twice within 0.5 s or calling
24+
machine.bootloader() and copy the file firmware.uf2 to the board drive,
25+
which will pop up on your Mac as /Volume/NICENANO .
26+
27+
In case the SuperMini bootloader is lost or overwritten, it can be found
28+
at https://github.com/adafruit/Adafruit_nRF52_Bootloader/releases in different
29+
formats. Using a JLINK adapter or interface, it can be uploaded as hex version.
30+
The bootloader is as well available through the Arduino IDE.
31+
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2021 Jim Mussared
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
// This is a translation of the cycle counter implementation in ports/stm32/machine_bitstream.c.
28+
// part of the code from robert-h w600 micropython port
29+
30+
#include "py/mpconfig.h"
31+
#include "py/mphal.h"
32+
33+
#if MICROPY_PY_MACHINE_BITSTREAM
34+
35+
#define mp_hal_quiet_timing_enter() MICROPY_BEGIN_ATOMIC_SECTION()
36+
#define mp_hal_quiet_timing_exit(irq_state) MICROPY_END_ATOMIC_SECTION(irq_state)
37+
38+
// NRF52840 @ 64MHz (cycle=15.625ns)
39+
#define NS_CYCLES_PER_ITER_HIGH (4) // 6 => 4
40+
#define NS_CYCLES_PER_ITER_LOW (4) // 6 => 4
41+
#define NS_OVERHEAD_CYCLES_HIGH (16) // 12 => 16
42+
#define NS_OVERHEAD_CYCLES_LOW (12) // 18 => 12
43+
44+
uint32_t mp_hal_delay_ns_calc(uint32_t ns, bool high) {
45+
uint32_t ncycles = 64 * ns / 1000; // hard coded system clock 64MHz for NRF52. the system clock cannot be change anyway
46+
uint32_t overhead = MIN(ncycles, high ? NS_OVERHEAD_CYCLES_HIGH : NS_OVERHEAD_CYCLES_LOW);
47+
return MAX(1, MP_ROUND_DIVIDE(ncycles - overhead, high ? NS_CYCLES_PER_ITER_HIGH : NS_CYCLES_PER_ITER_LOW));
48+
}
49+
50+
void machine_bitstream_high_low(mp_hal_pin_obj_t p, uint32_t *timing_ns, const uint8_t *buf, size_t len) {
51+
uint32_t pin = p->pin;
52+
uint32_t reg;
53+
if (pin >= 32) {
54+
pin -= 32;
55+
reg = NRF_P1_BASE + 0x504;
56+
NRF_P1->DIRSET = (1 << pin);
57+
} else {
58+
reg = NRF_P0_BASE + 0x504;
59+
NRF_P0->DIRSET = (1 << pin);
60+
}
61+
uint32_t lo_mask = ~(1 << pin);
62+
uint32_t hi_mask = 1 << pin;
63+
64+
// Convert ns to loop iterations [high_time_0, low_time_0, high_time_1, low_time_1].
65+
66+
for (size_t i = 0; i < 4; ++i) {
67+
timing_ns[i] = mp_hal_delay_ns_calc(timing_ns[i], i % 2 == 0);
68+
}
69+
70+
uint32_t irq_state = mp_hal_quiet_timing_enter();
71+
72+
__asm volatile (
73+
// Force consistent register assignment.
74+
// r6 = len
75+
"ldr r6, %0\n"
76+
// r4 = buf
77+
"ldr r4, %1\n"
78+
// r5 = timing_ms
79+
"ldr r5, %2\n"
80+
// r1 = GPIO reg
81+
"ldr r1, %5\n"
82+
// r8 GPIO reg value
83+
"ldr r8, [r1, #0]\n"
84+
// r9 Hi-Mask
85+
"ldr r9, %3\n"
86+
// r10 Lo-Mask
87+
"ldr r10, %4\n"
88+
89+
// // Must align for consistent timing.
90+
".align 4\n"
91+
92+
// Don't increment/decrement before first iteration.
93+
"b .outer2\n"
94+
".outer:\n"
95+
// ++buf, --len
96+
" add r4, #1\n"
97+
" sub r6, #1\n"
98+
99+
// len iterations
100+
".outer2:\n"
101+
" cmp r6, #0\n"
102+
" beq .done\n"
103+
// r0 = *buf
104+
" ldrb r0, [r4, #0]\n"
105+
106+
// 8 bits in byte
107+
" mov r7, #8\n"
108+
// Reload the port value at every byte
109+
" ldr r8, [r1, #0]\n"
110+
" .inner:\n"
111+
// *(TLS_REG *)reg |= hi_mask;
112+
" orr r8, r9\n"
113+
" str r8, [r1, #0]\n"
114+
115+
// r3 = (r0 >> 4) & 8 (r0 is 8 if high bit is 1 else 0)
116+
" mov r2, r6\n"
117+
" lsr r3, r0, #4\n"
118+
" mov r6, #8\n"
119+
" and r3, r6\n"
120+
" mov r6, r2\n"
121+
122+
// r2 = timing_ns[r3]
123+
" ldr r2, [r5, r3]\n"
124+
" .loop1:\n sub r2, #1\n cmp r2, #0\n bne .loop1\n"
125+
126+
// *(TLS_REG *)reg &= lo_mask;
127+
" and r8, r10\n"
128+
" str r8, [r1, #0]\n"
129+
130+
// r2 = timing_ns[r3 + 4]
131+
" add r3, #4\n"
132+
" ldr r2, [r5, r3]\n"
133+
" .loop2:\n sub r2, #1\n cmp r2, #0\n bne .loop2\n"
134+
135+
// b >>= 1
136+
" lsl r0, r0, #1\n"
137+
" sub r7, #1\n"
138+
// continue inner loop
139+
" cmp r7, #0\n"
140+
" bne .inner\n"
141+
// continue outer loop
142+
" b .outer\n"
143+
144+
".done:\n"
145+
:
146+
: "m" (len), "m" (buf), "m" (timing_ns), "m" (hi_mask), "m" (lo_mask), "m" (reg)
147+
: "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10"
148+
);
149+
150+
mp_hal_quiet_timing_exit(irq_state);
151+
152+
}
153+
154+
155+
#endif // MICROPY_PY_MACHINE_BITSTREAM
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include("$(PORT_DIR)/modules/manifest.py")
2+
3+
# Utils
4+
require("neopixel")
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2017 Glenn Ruben Bakke
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#define MICROPY_HW_BOARD_NAME "SuperMini / Nice!Nano / Pro Micro nRF52840"
28+
#define MICROPY_HW_MCU_NAME "NRF52840"
29+
#define MICROPY_PY_SYS_PLATFORM "nrf52"
30+
31+
#define MICROPY_PY_MACHINE_UART (1)
32+
#define MICROPY_PY_MACHINE_HW_PWM (1)
33+
#define MICROPY_PY_MACHINE_HW_SPI (1)
34+
#define MICROPY_PY_MACHINE_RTCOUNTER (1)
35+
#define MICROPY_PY_MACHINE_I2C (1)
36+
#define MICROPY_PY_MACHINE_ADC (1)
37+
#define MICROPY_PY_MACHINE_TEMP (1)
38+
#define MICROPY_PY_FRAMEBUF (1)
39+
#define MICROPY_PY_MACHINE_BITSTREAM (1)
40+
#define MICROPY_PY_MUSIC (1)
41+
#define MICROPY_PY_MACHINE_SOFT_PWM (1)
42+
43+
#define MICROPY_HW_ENABLE_RNG (1)
44+
45+
#define MICROPY_HW_USB_CDC (1)
46+
47+
#define MICROPY_HW_HAS_LED (1)
48+
#define MICROPY_HW_LED_COUNT (1)
49+
#define MICROPY_HW_LED_PULLUP (0)
50+
#define MICROPY_HW_LED1 (15)
51+
#define HELP_TEXT_BOARD_LED "1"
52+
53+
#define MICROPY_HW_UART1_RX (8)
54+
#define MICROPY_HW_UART1_TX (6)
55+
56+
#define MICROPY_HW_SPI0_NAME "SPI0"
57+
#define MICROPY_HW_SPI0_SCK (32 + 13)
58+
#define MICROPY_HW_SPI0_MOSI (10)
59+
#define MICROPY_HW_SPI0_MISO (32 + 11)
60+
61+
#define MICROPY_HW_PWM0_NAME "PWM0"
62+
#define MICROPY_HW_PWM1_NAME "PWM1"
63+
#define MICROPY_HW_PWM2_NAME "PWM2"
64+
65+
#define MICROPY_HW_MUSIC_PIN (38)
66+
67+
#define MICROPY_HW_USB_VID (0x239A)
68+
#define MICROPY_HW_USB_PID (0x8052)
69+
#define MICROPY_HW_USB_CDC_1200BPS_TOUCH (1)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
MCU_SERIES = m4
2+
MCU_VARIANT = nrf52
3+
MCU_SUB_VARIANT = nrf52840
4+
SOFTDEV_VERSION = 6.1.1
5+
SD=s140
6+
LD_FILES += boards/SUPERMINI_NRF52840/bootloader.ld boards/nrf52840_1M_256k.ld
7+
8+
NRF_DEFINES += -DNRF52840_XXAA
9+
10+
MICROPY_VFS_LFS2 = 1
11+
FS_SIZE = 256k
12+
13+
# DEBUG ?= 1
14+
15+
FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py
16+
17+
uf2: hex
18+
python3 $(TOP)/tools/uf2conv.py -c -o $(BUILD)/firmware.uf2 -f 0xADA52840 $(BUILD)/firmware.hex
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
P0_02,P2
2+
AIN0,P2
3+
AIN2,P4
4+
P0_04,P4
5+
V_BAT,P4
6+
P0_06,P6
7+
UART1_TX,P6
8+
UART1_RX,P8
9+
P0_08,P8
10+
P0_09,P9
11+
NFC1,P9
12+
NFC2,P10
13+
SPI0_MOSI,P10
14+
P0_10,P10
15+
P0_11,P11
16+
VCC_OFF,P13
17+
P0_13,P13
18+
LED,P15
19+
P0_15,P15
20+
I2C_SDA,P17
21+
I2C_SCL,P20
22+
P0_17,P17
23+
P0_20,P20
24+
P0_22,P22
25+
P0_24,P24
26+
P0_29,P29
27+
AIN5,P29
28+
AIN7,P31
29+
P0_31,P31
30+
P1_00,P32
31+
P1_01,P33
32+
P1_02,P34
33+
P1_04,P35
34+
P1_06,P38
35+
P1_07,P39
36+
P1_11,P43
37+
SPI0_MISO,P43
38+
SPI0_SCK,P45
39+
P1_13,P45
40+
P1_15,P47

0 commit comments

Comments
 (0)
0