summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hw/bsp/ch58x/debug_uart.c10
-rw-r--r--hw/bsp/ch58x/family.c16
-rw-r--r--hw/bsp/ch58x/family.mk4
-rw-r--r--hw/bsp/ch58x/wch-riscv.cfg2
-rw-r--r--test/hil/tinyusb.json2
5 files changed, 25 insertions, 9 deletions
diff --git a/hw/bsp/ch58x/debug_uart.c b/hw/bsp/ch58x/debug_uart.c
index 7dd133cb2..850e40718 100644
--- a/hw/bsp/ch58x/debug_uart.c
+++ b/hw/bsp/ch58x/debug_uart.c
@@ -41,8 +41,14 @@ static volatile uint32_t tx_consume;
void uart_write(char c) {
uint32_t tx_produce_next = (tx_produce + 1) & UART_RINGBUFFER_MASK_TX;
- // If ring buffer is full, wait
- while (tx_produce_next == tx_consume) {}
+ // If the ring buffer is full, drain it here as the FIFO frees up: nothing else advances
+ // tx_consume between uart_write() calls, so a plain spin would deadlock on a >buffer-size burst.
+ while (tx_produce_next == tx_consume) {
+ if (R8_UART1_LSR & RB_LSR_TX_FIFO_EMP) {
+ R8_UART1_THR = tx_buf[tx_consume];
+ tx_consume = (tx_consume + 1) & UART_RINGBUFFER_MASK_TX;
+ }
+ }
// If UART TX FIFO is empty and no pending data, send directly
if ((tx_consume == tx_produce) && (R8_UART1_LSR & RB_LSR_TX_FIFO_EMP)) {
diff --git a/hw/bsp/ch58x/family.c b/hw/bsp/ch58x/family.c
index 8e5f2826b..64ae4a903 100644
--- a/hw/bsp/ch58x/family.c
+++ b/hw/bsp/ch58x/family.c
@@ -163,9 +163,19 @@ uint32_t board_button_read(void) {
#endif
}
-// Note: CH58x exposes no memory-mapped unique-ID register (unlike ch32v10x/v20x at
-// 0x1FFFF7E8), and the SDK's GET_UNIQUE_ID() is a BootROM stub not present in
-// libISP583.a. So board_get_unique_id() falls back to the fixed default in board.c.
+// CH58x has no memory-mapped unique-ID register (unlike ch32v10x/v20x at 0x1FFFF7E8), but the
+// factory programs a unique 6-byte MAC address into FlashROM (it is a BLE part). GetMACAddress()
+// reads it via the ISP ROM command FLASH_EEPROM_CMD, which is provided by libISP583.a.
+size_t board_get_unique_id(uint8_t id[], size_t max_len) {
+ // FLASH_EEPROM_CMD writes word-granular and requires a 4-byte-aligned buffer (CH58x_flash.c);
+ // size 8 matches the SDK's GET_UNIQUE_ID buffer (6 MAC bytes + 2 it pads), so the read can't
+ // run past the end whether it returns 6 or a full 8.
+ TU_ATTR_ALIGNED(4) uint8_t mac[8];
+ GetMACAddress(mac);
+ size_t len = TU_MIN(max_len, (size_t) 6); // the 6-byte MAC is the unique part
+ memcpy(id, mac, len);
+ return len;
+}
int board_uart_read(uint8_t* buf, int len) {
(void) buf;
diff --git a/hw/bsp/ch58x/family.mk b/hw/bsp/ch58x/family.mk
index ccdaa7268..ac0443659 100644
--- a/hw/bsp/ch58x/family.mk
+++ b/hw/bsp/ch58x/family.mk
@@ -28,7 +28,7 @@ CFLAGS += \
LDFLAGS += \
-nostartfiles \
- --specs=nosys.specs --specs=nano.specs \
+ --specs=nosys.specs --specs=nano.specs
LIBS += $(TOP)/$(SDK_SRC_DIR)/StdPeriphDriver/libISP583.a
@@ -40,7 +40,7 @@ SRC_C += \
$(SDK_SRC_DIR)/StdPeriphDriver/CH58x_sys.c \
$(FAMILY_PATH)/debug_uart.c \
$(FAMILY_PATH)/ch58x_it.c \
- $(FAMILY_PATH)/system_ch58x.c \
+ $(FAMILY_PATH)/system_ch58x.c
SRC_S += \
$(SDK_SRC_DIR)/Startup/startup_CH583.S
diff --git a/hw/bsp/ch58x/wch-riscv.cfg b/hw/bsp/ch58x/wch-riscv.cfg
index 5913a2465..64d595d8e 100644
--- a/hw/bsp/ch58x/wch-riscv.cfg
+++ b/hw/bsp/ch58x/wch-riscv.cfg
@@ -9,7 +9,7 @@ sdi newtap $_CHIPNAME cpu -irlen 5 -expected-id 0x00001
set _TARGETNAME $_CHIPNAME.cpu
target create $_TARGETNAME.0 wch_riscv -chain-position $_TARGETNAME
-$_TARGETNAME.0 configure -work-area-phys 0x80000000 -work-area-size 10000 -work-area-backup 1
+$_TARGETNAME.0 configure -work-area-phys 0x20000000 -work-area-size 0x8000 -work-area-backup 1
set _FLASHNAME $_CHIPNAME.flash
flash bank $_FLASHNAME wch_riscv 0x00000000 0 0 0 $_TARGETNAME.0
diff --git a/test/hil/tinyusb.json b/test/hil/tinyusb.json
index ccf81c582..71d92aae1 100644
--- a/test/hil/tinyusb.json
+++ b/test/hil/tinyusb.json
@@ -496,7 +496,7 @@
},
{
"name": "ch582m_evt",
- "uid": "0123456789ABCDEF",
+ "uid": "D443627B5450",
"toolchain": "riscv-gcc",
"tests": {
"device": true,