replace jlink with native usb cdc for serial REPL
This commit is contained in:
parent
be2ff20e42
commit
1745e20391
@ -116,6 +116,7 @@ SRC_C += \
|
||||
boards/$(BOARD)/board.c \
|
||||
nrfx/mdk/system_$(MCU_SUB_VARIANT).c \
|
||||
device/$(MCU_VARIANT)/startup_$(MCU_SUB_VARIANT).c \
|
||||
background.c \
|
||||
lib/oofatfs/ff.c \
|
||||
lib/oofatfs/option/ccsbcs.c \
|
||||
lib/timeutils/timeutils.c \
|
||||
@ -127,6 +128,7 @@ SRC_C += \
|
||||
lib/mp-readline/readline.c \
|
||||
internal_flash.c \
|
||||
|
||||
# lib/utils/stdout_helpers.c
|
||||
|
||||
ifeq ($(MCU_SUB_VARIANT),nrf52840)
|
||||
|
||||
|
54
ports/nrf/background.c
Normal file
54
ports/nrf/background.c
Normal file
@ -0,0 +1,54 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file background.c
|
||||
@author hathach (tinyusb.org)
|
||||
|
||||
@section LICENSE
|
||||
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2018, Adafruit Industries (adafruit.com)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holders nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
|
||||
#include "tusb.h"
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* MACRO TYPEDEF CONSTANT ENUM
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* VARIABLE DECLARATION
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* FUNCTION DECLARATION
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
void run_background_tasks(void) {
|
||||
tusb_task();
|
||||
tud_cdc_flush();
|
||||
}
|
@ -254,6 +254,10 @@ extern const struct _mp_obj_module_t ble_module;
|
||||
// We need to provide a declaration/definition of alloca()
|
||||
#include <alloca.h>
|
||||
|
||||
extern void run_background_tasks(void);
|
||||
#define MICROPY_VM_HOOK_LOOP run_background_tasks();
|
||||
#define MICROPY_VM_HOOK_RETURN run_background_tasks();
|
||||
|
||||
//#define CIRCUITPY_BOOT_OUTPUT_FILE "/boot_out.txt"
|
||||
|
||||
#endif
|
||||
|
@ -32,6 +32,8 @@
|
||||
#include "py/mperrno.h"
|
||||
#include "hal_uart.h"
|
||||
|
||||
#ifndef NRF52840_XXAA
|
||||
|
||||
#define UART_INSTANCE UART_BASE(0)
|
||||
|
||||
#if (MICROPY_PY_BLE_NUS == 0)
|
||||
@ -84,3 +86,60 @@ void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len) {
|
||||
void mp_hal_stdout_tx_str(const char *str) {
|
||||
mp_hal_stdout_tx_strn(str, strlen(str));
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include "tusb.h"
|
||||
|
||||
int mp_hal_stdin_rx_chr(void) {
|
||||
for (;;) {
|
||||
#ifdef MICROPY_VM_HOOK_LOOP
|
||||
MICROPY_VM_HOOK_LOOP
|
||||
#endif
|
||||
// if (reload_requested) {
|
||||
// return CHAR_CTRL_D;
|
||||
// }
|
||||
if (tud_cdc_available()) {
|
||||
#ifdef MICROPY_HW_LED_RX
|
||||
gpio_toggle_pin_level(MICROPY_HW_LED_RX);
|
||||
#endif
|
||||
return tud_cdc_read_char();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool mp_hal_stdin_any(void) {
|
||||
return tud_cdc_available() > 0;
|
||||
}
|
||||
|
||||
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
|
||||
|
||||
// #ifdef MICROPY_HW_LED_TX
|
||||
// gpio_toggle_pin_level(MICROPY_HW_LED_TX);
|
||||
// #endif
|
||||
//
|
||||
// #ifdef CIRCUITPY_BOOT_OUTPUT_FILE
|
||||
// if (boot_output_file != NULL) {
|
||||
// UINT bytes_written = 0;
|
||||
// f_write(boot_output_file, str, len, &bytes_written);
|
||||
// }
|
||||
// #endif
|
||||
|
||||
tud_cdc_write(str, len);
|
||||
}
|
||||
|
||||
void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) {
|
||||
while (len--) {
|
||||
if (*str == '\n') {
|
||||
mp_hal_stdout_tx_strn("\r", 1);
|
||||
}
|
||||
mp_hal_stdout_tx_strn(str++, 1);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void mp_hal_stdout_tx_str(const char *str) {
|
||||
mp_hal_stdout_tx_strn(str, strlen(str));
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,8 @@
|
||||
#include "ble_uart.h"
|
||||
#endif
|
||||
|
||||
#ifndef NRF52840_XXAA
|
||||
|
||||
void serial_init(void) {
|
||||
|
||||
#if MICROPY_PY_BLE_NUS
|
||||
@ -84,3 +86,30 @@ void serial_write(const char* text) {
|
||||
mp_hal_stdout_tx_str(text);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include "tusb.h"
|
||||
|
||||
void serial_init(void) {
|
||||
// usb should be initialized in board_init()
|
||||
}
|
||||
|
||||
|
||||
bool serial_connected(void) {
|
||||
return tud_cdc_connected();
|
||||
}
|
||||
|
||||
char serial_read(void) {
|
||||
return (char) tud_cdc_read_char();
|
||||
}
|
||||
|
||||
bool serial_bytes_available(void) {
|
||||
return tud_cdc_available() > 0;
|
||||
}
|
||||
|
||||
void serial_write(const char* text) {
|
||||
tud_cdc_write(text, strlen(text));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -52,8 +52,8 @@
|
||||
|
||||
/*------------- RTOS -------------*/
|
||||
#define CFG_TUSB_OS OPT_OS_NONE
|
||||
//#define CFG_TUD_TASK_PRIO 0
|
||||
//#define CFG_TUD_TASK_QUEUE_SZ 16
|
||||
//#define CFG_TUD_TASK_PRIO 0
|
||||
//#define CFG_TUD_TASK_STACK_SZ 150
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
@ -90,7 +90,7 @@
|
||||
#define CFG_TUD_CDC_FLUSH_ON_SOF 0
|
||||
|
||||
// Number of supported Logical Unit Number (At least 1)
|
||||
#define CFG_TUD_MSC_MAXLUN 1
|
||||
#define CFG_TUD_MSC_MAXLUN 1
|
||||
|
||||
// Number of Blocks
|
||||
#define CFG_TUD_MSC_BLOCK_NUM (256*1024)/512
|
||||
|
Loading…
x
Reference in New Issue
Block a user