Skip to content

Commit ee7a7c5

Browse files
committed
get cmake build with 54h20 not tested on actual hw, probably not running
1 parent 87523f2 commit ee7a7c5

File tree

24 files changed

+487
-137
lines changed

24 files changed

+487
-137
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
set(MCU_VARIANT nrf54h20)
2+
3+
function(update_board TARGET)
4+
# temporarily, 54h20 has multiple sram sections
5+
target_compile_definitions(${TARGET} PUBLIC
6+
CFG_EXAMPLE_VIDEO_READONLY
7+
)
8+
target_sources(${TARGET} PRIVATE
9+
# ${NRFX_PATH}/drivers/src/nrfx_usbreg.c
10+
)
11+
endfunction()
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2020, Ha Thach (tinyusb.org)
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*
24+
* This file is part of the TinyUSB stack.
25+
*/
26+
27+
/* metadata:
28+
name: Nordic nRF5340 DK
29+
url: https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF5340-DK
30+
*/
31+
32+
#ifndef BOARD_H_
33+
#define BOARD_H_
34+
35+
#ifdef __cplusplus
36+
extern "C" {
37+
#endif
38+
39+
#define _PINNUM(port, pin) ((port)*32 + (pin))
40+
41+
// LED
42+
#define LED_PIN 28
43+
#define LED_STATE_ON 0
44+
45+
// Button
46+
#define BUTTON_PIN 23
47+
#define BUTTON_STATE_ACTIVE 0
48+
49+
// UART
50+
#define UART_RX_PIN 22
51+
#define UART_TX_PIN 20
52+
53+
// SPI for USB host shield
54+
// Pin is correct but not working probably due to signal incompatible (1.8V 3v3) with MAC3421E !?
55+
//#define MAX3421_SCK_PIN _PINNUM(1, 15)
56+
//#define MAX3421_MOSI_PIN _PINNUM(1, 13)
57+
//#define MAX3421_MISO_PIN _PINNUM(1, 14)
58+
//#define MAX3421_CS_PIN _PINNUM(1, 12)
59+
//#define MAX3421_INTR_PIN _PINNUM(1, 11)
60+
61+
#ifdef __cplusplus
62+
}
63+
#endif
64+
65+
#endif /* BOARD_H_ */
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
MCU_VARIANT = nrf54h20_application
2+
CFLAGS += -DNRF54H20_XXAA
3+
4+
# enable max3421 host driver for this board
5+
MAX3421_HOST = 1
6+
7+
LD_FILE = hw/mcu/nordic/nrfx/mdk/nrf5340_xxaa_application.ld
8+
9+
SRC_C += hw/mcu/nordic/nrfx/drivers/src/nrfx_usbreg.c
10+
11+
# caused by void SystemStoreFICRNS() (without void) in system_nrf5340_application.c
12+
CFLAGS += -Wno-error=strict-prototypes
13+
14+
# flash using jlink
15+
JLINK_DEVICE = nrf5340_xxaa_app
16+
flash: flash-jlink

hw/bsp/nrf/boards/pca10095/board.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
set(MCU_VARIANT nrf5340_application)
1+
#set(MCU_VARIANT nrf5340_application)
2+
set(MCU_VARIANT nrf5340)
23

