Skip to content

Commit 237f120

Browse files
author
Yuriy Vynnychek
committed
B91 BLE, DFU and west debug support
1 parent d0233a8 commit 237f120

File tree

14 files changed

+208
-57
lines changed

14 files changed

+208
-57
lines changed

boards/common/spi_burn.board.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# SPDX-License-Identifier: Apache-2.0
22

33
board_set_flasher_ifnset(spi_burn)
4+
board_set_debugger_ifnset(spi_burn)
45
board_finalize_runner_args(spi_burn)

boards/riscv/tlsr9518adk80d/Kconfig.defconfig

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ config I2C_TELINK_B91
3636
config ADC_TELINK_B91
3737
default y if ADC
3838

39+
# Workaround for not being able to have commas in macro arguments
40+
DT_CHOSEN_Z_CODE_PARTITION := zephyr,code-partition
41+
42+
config FLASH_LOAD_OFFSET
43+
default $(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_CODE_PARTITION)) if USE_DT_CODE_PARTITION
44+
3945
if BT
4046

4147
# BLE Controller SDK from hal_telink requires
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# SPDX-License-Identifier: Apache-2.0
22

3-
board_runner_args(spi_burn --addr 0x0)
3+
board_runner_args(spi_burn)
44
include(${ZEPHYR_BASE}/boards/common/spi_burn.board.cmake)

boards/riscv/tlsr9518adk80d/doc/index.rst

+15-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,21 @@ It is also possible to use the west flash command, but additional steps are requ
279279
Debugging
280280
=========
281281

282-
Supporting UART debug and OpenOCD+GDB.
282+
Supporting UART debug and OpenOCD+GDB. west debug command also supported. You may run it in a simle way, like:
283+
284+
.. code-block:: console
285+
286+
west debug
287+
288+
Or with additional arguments, like:
289+
290+
.. code-block:: console
291+
292+
west debug --gdb-port=<port_number> --gdb-ex=<additional_ex_arguments>
293+
294+
Example:
295+
west debug --gdb-port=1111 --gdb-ex="-ex monitor reset halt -ex b main -ex continue"
296+
283297

284298
References
285299
**********

boards/riscv/tlsr9518adk80d/tlsr9518adk80d.dts

+33-32
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
aliases {
1717
led0 = &led_blue;
1818
led1 = &led_green;
19+
led2 = &led_white;
20+
led3 = &led_red;
1921
sw0 = &key_1;
2022
pwm-led0 = &pwm_led_blue;
2123
pwm-0 = &pwm0;
@@ -69,6 +71,7 @@
6971
zephyr,flash = &flash;
7072
zephyr,flash-controller = &flash_mspi;
7173
zephyr,entropy = &trng0;
74+
zephyr,code-partition = &slot0_partition;
7275
};
7376
};
7477

@@ -86,6 +89,36 @@
8689

8790
&flash {
8891
reg = <0x20000000 0x100000>;
92+
93+
partitions {
94+
compatible = "fixed-partitions";
95+
#address-cells = <1>;
96+
#size-cells = <1>;
97+
98+
boot_partition: partition@0 {
99+
label = "mcuboot";
100+
reg = <0x00000000 0x10000>;
101+
};
102+
slot0_partition: partition@10000 {
103+
label = "image-0";
104+
reg = <0x10000 0x70000>;
105+
};
106+
slot1_partition: partition@80000 {
107+
label = "image-1";
108+
reg = <0x80000 0x70000>;
109+
};
110+
scratch_partition: partition@f0000 {
111+
label = "image-scratch";
112+
reg = <0xf0000 0x4000>;
113+
};
114+
storage_partition: partition@f4000 {
115+
label = "storage";
116+
reg = <0xf4000 0x0000b000>;
117+
/* region <0xff000 0x1000> is reserved for
118+
* Telink B91 SDK's data (BLE MAC address etc.)
119+
*/
120+
};
121+
};
89122
};
90123

