From 2a68f70094326ba8bd05d0361171df565f08225a Mon Sep 17 00:00:00 2001 From: yangpengya <53293497+yangpengya@users.noreply.github.com> Date: Tue, 16 Jan 2024 01:00:09 +0800 Subject: [PATCH] =?UTF-8?q?[bsp][hc32]=E6=9B=B4=E6=AD=A3pin=E5=92=8Cusart?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E9=A1=BA=E5=BA=8F(bug=20fix)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #8480 #8458 --- bsp/hc32/libraries/hc32_drivers/drv_common.c | 36 +++++++++++++++++-- bsp/hc32/libraries/hc32_drivers/drv_gpio.c | 1 - bsp/hc32/libraries/hc32_drivers/drv_gpio.h | 2 ++ bsp/hc32/libraries/hc32_drivers/drv_usart.c | 4 +-- bsp/hc32/libraries/hc32_drivers/drv_usart.h | 1 + .../libraries/hc32_drivers/drv_usart_v2.c | 4 +-- .../libraries/hc32_drivers/drv_usart_v2.h | 1 + 7 files changed, 39 insertions(+), 10 deletions(-) diff --git a/bsp/hc32/libraries/hc32_drivers/drv_common.c b/bsp/hc32/libraries/hc32_drivers/drv_common.c index 0ab1a6979a..c9c833aaeb 100644 --- a/bsp/hc32/libraries/hc32_drivers/drv_common.c +++ b/bsp/hc32/libraries/hc32_drivers/drv_common.c @@ -13,6 +13,28 @@ #define DBG_TAG "drv_common" #define DBG_LVL DBG_INFO #include + +#ifdef RT_USING_PIN +#include +#endif + +#ifdef RT_USING_SERIAL +#ifdef RT_USING_SERIAL_V2 +#include +#else +#include +#endif /* RT_USING_SERIAL */ +#endif /* RT_USING_SERIAL_V2 */ + +#ifdef RT_USING_FINSH +#include +static void reboot(uint8_t argc, char **argv) +{ + rt_hw_cpu_reset(); +} +MSH_CMD_EXPORT(reboot, Reboot System); +#endif /* RT_USING_FINSH */ + /** * This function is executed in case of error occurrence. */ @@ -71,14 +93,22 @@ void rt_hw_board_init() rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END); #endif - /* Board underlying hardware initialization */ -#ifdef RT_USING_COMPONENTS_INIT - rt_components_board_init(); +#ifdef RT_USING_PIN + rt_hw_pin_init(); +#endif + +#ifdef RT_USING_SERIAL + rt_hw_usart_init(); #endif #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE) rt_console_set_device(RT_CONSOLE_DEVICE_NAME); #endif + + /* Board underlying hardware initialization */ +#ifdef RT_USING_COMPONENTS_INIT + rt_components_board_init(); +#endif } void rt_hw_us_delay(rt_uint32_t us) diff --git a/bsp/hc32/libraries/hc32_drivers/drv_gpio.c b/bsp/hc32/libraries/hc32_drivers/drv_gpio.c index 1ad85dce2d..526bd0a426 100644 --- a/bsp/hc32/libraries/hc32_drivers/drv_gpio.c +++ b/bsp/hc32/libraries/hc32_drivers/drv_gpio.c @@ -504,7 +504,6 @@ int rt_hw_pin_init(void) return rt_device_pin_register("pin", &hc32_pin_ops, RT_NULL); } -INIT_BOARD_EXPORT(rt_hw_pin_init); #endif diff --git a/bsp/hc32/libraries/hc32_drivers/drv_gpio.h b/bsp/hc32/libraries/hc32_drivers/drv_gpio.h index 7ea9a83212..bdfe69a524 100644 --- a/bsp/hc32/libraries/hc32_drivers/drv_gpio.h +++ b/bsp/hc32/libraries/hc32_drivers/drv_gpio.h @@ -26,6 +26,8 @@ struct hc32_pin_irq_map struct hc32_irq_config irq_config; }; +int rt_hw_pin_init(void); + #endif #endif /* __DRV_GPIO_H__ */ diff --git a/bsp/hc32/libraries/hc32_drivers/drv_usart.c b/bsp/hc32/libraries/hc32_drivers/drv_usart.c index 82776e37d7..a5ce518f35 100644 --- a/bsp/hc32/libraries/hc32_drivers/drv_usart.c +++ b/bsp/hc32/libraries/hc32_drivers/drv_usart.c @@ -1490,7 +1490,7 @@ static const struct rt_uart_ops hc32_uart_ops = .dma_transmit = hc32_dma_transmit }; -int hc32_hw_uart_init(void) +int rt_hw_usart_init(void) { rt_err_t result = RT_EOK; rt_size_t obj_num = sizeof(uart_obj) / sizeof(struct hc32_uart); @@ -1537,8 +1537,6 @@ int hc32_hw_uart_init(void) return result; } -INIT_BOARD_EXPORT(hc32_hw_uart_init); - #endif #endif /* RT_USING_SERIAL */ diff --git a/bsp/hc32/libraries/hc32_drivers/drv_usart.h b/bsp/hc32/libraries/hc32_drivers/drv_usart.h index 7a1fef13e2..2c81ac8bc2 100644 --- a/bsp/hc32/libraries/hc32_drivers/drv_usart.h +++ b/bsp/hc32/libraries/hc32_drivers/drv_usart.h @@ -90,6 +90,7 @@ struct hc32_uart /******************************************************************************* * Global function prototypes (definition in C source) ******************************************************************************/ +int rt_hw_usart_init(void); #ifdef __cplusplus } diff --git a/bsp/hc32/libraries/hc32_drivers/drv_usart_v2.c b/bsp/hc32/libraries/hc32_drivers/drv_usart_v2.c index ac91d88374..866c951153 100644 --- a/bsp/hc32/libraries/hc32_drivers/drv_usart_v2.c +++ b/bsp/hc32/libraries/hc32_drivers/drv_usart_v2.c @@ -1630,7 +1630,7 @@ static const struct rt_uart_ops hc32_uart_ops = .transmit = hc32_transmit }; -int hc32_hw_uart_init(void) +int rt_hw_usart_init(void) { rt_err_t result = RT_EOK; rt_size_t obj_num = sizeof(uart_obj) / sizeof(struct hc32_uart); @@ -1674,8 +1674,6 @@ int hc32_hw_uart_init(void) return result; } -INIT_BOARD_EXPORT(hc32_hw_uart_init); - #endif #endif /* RT_USING_SERIAL_V2 */ diff --git a/bsp/hc32/libraries/hc32_drivers/drv_usart_v2.h b/bsp/hc32/libraries/hc32_drivers/drv_usart_v2.h index c6051e56aa..fa4cd93b36 100644 --- a/bsp/hc32/libraries/hc32_drivers/drv_usart_v2.h +++ b/bsp/hc32/libraries/hc32_drivers/drv_usart_v2.h @@ -90,6 +90,7 @@ struct hc32_uart /******************************************************************************* * Global function prototypes (definition in C source) ******************************************************************************/ +int rt_hw_usart_init(void); #ifdef __cplusplus }