Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci_set_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"ch32v10x": ["riscv-gcc"],
"ch32v20x": ["riscv-gcc"],
"ch32v30x": ["riscv-gcc"],
"ch58x": ["riscv-gcc"],
"da1469x": ["arm-gcc"],
"fomu": ["riscv-gcc"],
"ft9xx": ["ft9xx-gcc"],
Expand Down
1 change: 1 addition & 0 deletions docs/reference/boards.rst
Original file line number Diff line number Diff line change
Expand Up @@ -368,4 +368,5 @@ ch32v203g_r0_1v0 CH32V203G-R0-1v0 ch32v20x https://github.com/openwch/ch32v20
nanoch32v203 nanoCH32V203 ch32v20x https://github.com/wuxx/nanoCH32V203
ch32v307v_r1_1v0 CH32V307V-R1-1v0 ch32v30x https://github.com/openwch/ch32v307/tree/main/SCHPCB/CH32V307V-R1-1v0
nanoch32v305 nanoCH32V305 ch32v30x https://github.com/wuxx/nanoCH32V305
yd-ch582m yd-ch582m ch58x http://vcc-gnd.com
================ ================ ======== ===================================================================== ======
1 change: 1 addition & 0 deletions examples/device/audio_4_channel_mic_freertos/skip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mcu:CH32F20X
mcu:CH32V103
mcu:CH32V20X
mcu:CH32V307
mcu:CH58X
mcu:CXD56
mcu:F1C100S
mcu:GD32VF103
Expand Down
1 change: 1 addition & 0 deletions examples/device/audio_test_freertos/skip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mcu:CH32F20X
mcu:CH32V103
mcu:CH32V20X
mcu:CH32V307
mcu:CH58X
mcu:CXD56
mcu:F1C100S
mcu:GD32VF103
Expand Down
1 change: 1 addition & 0 deletions examples/device/cdc_msc_freertos/skip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mcu:CH32F20X
mcu:CH32V103
mcu:CH32V20X
mcu:CH32V307
mcu:CH58X
mcu:CXD56
mcu:F1C100S
mcu:GD32VF103
Expand Down
1 change: 1 addition & 0 deletions examples/device/hid_composite_freertos/skip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mcu:CH32F20X
mcu:CH32V103
mcu:CH32V20X
mcu:CH32V307
mcu:CH58X
mcu:CXD56
mcu:F1C100S
mcu:GD32VF103
Expand Down
1 change: 1 addition & 0 deletions examples/device/midi_test_freertos/skip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mcu:CH32F20X
mcu:CH32V103
mcu:CH32V20X
mcu:CH32V307
mcu:CH58X
mcu:CXD56
mcu:F1C100S
mcu:GD32VF103
Expand Down
1 change: 1 addition & 0 deletions examples/device/video_capture/skip.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mcu:CH32V103
mcu:CH32V20X
mcu:CH58X
mcu:MSP430x5xx
mcu:NUC121
mcu:SAMD11
1 change: 1 addition & 0 deletions examples/device/video_capture_2ch/skip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mcu:GD32VF103
mcu:CH32V103
mcu:CH32V20X
mcu:CH32V307
mcu:CH58X
mcu:STM32L0
family:espressif
board:curiosity_nano
Expand Down
5 changes: 5 additions & 0 deletions hw/bsp/ch58x/boards/yd-ch582m/board.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set(LD_FLASH_SIZE 448K)
set(LD_RAM_SIZE 32K)

function(update_board TARGET)
endfunction()
61 changes: 61 additions & 0 deletions hw/bsp/ch58x/boards/yd-ch582m/board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2024 TinyUSB contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

/* metadata:
name: yd-ch582m from vcc-gnd studio
url: http://vcc-gnd.com/
*/

#ifndef BOARD_H_
#define BOARD_H_