91124
&gpiob {
@@ -144,35 +177,3 @@
144177
status = "okay";
145178
vref = "ADC_VREF_1P2V";
146179
};
147-
148-
&flash_mspi {
149-
partitions {
150-
compatible = "fixed-partitions";
151-
#address-cells = <1>;
152-
#size-cells = <1>;
153-
154-
boot_partition: partition@0 {
155-
label = "mcuboot";
156-
reg = <0x00000000 0x8000>;
157-
};
158-
slot0_partition: partition@8000 {
159-
label = "image-0";
160-
reg = <0x00008000 0x1a000>;
161-
};
162-
slot1_partition: partition@22000 {
163-
label = "image-1";
164-
reg = <0x00022000 0x1a000>;
165-
};
166-
scratch_partition: partition@3c000 {
167-
label = "image-scratch";
168-
reg = <0x0003c000 0x2000>;
169-
};
170-
storage_partition: partition@f0000 {
171-
label = "storage";
172-
reg = <0x000f0000 0x00008000>;
173-
/* region 0x000f8000 .. 0x000FFFFF
174-
* is reserved for factory calibration
175-
*/
176-
};
177-
};
178-
};

drivers/serial/uart_b91.c

+10
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
#define UART_STOP_BIT_1P5 BIT(4)
3636
#define UART_STOP_BIT_2 BIT(5)
3737

38+
/* TX RX reset bits */
39+
#define UART_RX_RESET_BIT BIT(6)
40+
#define UART_TX_RESET_BIT BIT(7)
41+
3842

3943
/* B91 UART registers structure */
4044
struct uart_b91_t {
@@ -304,6 +308,12 @@ static int uart_b91_driver_init(const struct device *dev)
304308
uint8_t bwpc = 0u;
305309
volatile struct uart_b91_t *uart = GET_UART(dev);
306310
const struct uart_b91_config *cfg = dev->config;
311+
struct uart_b91_data *data = dev->data;
312+
313+
/* Reset Tx, Rx status before usage */
314+
uart->status |= UART_RX_RESET_BIT | UART_TX_RESET_BIT;
315+
data->rx_byte_index = 0;
316+
data->tx_byte_index = 0;
307317

308318
/* configure pins */
309319
status = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CONFIG_LOG_BACKEND_UART=y
2+
CONFIG_IMG_BLOCK_BUF_SIZE=256
3+
CONFIG_GPIO=y
4+
CONFIG_ASSERT=y
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2022 Telink Semiconductor
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
chosen {
9+
zephyr,uart-mcumgr = &uart0;
10+
zephyr,shell-uart = &uart0;
11+
zephyr,console = &uart1;
12+
};
13+
};
14+
15+
&uart0 {
16+
status = "okay";
17+
current-speed = <115200>;
18+
pinctrl-0 = <&uart0_tx_pb2_default &uart0_rx_pb3_default>;
19+
pinctrl-names = "default";
20+
};
21+
22+
&uart1 {
23+
status = "okay";
24+
current-speed = <115200>;
25+
pinctrl-0 = <&uart1_tx_pc6_default &uart1_rx_pc7_default>;
26+
pinctrl-names = "default";
27+
};

samples/subsys/mgmt/mcumgr/smp_svr/src/main.c

+20
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@
88
#include <zephyr/zephyr.h>
99
#include <zephyr/stats/stats.h>
1010
#include <zephyr/usb/usb_device.h>
11+
#include <drivers/gpio.h>
12+
13+
/* The devicetree node identifier for the "led0" alias. */
14+
#define LED_NODE DT_ALIAS(led0)
15+
16+
/*
17+
* A build error on this line means your board is unsupported.
18+
* See the sample documentation for information on how to fix this.
19+
*/
20+
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED_NODE, gpios);
1121

1222
#ifdef CONFIG_MCUMGR_CMD_FS_MGMT
1323
#include <zephyr/device.h>
@@ -60,6 +70,12 @@ static struct fs_mount_t littlefs_mnt = {
6070
};
6171
#endif
6272

73+
static void gpio_init(void)
74+
{
75+
__ASSERT(device_is_ready(led.port), "Device is not ready");
76+
__ASSERT(gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE) == 0, "Fail to config gpio");
77+
}
78+
6379
void main(void)
6480
{
6581
int rc = STATS_INIT_AND_REG(smp_svr_stats, STATS_SIZE_32,
@@ -109,10 +125,14 @@ void main(void)
109125
*/
110126
LOG_INF("build time: " __DATE__ " " __TIME__);
111127

128+
/* Enable LED */
129+
gpio_init();
130+
112131
/* The system work queue handles all incoming mcumgr requests. Let the
113132
* main thread idle while the mcumgr server runs.
114133
*/
115134
while (1) {
135+
__ASSERT(gpio_pin_toggle_dt(&led) == 0, "Fail to toggle LED");
116136
k_sleep(K_MSEC(1000));
117137
STATS_INC(smp_svr_stats, ticks);
118138
}

0 commit comments

Comments
 (0)