Skip to content

Commit

Permalink
Merge pull request #1036 from hathach/fix_nrf52840_serial
Browse files Browse the repository at this point in the history
Fix nrf52840 serial mentioned #1021
  • Loading branch information
arturo182 committed Jul 18, 2018
2 parents 617351a + bb28faf commit 1fb8197
Show file tree
Hide file tree
Showing 10 changed files with 264 additions and 133 deletions.
4 changes: 2 additions & 2 deletions ports/nrf/Makefile
Expand Up @@ -102,6 +102,7 @@ SRC_C += \
tick.c \
background.c \
internal_flash.c \
interrupt_char.c \
drivers/bluetooth/ble_drv.c \
drivers/bluetooth/ble_uart.c \
boards/$(BOARD)/board.c \
Expand All @@ -113,7 +114,6 @@ SRC_C += \
lib/timeutils/timeutils.c \
lib/utils/buffer_helper.c \
lib/utils/context_manager_helpers.c \
lib/utils/interrupt_char.c \
lib/utils/pyexec.c \
lib/utils/stdout_helpers.c \
lib/libc/string0.c \
Expand All @@ -122,7 +122,7 @@ SRC_C += \
ifeq ($(MCU_SUB_VARIANT),nrf52840)

SRC_C += \
usb/tusb_descriptors.c \
usb/usb.c \
usb/usb_msc_flash.c \
lib/tinyusb/src/portable/nordic/nrf5x/dcd_nrf5x.c \
lib/tinyusb/src/portable/nordic/nrf5x/hal_nrf5x.c \
Expand Down
11 changes: 3 additions & 8 deletions ports/nrf/README.md
Expand Up @@ -51,15 +51,10 @@ Prerequisite steps for building the nrf port:
git submodule update --init
make -C mpy-cross

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

make
make flash

Alternatively the target board could be defined:

make BOARD=pca10056
make flash
make BOARD=pca10056
make BOARD=pca10056 flash

## Compile and Flash with Bluetooth Stack

Expand Down
2 changes: 1 addition & 1 deletion ports/nrf/background.c
Expand Up @@ -29,6 +29,6 @@
void run_background_tasks(void) {
#ifdef NRF52840_XXAA
tusb_task();
tud_cdc_flush();
tud_cdc_write_flush();
#endif
}
45 changes: 3 additions & 42 deletions ports/nrf/boards/pca10056/board.c
Expand Up @@ -26,41 +26,17 @@

#include <string.h>
#include <stdbool.h>

#include "nrfx.h"
#include "nrfx_power.h"
#include "boards/board.h"

#include "tick.h"
#include "tusb.h"
#include "nrfx.h"
#include "usb.h"

void board_init(void) {

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

// Init USB

#ifdef SOFTDEVICE_PRESENT
// TODO support Softdevice config
#else
// Softdevice is not present, init power module and register tusb power event function
// for vusb detect, ready, removed
extern void tusb_hal_nrf_power_event(uint32_t event);

// Power module init
const nrfx_power_config_t pwr_cfg = { 0 };
nrfx_power_init(&pwr_cfg);

// USB Power detection
const nrfx_power_usbevt_config_t config = { .handler = (nrfx_power_usb_event_handler_t) tusb_hal_nrf_power_event };
nrfx_power_usbevt_init(&config);

nrfx_power_usbevt_enable();
#endif

tusb_init();
usb_init();
}

bool board_requests_safe_mode(void) {
Expand All @@ -72,21 +48,6 @@ void reset_board(void) {
}


//--------------------------------------------------------------------+
// tinyusb callbacks
//--------------------------------------------------------------------+
void tud_mount_cb(uint8_t rhport) {
(void) rhport;
}

void tud_umount_cb(uint8_t rhport) {
(void) rhport;
}

uint32_t tusb_hal_millis(void) {
uint64_t ms;
uint32_t us;
current_tick(&ms, &us);
return (uint32_t) ms;
}

58 changes: 58 additions & 0 deletions ports/nrf/interrupt_char.c
@@ -0,0 +1,58 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2013-2016 Damien P. George
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#include "py/obj.h"
#include "py/mpstate.h"

#ifdef NRF52840_XXAA
#include "usb.h"
#endif

#if MICROPY_KBD_EXCEPTION

int mp_interrupt_char;

void mp_hal_set_interrupt_char(int c) {
if (c != -1) {
mp_obj_exception_clear_traceback(MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)));
}
mp_interrupt_char = c;

#ifdef NRF52840_XXAA
tud_cdc_set_wanted_char(c);
#endif
}

void mp_keyboard_interrupt(void) {
MP_STATE_VM(mp_pending_exception) = MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception));
#if MICROPY_ENABLE_SCHEDULER
if (MP_STATE_VM(sched_state) == MP_SCHED_IDLE) {
MP_STATE_VM(sched_state) = MP_SCHED_PENDING;
}
#endif
}

#endif
2 changes: 1 addition & 1 deletion ports/nrf/mpconfigport.h
Expand Up @@ -232,7 +232,7 @@ extern const struct _mp_obj_module_t mp_module_ubluepy;
// We need to provide a declaration/definition of alloca()
#include <alloca.h>

extern void run_background_tasks(void);
void run_background_tasks(void);
#define MICROPY_VM_HOOK_LOOP run_background_tasks();
#define MICROPY_VM_HOOK_RETURN run_background_tasks();

Expand Down
78 changes: 0 additions & 78 deletions ports/nrf/usb/tusb_descriptors.c

This file was deleted.

0 comments on commit 1fb8197

Please sign in to comment.