#ifdef __cplusplus
extern "C" {
#endif

// LED: PB4 on yd-ch582m board
#define LED_PIN GPIO_Pin_4
#define LED_STATE_ON 0

// Directly reuse BOOT pin as user button
#define BUTTON_PIN GPIO_Pin_22
#define BUTTON_STATE_ACTIVE 0

// UART: UART1 TX=PA9, RX=PA8
#define CFG_BOARD_UART_BAUDRATE 115200

// Dual-port: USB1 (rhport 0) = Device, USB2 (rhport 1) = Host
// Swap these two if you want the opposite assignment
#ifndef BOARD_TUD_RHPORT
#define BOARD_TUD_RHPORT 0
#endif
#ifndef BOARD_TUH_RHPORT
#define BOARD_TUH_RHPORT 1
#endif

#ifdef __cplusplus
}
#endif

#endif
3 changes: 3 additions & 0 deletions hw/bsp/ch58x/boards/yd-ch582m/board.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
LDFLAGS += \
-Wl,--defsym=__FLASH_SIZE=448K \
-Wl,--defsym=__RAM_SIZE=32K \
37 changes: 37 additions & 0 deletions hw/bsp/ch58x/ch58x_it.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2024 TinyUSB contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* This file is part of the TinyUSB stack.
*/

#include "ch58x_it.h"

// NMI exception handler
__INTERRUPT __HIGH_CODE void NMI_Handler(void) {
while (1) {}
}

// Hard Fault exception handler
__INTERRUPT __HIGH_CODE void HardFault_Handler(void) {
while (1) {}
}
46 changes: 46 additions & 0 deletions hw/bsp/ch58x/ch58x_it.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2024 TinyUSB contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* This file is part of the TinyUSB stack.
*/

#ifndef CH58X_IT_H_
#define CH58X_IT_H_

#ifdef __cplusplus
extern "C" {
#endif

#include "CH58x_common.h"

void NMI_Handler(void);
void HardFault_Handler(void);
void USB_IRQHandler(void);
void USB2_IRQHandler(void);
void SysTick_Handler(void);

#ifdef __cplusplus
}
#endif

#endif /* CH58X_IT_H_ */
80 changes: 80 additions & 0 deletions hw/bsp/ch58x/debug_uart.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2024 TinyUSB contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* This file is part of the TinyUSB stack.
*/

#include "debug_uart.h"
#include "CH58x_common.h"

//--------------------------------------------------------------------+
// Ring buffer based UART TX for non-blocking writes
//--------------------------------------------------------------------+

#define UART_RINGBUFFER_SIZE_TX 128
#define UART_RINGBUFFER_MASK_TX (UART_RINGBUFFER_SIZE_TX - 1)

static char tx_buf[UART_RINGBUFFER_SIZE_TX];
static uint32_t tx_produce;
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 UART TX FIFO is empty and no pending data, send directly
if ((tx_consume == tx_produce) && (R8_UART1_LSR & RB_LSR_TX_FIFO_EMP)) {
R8_UART1_THR = c;
} else {
tx_buf[tx_produce] = c;
tx_produce = tx_produce_next;
}
}

void uart_sync(void) {
// Wait for ring buffer to drain
while (tx_consume != tx_produce) {
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;
}
}
// Wait for last byte to finish transmitting
while (!(R8_UART1_LSR & RB_LSR_TX_ALL_EMP)) {}
}

void usart_printf_init(uint32_t baudrate) {
tx_produce = 0;
tx_consume = 0;

// Configure UART1 pins: TX=PA9, RX=PA8
GPIOA_SetBits(GPIO_Pin_9);
GPIOA_ModeCfg(GPIO_Pin_9, GPIO_ModeOut_PP_5mA);
GPIOA_ModeCfg(GPIO_Pin_8, GPIO_ModeIN_PU);

// Init UART1 with specified baud rate
UART1_DefInit();
UART1_BaudRateCfg(baudrate);
}
44 changes: 44 additions & 0 deletions hw/bsp/ch58x/debug_uart.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2024 TinyUSB contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* This file is part of the TinyUSB stack.
*/

#ifndef DEBUG_UART_H_
#define DEBUG_UART_H_

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

void uart_write(char c);
void uart_sync(void);
void usart_printf_init(uint32_t baudrate);

#ifdef __cplusplus
}
#endif

#endif /* DEBUG_UART_H_ */
Loading
Loading