Skip to content

Commit 1fb8197

Browse files
authored
Merge pull request adafruit#1036 from hathach/fix_nrf52840_serial
Fix nrf52840 serial mentioned adafruit#1021
2 parents 617351a + bb28faf commit 1fb8197

File tree

10 files changed

+264
-133
lines changed

10 files changed

+264
-133
lines changed

ports/nrf/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ SRC_C += \
102102
tick.c \
103103
background.c \
104104
internal_flash.c \
105+
interrupt_char.c \
105106
drivers/bluetooth/ble_drv.c \
106107
drivers/bluetooth/ble_uart.c \
107108
boards/$(BOARD)/board.c \
@@ -113,7 +114,6 @@ SRC_C += \
113114
lib/timeutils/timeutils.c \
114115
lib/utils/buffer_helper.c \
115116
lib/utils/context_manager_helpers.c \
116-
lib/utils/interrupt_char.c \
117117
lib/utils/pyexec.c \
118118
lib/utils/stdout_helpers.c \
119119
lib/libc/string0.c \
@@ -122,7 +122,7 @@ SRC_C += \
122122
ifeq ($(MCU_SUB_VARIANT),nrf52840)
123123

124124
SRC_C += \
125-
usb/tusb_descriptors.c \
125+
usb/usb.c \
126126
usb/usb_msc_flash.c \
127127
lib/tinyusb/src/portable/nordic/nrf5x/dcd_nrf5x.c \
128128
lib/tinyusb/src/portable/nordic/nrf5x/hal_nrf5x.c \

ports/nrf/README.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,10 @@ Prerequisite steps for building the nrf port:
5151
git submodule update --init
5252
make -C mpy-cross
5353

54-
By default, the feather52832 is used as compile target. To build and flash issue the following command inside the ports/nrf/ folder:
54+
To build and flash issue the following command inside the ports/nrf/ folder:
5555

56-
make
57-
make flash
58-
59-
Alternatively the target board could be defined:
60-
61-
make BOARD=pca10056
62-
make flash
56+
make BOARD=pca10056
57+
make BOARD=pca10056 flash
6358

6459
## Compile and Flash with Bluetooth Stack
6560

ports/nrf/background.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@
2929
void run_background_tasks(void) {
3030
#ifdef NRF52840_XXAA
3131
tusb_task();
32-
tud_cdc_flush();
32+
tud_cdc_write_flush();
3333
#endif
3434
}

ports/nrf/boards/pca10056/board.c

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -26,41 +26,17 @@
2626

2727
#include <string.h>
2828
#include <stdbool.h>
29-
30-
#include "nrfx.h"
31-
#include "nrfx_power.h"
3229
#include "boards/board.h"
33-
34-
#include "tick.h"
35-
#include "tusb.h"
30+
#include "nrfx.h"
31+
#include "usb.h"
3632

3733
void board_init(void) {
3834

3935
// Clock
4036
NRF_CLOCK->LFCLKSRC = (uint32_t)((CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos) & CLOCK_LFCLKSRC_SRC_Msk);
4137
NRF_CLOCK->TASKS_LFCLKSTART = 1UL;
4238

43-
// Init USB
44-
45-
#ifdef SOFTDEVICE_PRESENT
46-
// TODO support Softdevice config
47-
#else
48-
// Softdevice is not present, init power module and register tusb power event function
49-
// for vusb detect, ready, removed
50-
extern void tusb_hal_nrf_power_event(uint32_t event);
51-
52-
// Power module init
53-
const nrfx_power_config_t pwr_cfg = { 0 };
54-
nrfx_power_init(&pwr_cfg);
55-
56-
// USB Power detection
57-
const nrfx_power_usbevt_config_t config = { .handler = (nrfx_power_usb_event_handler_t) tusb_hal_nrf_power_event };
58-
nrfx_power_usbevt_init(&config);
59-
60-
nrfx_power_usbevt_enable();
61-
#endif
62-
63-
tusb_init();
39+
usb_init();
6440
}
6541

6642
bool board_requests_safe_mode(void) {
@@ -72,21 +48,6 @@ void reset_board(void) {
7248
}
7349

7450

75-
//--------------------------------------------------------------------+
76-
// tinyusb callbacks
77-
//--------------------------------------------------------------------+
78-
void tud_mount_cb(uint8_t rhport) {
79-
(void) rhport;
80-
}
8151

82-
void tud_umount_cb(uint8_t rhport) {
83-
(void) rhport;
84-
}
8552

86-
uint32_t tusb_hal_millis(void) {
87-
uint64_t ms;
88-
uint32_t us;
89-
current_tick(&ms, &us);
90-
return (uint32_t) ms;
91-
}
9253

ports/nrf/interrupt_char.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2013-2016 Damien P. George
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+
#include "py/obj.h"
28+
#include "py/mpstate.h"
29+
30+
#ifdef NRF52840_XXAA
31+
#include "usb.h"
32+
#endif
33+
34+
#if MICROPY_KBD_EXCEPTION
35+
36+
int mp_interrupt_char;
37+
38+
void mp_hal_set_interrupt_char(int c) {
39+
if (c != -1) {
40+
mp_obj_exception_clear_traceback(MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)));
41+
}
42+
mp_interrupt_char = c;
43+
44+
#ifdef NRF52840_XXAA
45+
tud_cdc_set_wanted_char(c);
46+
#endif
47+
}
48+
49+
void mp_keyboard_interrupt(void) {
50+
MP_STATE_VM(mp_pending_exception) = MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception));
51+
#if MICROPY_ENABLE_SCHEDULER
52+
if (MP_STATE_VM(sched_state) == MP_SCHED_IDLE) {
53+
MP_STATE_VM(sched_state) = MP_SCHED_PENDING;
54+
}
55+
#endif
56+
}
57+
58+
#endif

ports/nrf/mpconfigport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ extern const struct _mp_obj_module_t mp_module_ubluepy;
232232
// We need to provide a declaration/definition of alloca()
233233
#include <alloca.h>
234234

235-
extern void run_background_tasks(void);
235+
void run_background_tasks(void);
236236
#define MICROPY_VM_HOOK_LOOP run_background_tasks();
237237
#define MICROPY_VM_HOOK_RETURN run_background_tasks();
238238

ports/nrf/usb/tusb_descriptors.c

Lines changed: 0 additions & 78 deletions
This file was deleted.

0 commit comments

Comments
 (0)