34
function(update_board TARGET)
45
target_sources(${TARGET} PRIVATE

hw/bsp/nrf/boards/pca10095/board.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
CPU_CORE = cortex-m33
21
MCU_VARIANT = nrf5340_application
32
CFLAGS += -DNRF5340_XXAA -DNRF5340_XXAA_APPLICATION
43

hw/bsp/nrf/family.c

Lines changed: 33 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@
4545
#include "nrfx.h"
4646
#include "hal/nrf_gpio.h"
4747
#include "nrfx_gpiote.h"
48+
#if !defined(NRF54H20_XXAA)
4849
#include "nrfx_power.h"
50+
#endif
4951
#include "nrfx_uarte.h"
5052
#include "nrfx_spim.h"
5153

@@ -58,21 +60,26 @@
5860
#pragma GCC diagnostic pop
5961
#endif
6062

61-
62-
// There is API changes between nrfx v2 and v3
63-
#if 85301 >= (10000*MDK_MAJOR_VERSION + 100*MDK_MINOR_VERSION + MDK_MICRO_VERSION)
64-
// note MDK 8.53.1 is also used by nrfx v3.0.0, just skip this version and use later 3.x
65-
#define NRFX_VER 2
66-
#else
67-
#define NRFX_VER 3
63+
// example only supports nrfx v3 for code simplicity
64+
#if !(defined(NRFX_CONFIG_API_VER_MAJOR) && NRFX_CONFIG_API_VER_MAJOR >= 3) && \
65+
!(85301 >= (10000*MDK_MAJOR_VERSION + 100*MDK_MINOR_VERSION + MDK_MICRO_VERSION))
66+
#error "Example requires nrfx v3.0.0 or later"
6867
#endif
6968

7069
//--------------------------------------------------------------------+
7170
// Forward USB interrupt events to TinyUSB IRQ Handler
7271
//--------------------------------------------------------------------+
72+
#if defined(NRF54H20_XXAA)
73+
#define USBD_IRQn USBHS_IRQn
74+
void USBHS_IRQHandler(void) {
75+
tusb_int_handler(0, true);
76+
}
77+
78+
#else
7379
void USBD_IRQHandler(void) {
7480
tud_int_handler(0);
7581
}
82+
#endif
7683

7784
/*------------------------------------------------------------------*/
7885
/* MACRO TYPEDEF CONSTANT ENUM
@@ -96,39 +103,39 @@ enum {
96103
#define OUTPUTRDY_Msk POWER_USBREGSTATUS_OUTPUTRDY_Msk
97104
#endif
98105

99-
static nrfx_uarte_t _uart_id = NRFX_UARTE_INSTANCE(0);
106+
static nrfx_uarte_t _uart_id = NRFX_UARTE_INSTANCE(CFG_NRFX_UARTE_INSTANCE_ID);
100107

101108
// tinyusb function that handles power event (detected, ready, removed)
102109
// We must call it within SD's SOC event handler, or set it as power event handler if SD is not enabled.
103110
extern void tusb_hal_nrf_power_event(uint32_t event);
104111

112+
#if !defined(NRF54H20_XXAA)
105113
// nrf power callback, could be unused if SD is enabled or usb is disabled (board_test example)
106114
TU_ATTR_UNUSED static void power_event_handler(nrfx_power_usb_evt_t event) {
107115
tusb_hal_nrf_power_event((uint32_t) event);
108116
}
117+
#endif
109118

110119
//------------- Host using MAX2341E -------------//
111120
#if CFG_TUH_ENABLED && defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
112121
static void max3421_init(void);
113122
static nrfx_spim_t _spi = NRFX_SPIM_INSTANCE(1);
114-
115-
#if NRFX_VER > 2
116123
static nrfx_gpiote_t _gpiote = NRFX_GPIOTE_INSTANCE(0);
117124
#endif
118125

119-
#endif
120-
121126
//--------------------------------------------------------------------+
122127
//
123128
//--------------------------------------------------------------------+
124129

125130
void board_init(void) {
131+
#if !defined(NRF54H20_XXAA)
126132
// stop LF clock just in case we jump from application without reset
127133
NRF_CLOCK->TASKS_LFCLKSTOP = 1UL;
128134

129135
// Use Internal OSC to compatible with all boards
130136
NRF_CLOCK->LFCLKSRC = LFCLK_SRC_RC;
131137
NRF_CLOCK->TASKS_LFCLKSTART = 1UL;
138+
#endif
132139

133140
// LED
134141
nrf_gpio_cfg_output(LED_PIN);
@@ -140,6 +147,7 @@ void board_init(void) {
140147
#if CFG_TUSB_OS == OPT_OS_NONE
141148
// 1ms tick timer
142149
SysTick_Config(SystemCoreClock / 1000);
150+
143151
#elif CFG_TUSB_OS == OPT_OS_ZEPHYR
144152
#ifdef CONFIG_HAS_HW_NRF_USBREG
145153
// IRQ_CONNECT(USBREGULATOR_IRQn, DT_IRQ(DT_INST(0, nordic_nrf_clock), priority), nrfx_isr, nrfx_usbreg_irq_handler, 0);
@@ -153,21 +161,6 @@ void board_init(void) {
153161
#endif
154162

155163
// UART
156-
#if NRFX_VER <= 2
157-
nrfx_uarte_config_t uart_cfg = {
158-
.pseltxd = UART_TX_PIN,
159-
.pselrxd = UART_RX_PIN,
160-
.pselcts = NRF_UARTE_PSEL_DISCONNECTED,
161-
.pselrts = NRF_UARTE_PSEL_DISCONNECTED,
162-
.p_context = NULL,
163-
.baudrate = NRF_UARTE_BAUDRATE_115200, // CFG_BOARD_UART_BAUDRATE
164-
.interrupt_priority = 7,
165-
.hal_cfg = {
166-
.hwfc = NRF_UARTE_HWFC_DISABLED,
167-
.parity = NRF_UARTE_PARITY_EXCLUDED,
168-
}
169-
};
170-
#else
171164
nrfx_uarte_config_t uart_cfg = {
172165
.txd_pin = UART_TX_PIN,
173166
.rxd_pin = UART_RX_PIN,
@@ -181,7 +174,6 @@ void board_init(void) {
181174
.parity = NRF_UARTE_PARITY_EXCLUDED,
182175
}
183176
};
184-
#endif
185177

186178
nrfx_uarte_init(&_uart_id, &uart_cfg, NULL);
187179

@@ -191,6 +183,7 @@ void board_init(void) {
191183
// 2 is highest for application
192184
NVIC_SetPriority(USBD_IRQn, 2);
193185

186+
#if !defined(NRF54H20_XXAA)
194187
// USB power may already be ready at this time -> no event generated
195188
// We need to invoke the handler based on the status initially
196189
uint32_t usb_reg;
@@ -234,6 +227,7 @@ void board_init(void) {
234227
tusb_hal_nrf_power_event(USB_EVT_READY);
235228
}
236229
#endif
230+
#endif
237231

238232
#if CFG_TUH_ENABLED && defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
239233
max3421_init();
@@ -255,7 +249,9 @@ uint32_t board_button_read(void) {
255249
size_t board_get_unique_id(uint8_t id[], size_t max_len) {
256250
(void) max_len;
257251

258-
#ifdef NRF5340_XXAA
252+
#if defined(NRF54H20_XXAA)
253+
uintptr_t did_addr = (uintptr_t) NRF_FICR->BLE.ADDR;
254+
#elif defined(NRF5340_XXAA)
259255
uintptr_t did_addr = (uintptr_t) NRF_FICR->INFO.DEVICEID;
260256
#else
261257
uintptr_t did_addr = (uintptr_t) NRF_FICR->DEVICEID;
@@ -277,11 +273,7 @@ int board_uart_read(uint8_t* buf, int len) {
277273
}
278274

279275
int board_uart_write(void const* buf, int len) {
280-
nrfx_err_t err = nrfx_uarte_tx(&_uart_id, (uint8_t const*) buf, (size_t) len
281-
#if NRFX_VER > 2
282-
,0
283-
#endif
284-
);
276+
nrfx_err_t err = nrfx_uarte_tx(&_uart_id, (uint8_t const*) buf, (size_t) len ,0);
285277
return (NRFX_SUCCESS == err) ? len : 0;
286278
}
287279

@@ -352,18 +344,16 @@ void nrf_error_cb(uint32_t id, uint32_t pc, uint32_t info) {
352344
// API: SPI transfer with MAX3421E, must be implemented by application
353345
//--------------------------------------------------------------------+
354346
#if CFG_TUH_ENABLED && defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
355-
356-
#if NRFX_VER <= 2
357-
void max3421_int_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action ) {
358-
if (action != NRF_GPIOTE_POLARITY_HITOLO) return;
359-
#else
360347
void max3421_int_handler(nrfx_gpiote_pin_t pin, nrfx_gpiote_trigger_t action, void* p_context) {
361348
(void) p_context;
362-
if (action != NRFX_GPIOTE_TRIGGER_HITOLO) return;
363-
#endif
349+
if (action != NRFX_GPIOTE_TRIGGER_HITOLO) {
350+
return;
351+
}
352+
if (pin != MAX3421_INTR_PIN) {
353+
return;
354+
}
364355

365-
if (pin != MAX3421_INTR_PIN) return;
366-
tuh_int_handler(1, true);
356+
tusb_int_handler(1, true);
367357
}
368358

369359
static void max3421_init(void) {
@@ -378,13 +368,8 @@ static void max3421_init(void) {
378368
.sck_pin = MAX3421_SCK_PIN,
379369
.mosi_pin = MAX3421_MOSI_PIN,
380370
.miso_pin = MAX3421_MISO_PIN,
381-
#if NRFX_VER <= 2
382-
.ss_pin = NRFX_SPIM_PIN_NOT_USED,
383-
.frequency = NRF_SPIM_FREQ_4M,
384-
#else
385371
.ss_pin = NRF_SPIM_PIN_NOT_CONNECTED,
386372
.frequency = 4000000u,
387-
#endif
388373
.ss_active_high = false,
389374
.irq_priority = 3,
390375
.orc = 0xFF,
@@ -398,14 +383,6 @@ static void max3421_init(void) {
398383
TU_ASSERT(NRFX_SUCCESS == nrfx_spim_init(&_spi, &cfg, NULL, NULL), );
399384

400385
// max3421e interrupt pin
401-
#if NRFX_VER <= 2
402-
nrfx_gpiote_init(1);
403-
nrfx_gpiote_in_config_t in_config = NRFX_GPIOTE_CONFIG_IN_SENSE_HITOLO(true);
404-
in_config.pull = NRF_GPIO_PIN_PULLUP;
405-
NVIC_SetPriority(GPIOTE_IRQn, 2);
406-
nrfx_gpiote_in_init(MAX3421_INTR_PIN, &in_config, max3421_int_handler);
407-
nrfx_gpiote_trigger_enable(MAX3421_INTR_PIN, true);
408-
#else
409386
nrf_gpio_pin_pull_t intr_pull = NRF_GPIO_PIN_PULLUP;
410387
nrfx_gpiote_trigger_config_t intr_trigger = {
411388
.trigger = NRFX_GPIOTE_TRIGGER_HITOLO,
@@ -426,7 +403,6 @@ static void max3421_init(void) {
426403

427404
nrfx_gpiote_input_configure(&_gpiote, MAX3421_INTR_PIN, &intr_config);
428405
nrfx_gpiote_trigger_enable(&_gpiote, MAX3421_INTR_PIN, true);
429-
#endif
430406
}
431407

432408
// API to enable/disable MAX3421 INTR pin interrupt

0 commit comments

Comments
 (0)