Skip to content

Commit 3657f7e

Browse files
wiktorkwiatkowskisjanc
authored andcommitted
hw/bsp/arduino-zero: route default UART to debugger, add UART1
The default UART used for logging (console_printf) is now routed through the debugger interface instead of external TX/RX pins, making serial output easier to access via USB cable. Additionally, UART1 has been configured and exposed on external pins for user applications.
1 parent fd2a896 commit 3657f7e

File tree

3 files changed

+43
-17
lines changed

3 files changed

+43
-17
lines changed

hw/bsp/arduino_zero/pkg.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,9 @@ pkg.deps.UART_0:
2929
- "@apache-mynewt-core/hw/drivers/uart"
3030
- "@apache-mynewt-core/hw/drivers/uart/uart_hal"
3131

32+
pkg.deps.UART_1:
33+
- "@apache-mynewt-core/hw/drivers/uart"
34+
- "@apache-mynewt-core/hw/drivers/uart/uart_hal"
35+
3236
pkg.cflags:
3337
- -D__SAMD21G18A__

hw/bsp/arduino_zero/src/hal_bsp.c

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,11 @@
4646
#include <usart.h>
4747

4848
#include <os/os_dev.h>
49-
#if MYNEWT_VAL(UART_0)
49+
#if MYNEWT_VAL(UART_0) || MYNEWT_VAL(UART_1)
5050
#include <uart/uart.h>
5151
#include <uart_hal/uart_hal.h>
5252
#include <mcu/hal_uart.h>
5353

54-
static struct uart_dev hal_uart0;
5554
#endif
5655
#if MYNEWT_VAL(SPI_0)
5756
/* configure the SPI port for arduino external spi */
@@ -84,18 +83,31 @@ struct samd21_i2c_config i2c_config = {
8483
#endif
8584

8685
#if MYNEWT_VAL(UART_0)
87-
static const struct samd21_uart_config uart_cfgs[] = {
88-
[0] = {
89-
.suc_sercom = SERCOM2,
90-
.suc_mux_setting = USART_RX_3_TX_2_XCK_3,
91-
.suc_generator_source = GCLK_GENERATOR_0,
92-
.suc_sample_rate = USART_SAMPLE_RATE_16X_ARITHMETIC,
93-
.suc_sample_adjustment = USART_SAMPLE_ADJUSTMENT_7_8_9,
94-
.suc_pad0 = 0,
95-
.suc_pad1 = 0,
96-
.suc_pad2 = PINMUX_PA10D_SERCOM2_PAD2,
97-
.suc_pad3 = PINMUX_PA11D_SERCOM2_PAD3
98-
}
86+
static const struct samd21_uart_config uart0_cfg = {
87+
.suc_sercom = SERCOM5,
88+
.suc_mux_setting = USART_RX_3_TX_2_XCK_3,
89+
.suc_generator_source = GCLK_GENERATOR_0,
90+
.suc_sample_rate = USART_SAMPLE_RATE_16X_ARITHMETIC,
91+
.suc_sample_adjustment = USART_SAMPLE_ADJUSTMENT_7_8_9,
92+
.suc_pad0 = PINMUX_UNUSED,
93+
.suc_pad1 = PINMUX_UNUSED,
94+
.suc_pad2 = PINMUX_PB22D_SERCOM5_PAD2,
95+
.suc_pad3 = PINMUX_PB23D_SERCOM5_PAD3,
96+
};
97+
#endif
98+
99+
#if MYNEWT_VAL(UART_1)
100+
static const struct samd21_uart_config uart1_cfg = {
101+
.suc_sercom = SERCOM2,
102+
.suc_mux_setting = USART_RX_3_TX_2_XCK_3,
103+
.suc_generator_source = GCLK_GENERATOR_0,
104+
.suc_sample_rate = USART_SAMPLE_RATE_16X_ARITHMETIC,
105+
.suc_sample_adjustment = USART_SAMPLE_ADJUSTMENT_7_8_9,
106+
.suc_pad0 = PINMUX_UNUSED,
107+
.suc_pad1 = PINMUX_UNUSED,
108+
.suc_pad2 = PINMUX_PA10D_SERCOM2_PAD2,
109+
.suc_pad3 = PINMUX_PA11D_SERCOM2_PAD3
110+
99111
};
100112
#endif
101113

@@ -129,7 +141,6 @@ hal_bsp_core_dump(int *area_cnt)
129141
return dump_cfg;
130142
}
131143

132-
133144
/**
134145
* Returns the configured priority for the given interrupt. If no priority
135146
* configured, return the priority passed in
@@ -157,8 +168,16 @@ hal_bsp_init(void)
157168
#endif
158169

159170
#if MYNEWT_VAL(UART_0)
160-
rc = os_dev_create((struct os_dev *) &hal_uart0, "uart0",
161-
OS_DEV_INIT_PRIMARY, 0, uart_hal_init, (void *)&uart_cfgs[0]);
171+
static struct uart_dev hal_uart0;
172+
rc = os_dev_create((struct os_dev *)&hal_uart0, "uart0", OS_DEV_INIT_PRIMARY,
173+
0, uart_hal_init, (void *)&uart0_cfg);
174+
SYSINIT_PANIC_ASSERT(rc == 0);
175+
#endif
176+
177+
#if MYNEWT_VAL(UART_1)
178+
static struct uart_dev hal_uart1;
179+
rc = os_dev_create((struct os_dev *)&hal_uart1, "uart1", OS_DEV_INIT_PRIMARY,
180+
0, uart_hal_init, (void *)&uart1_cfg);
162181
SYSINIT_PANIC_ASSERT(rc == 0);
163182
#endif
164183

hw/bsp/arduino_zero/syscfg.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ syscfg.defs:
2525
UART_0:
2626
description: 'Whether to enable UART0'
2727
value: 1
28+
UART_1:
29+
description: 'Whether to enable UART1'
30+
value: 0
2831

2932
TIMER_0:
3033
description: 'Arduino zero Timer 0.'

0 commit comments

Comments
 (0)