Skip to content

Commit 0f3ced1

Browse files
maksymkoMaxim Sloyko
authored andcommitted
nrf/51: Initial commit to unicore-mx project
1 parent e2acc85 commit 0f3ced1

36 files changed

+3100
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ TARGETS:= stm32/f0 stm32/f1 stm32/f2 stm32/f3 stm32/f4 stm32/f7 \
2929
stm32/l0 stm32/l1 stm32/l4 \
3030
lpc13xx lpc17xx lpc43xx/m4 lpc43xx/m0 lm3s lm4f \
3131
efm32/tg efm32/g efm32/lg efm32/gg \
32+
nrf/51 \
3233
sam/3a sam/3n sam/3s sam/3u sam/3x sam/4l \
3334
vf6xx
3435

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Currently (at least partly) supported microcontrollers:
1313
- TI (Tiva) LM4F series (continuing as TM4F, pin and peripheral compatible)
1414
- EFM32 Gecko series (only core support)
1515
- NXP Vybrid VF6xx (formerly Freescale)
16+
- Nordic Semiconductor nRF51
1617

1718
The library is a fork of [libopencm3](https://github.com/libopencm3/libopencm3).
1819
We highly value all the work done in libopencm3, but for our projects we need a higher

include/unicore-mx/dispatch/nvic.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
#elif defined(LPC43XX_M0)
4040
# include <unicore-mx/lpc43xx/m0/nvic.h>
4141

42+
#elif defined(NRF51)
43+
# include <unicore-mx/nrf/51/nvic.h>
44+
4245
#elif defined(SAM3A)
4346
# include <unicore-mx/sam/3a/nvic.h>
4447
#elif defined(SAM3N)

include/unicore-mx/nrf/51/clock.h

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* This file is part of the unicore-mx project.
3+
*
4+
* This library is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Lesser General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This library is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public License
15+
* along with this library. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#ifndef NRF51_CLOCK_H
19+
#define NRF51_CLOCK_H
20+
21+
#include <stdbool.h>
22+
23+
#include <unicore-mx/cm3/common.h>
24+
#include <unicore-mx/nrf/memorymap.h>
25+
26+
/* Clock tasks */
27+
#define CLOCK_TASK_HFCLKSTART MMIO32(CLOCK_BASE + 0x000)
28+
#define CLOCK_TASK_HFCLKSTOP MMIO32(CLOCK_BASE + 0x004)
29+
#define CLOCK_TASK_LFCLKSTART MMIO32(CLOCK_BASE + 0x008)
30+
#define CLOCK_TASK_LFCLKSTOP MMIO32(CLOCK_BASE + 0x00C)
31+
#define CLOCK_TASK_CAL MMIO32(CLOCK_BASE + 0x010)
32+
#define CLOCK_TASK_CTSTART MMIO32(CLOCK_BASE + 0x014)
33+
#define CLOCK_TASK_CTSTOP MMIO32(CLOCK_BASE + 0x018)
34+
35+
/* Clock events */
36+
#define CLOCK_EVENT_HFCLKSTARTED MMIO32(CLOCK_BASE + 0x100)
37+
#define CLOCK_EVENT_LFCLKSTARTED MMIO32(CLOCK_BASE + 0x104)
38+
#define CLOCK_EVENT_DONE MMIO32(CLOCK_BASE + 0x10C)
39+
#define CLOCK_EVENT_CTTO MMIO32(CLOCK_BASE + 0x110)
40+
41+
/* Clock registers */
42+
#define CLOCK_INTENSET MMIO32(CLOCK_BASE + 0x304)
43+
#define CLOCK_INTENCLR MMIO32(CLOCK_BASE + 0x308)
44+
#define CLOCK_HFCLKRUN MMIO32(CLOCK_BASE + 0x408)
45+
#define CLOCK_HFCLKSTAT MMIO32(CLOCK_BASE + 0x40C)
46+
#define CLOCK_LFCLKRUN MMIO32(CLOCK_BASE + 0x414)
47+
#define CLOCK_LFCLKSTAT MMIO32(CLOCK_BASE + 0x418)
48+
#define CLOCK_LFCLKSRCCOPY MMIO32(CLOCK_BASE + 0x41C)
49+
#define CLOCK_LFCLKSRC MMIO32(CLOCK_BASE + 0x518)
50+
#define CLOCK_CTIV MMIO32(CLOCK_BASE + 0x538)
51+
#define CLOCK_XTALFREQ MMIO32(CLOCK_BASE + 0x550)
52+
53+
/* Register contents */
54+
#define CLOCK_INTEN_HFCLKSTARTED (1 << 0)
55+
#define CLOCK_INTEN_LFCLKSTARTED (1 << 1)
56+
#define CLOCK_INTEN_DONE (1 << 3)
57+
#define CLOCK_INTEN_CTTO (1 << 4)
58+
59+
#define CLOCK_HFCLKRUN_STATUS (1 << 0)
60+
61+
#define CLOCK_HFCLKSTAT_SRC (1 << 0)
62+
#define CLOCK_HFCLKSTAT_STATE (1 << 16)
63+
64+
#define CLOCK_LFCLKRUN_STATUS (1 << 0)
65+
66+
#define CLOCK_LFCLK_SRC_SHIFT (0)
67+
#define CLOCK_LFCLK_SRC_MASK (3 << CLOCK_LFCLKSTAT_SRC_SHIFT)
68+
#define CLOCK_LFCLK_SRC_MASKED(V) (((V) << CLOCK_LFCLKSTAT_SRC_SHIFT) & CLOCK_LFCLKSTAT_SRC_MASK)
69+
70+
#define CLOCK_LFCLKSTAT_STATE (1 << 16)
71+
72+
enum clock_lfclk_src {
73+
CLOCK_LFCLK_SRC_RC,
74+
CLOCK_LFCLK_SRC_XTAL,
75+
CLOCK_LFCLK_SRC_SYNTH,
76+
};
77+
78+
enum clock_xtal_freq {
79+
CLOCK_XTAL_FREQ_32MHZ,
80+
CLOCK_XTAL_FREQ_16MHZ = 0xff,
81+
};
82+
83+
BEGIN_DECLS
84+
85+
void clock_lfclk_start(bool wait);
86+
void clock_hfclk_start(bool wait);
87+
void clock_set_xtal_freq(enum clock_xtal_freq freq);
88+
void clock_set_lfclk_src(enum clock_lfclk_src lfclk_src);
89+
90+
END_DECLS
91+
92+
#endif /* NRF51_CLOCK_H */

include/unicore-mx/nrf/51/ficr.h

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* This file is part of the unicore-mx project.
3+
*
4+
* This library is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Lesser General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This library is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public License
15+
* along with this library. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#ifndef NRF51_FICR_H
19+
#define NRF51_FICR_H
20+
21+
#include <unicore-mx/cm3/common.h>
22+
#include <unicore-mx/nrf/memorymap.h>
23+
24+
/* Factory Information Configuration Register */
25+
26+
#define FICR_CODEPAGESIZE MMIO32(FICR_BASE + 0x010)
27+
#define FICR_CODESIZE MMIO32(FICR_BASE + 0x014)
28+
29+
/* Deprecated */
30+
#define FICR_CLENR0 MMIO32(FICR_BASE + 0x028)
31+
/* Deprecated */
32+
#define FICR_PPFC MMIO32(FICR_BASE + 0x02C)
33+
34+
#define FICR_NUMRAMBLOCK MMIO32(FICR_BASE + 0x034)
35+
#define FICR_SIZERAMBLOCKS MMIO32(FICR_BASE + 0x038)
36+
37+
/* Deprecated */
38+
#define FICR_SIZERAMBLOCK(n) MMIO32(FICR_BASE + 0x038 + 0x4 * (n))
39+
40+
#define FICR_CONFIGID MMIO32(FICR_BASE + 0x05C)
41+
42+
#define FICR_DEVICEID0 MMIO32(FICR_BASE + 0x060)
43+
#define FICR_DEVICEID1 MMIO32(FICR_BASE + 0x064)
44+
45+
/* Encryption Root */
46+
#define FICR_ER(n) MMIO32(FICR_BASE + 0x080 + 0x4 * (n))
47+
#define FICR_ER0 FICR_ER(0)
48+
#define FICR_ER1 FICR_ER(1)
49+
#define FICR_ER2 FICR_ER(2)
50+
#define FICR_ER3 FICR_ER(3)
51+
52+
/* Identity Root */
53+
#define FICR_IR(n) MMIO32(FICR_BASE + 0x090 + 0x4 * (n))
54+
#define FICR_IR0 FICR_IR(0)
55+
#define FICR_IR1 FICR_IR(1)
56+
#define FICR_IR2 FICR_IR(2)
57+
#define FICR_IR3 FICR_IR(3)
58+
59+
#define FICR_DEVICEADDRTYPE MMIO32(FICR_BASE + 0x0A0)
60+
#define FICR_DEVICEADDR0 MMIO32(FICR_BASE + 0x0A4)
61+
#define FICR_DEVICEADDR1 MMIO32(FICR_BASE + 0x0A8)
62+
63+
#define FICR_OVERRIDEEN MMIO32(FICR_BASE + 0x0AC)
64+
65+
/* Override values for Nordic Semi proprietary NRF 1Mbit mode */
66+
#define FICR_NRF_1MBIT(n) MMIO32(FICR_BASE + 0x0B0 + 0x4 * (n))
67+
#define FICR_NRF_1MBIT0 FICR_NRF_1MBIT(0)
68+
#define FICR_NRF_1MBIT1 FICR_NRF_1MBIT(1)
69+
#define FICR_NRF_1MBIT2 FICR_NRF_1MBIT(2)
70+
#define FICR_NRF_1MBIT3 FICR_NRF_1MBIT(3)
71+
#define FICR_NRF_1MBIT4 FICR_NRF_1MBIT(4)
72+
73+
/* Override values for BLE 1Mbit mode */
74+
#define FICR_BLE_1MBIT(n) MMIO32(FICR_BASE + 0x0EC + 0x4 * (n))
75+
#define FICR_BLE_1MBIT0 FICR_BLE_1MBIT(0)
76+
#define FICR_BLE_1MBIT1 FICR_BLE_1MBIT(1)
77+
#define FICR_BLE_1MBIT2 FICR_BLE_1MBIT(2)
78+
#define FICR_BLE_1MBIT3 FICR_BLE_1MBIT(3)
79+
#define FICR_BLE_1MBIT4 FICR_BLE_1MBIT(4)
80+
81+
#define FICR_OVERRIDEEN_NRF_1MBIT (1 << 0)
82+
#define FICR_OVERRIDEEN_BLE_1MBIT (1 << 3)
83+
84+
#endif /* NRF51_FICR_H */

include/unicore-mx/nrf/51/gpio.h

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
/*
2+
* This file is part of the unicore-mx project.
3+
*
4+
* This library is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Lesser General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This library is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public License
15+
* along with this library. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#ifndef LIBUCMX_GPIO_H
19+
#define LIBUCMX_GPIO_H
20+
21+
#include <unicore-mx/cm3/common.h>
22+
#include <unicore-mx/nrf/memorymap.h>
23+
24+
#define GPIO (GPIO_BASE)
25+
26+
#define GPIO_OUT MMIO32(GPIO_BASE + 0x504)
27+
#define GPIO_OUTSET MMIO32(GPIO_BASE + 0x508)
28+
#define GPIO_OUTCLR MMIO32(GPIO_BASE + 0x50C)
29+
30+
#define GPIO_IN MMIO32(GPIO_BASE + 0x510)
31+
32+
#define GPIO_DIR MMIO32(GPIO_BASE + 0x514)
33+
#define GPIO_DIRSET MMIO32(GPIO_BASE + 0x518)
34+
#define GPIO_DIRCLR MMIO32(GPIO_BASE + 0x51C)
35+
36+
#define GPIO_PIN_CNF(N) MMIO32(GPIO_BASE + 0x700 + 0x4 * (N))
37+
38+
#define GPIOPIN0 (1 << 0)
39+
#define GPIOPIN1 (1 << 1)
40+
#define GPIOPIN2 (1 << 2)
41+
#define GPIOPIN3 (1 << 3)
42+
#define GPIOPIN4 (1 << 4)
43+
#define GPIOPIN5 (1 << 5)
44+
#define GPIOPIN6 (1 << 6)
45+
#define GPIOPIN7 (1 << 7)
46+
#define GPIOPIN8 (1 << 8)
47+
#define GPIOPIN9 (1 << 9)
48+
#define GPIOPIN10 (1 << 10)
49+
#define GPIOPIN11 (1 << 11)
50+
#define GPIOPIN12 (1 << 12)
51+
#define GPIOPIN13 (1 << 13)
52+
#define GPIOPIN14 (1 << 14)
53+
#define GPIOPIN15 (1 << 15)
54+
#define GPIOPIN16 (1 << 16)
55+
#define GPIOPIN17 (1 << 17)
56+
#define GPIOPIN18 (1 << 18)
57+
#define GPIOPIN19 (1 << 19)
58+
#define GPIOPIN20 (1 << 20)
59+
#define GPIOPIN21 (1 << 21)
60+
#define GPIOPIN22 (1 << 22)
61+
#define GPIOPIN23 (1 << 23)
62+
#define GPIOPIN24 (1 << 24)
63+
#define GPIOPIN25 (1 << 25)
64+
#define GPIOPIN26 (1 << 26)
65+
#define GPIOPIN27 (1 << 27)
66+
#define GPIOPIN28 (1 << 28)
67+
#define GPIOPIN29 (1 << 29)
68+
#define GPIOPIN30 (1 << 30)
69+
#define GPIOPIN31 (1 << 31)
70+
71+
#define GPIOPINN(n) (1 << (n))
72+
73+
#define PIN_CNF_DIR (1 << 0)
74+
#define PIN_CNF_INPUT (1 << 1)
75+
76+
#define PIN_CNF_PULL_SHIFT (2)
77+
#define PIN_CNF_PULL_MASK (3 << PIN_CNF_PULL_SHIFT)
78+
#define PIN_CNF_PULL_MASKED(V) (((V) << PIN_CNF_PULL_SHIFT) & PIN_CNF_PULL_MASK)
79+
80+
#define PIN_CNF_DRIVE_SHIFT (8)
81+
#define PIN_CNF_DRIVE_MASK (7 << PIN_CNF_DRIVE_SHIFT)
82+
#define PIN_CNF_DRIVE_MASKED(V) (((V) << PIN_CNF_DRIVE_SHIFT) & PIN_CNF_DRIVE_MASK)
83+
84+
#define PIN_CNF_SENSE_SHIFT (16)
85+
#define PIN_CNF_SENSE_MASK (3 << PIN_CNF_SENSE_SHIFT)
86+
#define PIN_CNF_SENSE_MASKED(V) (((V) << PIN_CNF_SENSE_SHIFT) & PIN_CNF_SENSE_MASK)
87+
88+
/* GPIO Tasks and Events (GPIOTE) */
89+
#define GPIO_TASK_OUT(n) MMIO32(GPIOTE_BASE + 0x4 * (n))
90+
#define GPIO_TASK_OUT0 GPIO_TASK_OUT(0)
91+
#define GPIO_TASK_OUT1 GPIO_TASK_OUT(1)
92+
#define GPIO_TASK_OUT2 GPIO_TASK_OUT(2)
93+
#define GPIO_TASK_OUT3 GPIO_TASK_OUT(3)
94+
95+
#define GPIO_EVENT_IN(n) MMIO32(GPIOTE_BASE + 0x100 + 0x4 * (n))
96+
#define GPIO_EVENT_IN0 GPIO_EVENT_IN(0)
97+
#define GPIO_EVENT_IN1 GPIO_EVENT_IN(1)
98+
#define GPIO_EVENT_IN2 GPIO_EVENT_IN(2)
99+
#define GPIO_EVENT_IN3 GPIO_EVENT_IN(3)
100+
101+
#define GPIO_EVENT_PORT MMIO32(GPIOTE_BASE + 0x17C)
102+
103+
#define GPIO_INTEN MMIO32(GPIOTE_BASE + 0x300)
104+
#define GPIO_INTENSET MMIO32(GPIOTE_BASE + 0x304)
105+
#define GPIO_INTENCLR MMIO32(GPIOTE_BASE + 0x308)
106+
107+
#define GPIO_TE_CONFIG(n) MMIO32(GPIOTE_BASE + 0x510 + 0x4 * (n))
108+
#define GPIO_TE_CONFIG0 GPIO_TE_CONFIG(0)
109+
#define GPIO_TE_CONFIG1 GPIO_TE_CONFIG(1)
110+
#define GPIO_TE_CONFIG2 GPIO_TE_CONFIG(2)
111+
#define GPIO_TE_CONFIG3 GPIO_TE_CONFIG(3)
112+
113+
/* Register Details */
114+
#define GPIO_INTEN_IN(n) (1 << (n))
115+
#define GPIO_INTEN_IN0 (1 << 0)
116+
#define GPIO_INTEN_IN1 (1 << 1)
117+
#define GPIO_INTEN_IN2 (1 << 2)
118+
#define GPIO_INTEN_IN3 (1 << 3)
119+
120+
#define GPIO_INTEN_PORT (1 << 31)
121+
122+
#define GPIO_TE_CONFIG_MODE_SHIFT (0)
123+
#define GPIO_TE_CONFIG_MODE_MASK (3 << GPIO_TE_CONFIG_MODE_SHIFT)
124+
#define GPIO_TE_CONFIG_MODE_MASKED(V) (((V) << GPIO_TE_CONFIG_MODE_SHIFT) & GPIO_TE_CONFIG_MODE_MASK)
125+
126+
#define GPIO_TE_CONFIG_PSEL_SHIFT (8)
127+
#define GPIO_TE_CONFIG_PSEL_MASK (0x1f << GPIO_TE_CONFIG_PSEL_SHIFT)
128+
#define GPIO_TE_CONFIG_PSEL_MASKED(V) (((V) << GPIO_TE_CONFIG_PSEL_SHIFT) & GPIO_TE_CONFIG_PSEL_MASK)
129+
130+
#define GPIO_TE_CONFIG_POLARITY_SHIFT (16)
131+
#define GPIO_TE_CONFIG_POLARITY_MASK (3 << GPIO_TE_CONFIG_POLARITY_SHIFT)
132+
#define GPIO_TE_CONFIG_POLARITY_MASKED(V) (((V) << GPIO_TE_CONFIG_POLARITY_SHIFT) & GPIO_TE_CONFIG_POLARITY_MASK)
133+
134+
#define GPIO_TE_CONFIG_OUTINIT (1 << 20)
135+
136+
#define GPIO_DIR_INPUT (0)
137+
#define GPIO_DIR_OUTPUT (1)
138+
139+
#define GPIO_INPUT_CONNECT (0)
140+
#define GPIO_INPUT_DISCONNECT (1)
141+
142+
#define GPIO_PULL_NONE (0)
143+
#define GPIO_PULL_DOWN (1)
144+
#define GPIO_PULL_UP (3)
145+
146+
#define GPIO_DRIVE_S0S1 (0)
147+
#define GPIO_DRIVE_H0S1 (1)
148+
#define GPIO_DRIVE_S0H1 (2)
149+
#define GPIO_DRIVE_H0H1 (3)
150+
#define GPIO_DRIVE_D0S1 (4)
151+
#define GPIO_DRIVE_D0H1 (5)
152+
#define GPIO_DRIVE_S0D1 (6)
153+
#define GPIO_DRIVE_H0D1 (7)
154+
155+
#define GPIO_TE_MODE_DISABLED (0)
156+
#define GPIO_TE_MODE_EVENT (1)
157+
#define GPIO_TE_MODE_TASK (3)
158+
159+
#define GPIO_TE_POLARITY_NONE (0)
160+
#define GPIO_TE_POLARITY_LO_TO_HI (1)
161+
#define GPIO_TE_POLARITY_HI_TO_LO (2)
162+
#define GPIO_TE_POLARITY_TOGGLE (3)
163+
164+
#define GPIO_TE_OUTINIT_LOW (1)
165+
#define GPIO_TE_OUTINIT_HIGH GPIO_TE_CONFIG_OUTINIT
166+
167+
BEGIN_DECLS
168+
169+
void gpio_set(uint32_t gpios);
170+
void gpio_clear(uint32_t gpios);
171+
void gpio_toggle(uint32_t gpios);
172+
uint32_t gpio_get(uint32_t gpios);
173+
174+
void gpio_setup_mode(uint32_t gpios, uint8_t dir, uint8_t pull);
175+
176+
void gpio_configure_task(uint8_t task_num,
177+
uint8_t pin_num, uint8_t polarity, uint8_t init);
178+
179+
void gpio_configure_event(uint8_t event_num, uint8_t pin_num, uint8_t polarity);
180+
181+
void gpio_enable_interrupts(uint32_t mask);
182+
void gpio_disable_interrupts(uint32_t mask);
183+
void gpio_clear_interrupts(void);
184+
185+
END_DECLS
186+
187+
#endif /* LIBUCMX_GPIO_H */

0 commit comments

Comments
 (0)