adding log support with uart

started with pca10056
This commit is contained in:
hathach
2019-10-12 00:00:08 +07:00
parent d9ef34276b
commit 195d0f5a14
13 changed files with 233 additions and 195 deletions
+1
View File
@@ -24,6 +24,7 @@ LDFLAGS += -L$(TOP)/hw/mcu/nordic/nrfx/mdk
SRC_C += \
hw/mcu/nordic/nrfx/drivers/src/nrfx_power.c \
hw/mcu/nordic/nrfx/drivers/src/nrfx_uart.c \
hw/mcu/nordic/nrfx/mdk/system_nrf52840.c \
INC += \
+28 -3
View File
@@ -29,6 +29,7 @@
#include "nrfx.h"
#include "nrfx/hal/nrf_gpio.h"
#include "nrfx/drivers/include/nrfx_power.h"
#include "nrfx/drivers/include/nrfx_uart.h"
#ifdef SOFTDEVICE_PRESENT
#include "nrf_sdm.h"
@@ -44,6 +45,12 @@
#define BUTTON_PIN 11
#define BUTTON_STATE_ACTIVE 0
#define UART_RX_PIN 8
#define UART_TX_PIN 6
static nrfx_uart_t _uart_id = NRFX_UART_INSTANCE(0);
//static void uart_handler(nrfx_uart_event_t const * p_event, void* p_context);
// tinyusb function that handles power event (detected, ready, removed)
// We must call it within SD's SOC event handler, or set it as power event handler if SD is not enabled.
extern void tusb_hal_nrf_power_event(uint32_t event);
@@ -69,6 +76,21 @@ void board_init(void)
SysTick_Config(SystemCoreClock/1000);
#endif
// UART
nrfx_uart_config_t uart_cfg =
{
.pseltxd = UART_TX_PIN,
.pselrxd = UART_RX_PIN,
.pselcts = NRF_UART_PSEL_DISCONNECTED,
.pselrts = NRF_UART_PSEL_DISCONNECTED,
.p_context = NULL,
.hwfc = NRF_UART_HWFC_DISABLED,
.parity = NRF_UART_PARITY_EXCLUDED,
.baudrate = NRF_UART_BAUDRATE_115200 // CFG_BOARD_UART_BAUDRATE
};
nrfx_uart_init(&_uart_id, &uart_cfg, NULL); //uart_handler);
#if TUSB_OPT_DEVICE_ENABLED
// Priorities 0, 1, 4 (nRF52) are reserved for SoftDevice
// 2 is highest for application
@@ -124,6 +146,11 @@ uint32_t board_button_read(void)
return BUTTON_STATE_ACTIVE == nrf_gpio_pin_read(BUTTON_PIN);
}
//static void uart_handler(nrfx_uart_event_t const * p_event, void* p_context)
//{
//
//}
int board_uart_read(uint8_t* buf, int len)
{
(void) buf;
@@ -133,9 +160,7 @@ int board_uart_read(uint8_t* buf, int len)
int board_uart_write(void const * buf, int len)
{
(void) buf;
(void) len;
return 0;
return (NRFX_SUCCESS == nrfx_uart_tx(&_uart_id, (uint8_t const*) buf, (size_t) len)) ? len : 0;
}
#if CFG_TUSB_OS == OPT_OS_NONE