From f6985d97c5853db1066044239e551dc2a36b6a9d Mon Sep 17 00:00:00 2001 From: wmano Date: Tue, 2 Sep 2025 22:09:40 +0800 Subject: [PATCH] debug uart --- apps/boot/bsp/bsp_uart_config.h | 2 +- apps/boot/func/app.c | 2 +- apps/boot/include/main.h | 4 +- apps/boot/main.c | 4 +- apps/chrg/.config | 4 +- apps/chrg/applications/bsp/chrg_pin.h | 2 +- apps/chrg/applications/utils/chrg_source.c | 60 +++++++++++++++++++ apps/chrg/project.uvprojx | 69 +++++++++++----------- apps/chrg/rtconfig.h | 3 +- 9 files changed, 105 insertions(+), 45 deletions(-) diff --git a/apps/boot/bsp/bsp_uart_config.h b/apps/boot/bsp/bsp_uart_config.h index 1c42ea3..9191dc5 100644 --- a/apps/boot/bsp/bsp_uart_config.h +++ b/apps/boot/bsp/bsp_uart_config.h @@ -4,7 +4,7 @@ #include "app_config.h" #define BSP_PRINTF_BUFF_SIZE 256 -#define BSP_PRINTF_HANDLE UART(1) +#define BSP_PRINTF_HANDLE UART(2) #define BSP_UART_BUFF_SIZE 64 diff --git a/apps/boot/func/app.c b/apps/boot/func/app.c index f68b766..e7eceeb 100644 --- a/apps/boot/func/app.c +++ b/apps/boot/func/app.c @@ -681,7 +681,7 @@ void APP_Init (void) TIMER_RUN_FOREVER); drv_timer_start(&timerWait); - DT_Init(&fdUart, BSP_UART2, gRecv.bufRx, &gRecv.lenRx, YM_MSG_SIZE_MAX + 16); + DT_Init(&fdUart, BSP_UART1, gRecv.bufRx, &gRecv.lenRx, YM_MSG_SIZE_MAX + 16); ymodem_init(sendDataHandler, boot_ProtocolDataHandle, boot_SetReplyInfo); diff --git a/apps/boot/include/main.h b/apps/boot/include/main.h index 3fc0a18..7f8e858 100644 --- a/apps/boot/include/main.h +++ b/apps/boot/include/main.h @@ -13,8 +13,8 @@ extern "C" { #define KEY0_Pin GPIO_PIN_8 #define KEY0_GPIO_Port GPIOC - #define LED0_Pin GPIO_PIN_8 - #define LED0_GPIO_Port GPIOA + #define LED0_Pin GPIO_PIN_13 + #define LED0_GPIO_Port GPIOC #elif defined(STM32F411xE)||defined(STM32F401xC) #define KEY0_Pin GPIO_PIN_0 #define KEY0_GPIO_Port GPIOA diff --git a/apps/boot/main.c b/apps/boot/main.c index e2cecc7..d5c26ba 100644 --- a/apps/boot/main.c +++ b/apps/boot/main.c @@ -188,14 +188,14 @@ int main (void) int fputc(int ch, FILE *f) { - HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xffff); + HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, 0xffff); return ch; } int fgetc(FILE * f) { uint8_t ch = 0; - HAL_UART_Receive(&huart1,&ch, 1, 0xffff); + HAL_UART_Receive(&huart2,&ch, 1, 0xffff); return ch; } diff --git a/apps/chrg/.config b/apps/chrg/.config index 81cbe70..150adcb 100644 --- a/apps/chrg/.config +++ b/apps/chrg/.config @@ -180,7 +180,7 @@ CONFIG_RT_USING_DEVICE=y # CONFIG_RT_USING_THREADSAFE_PRINTF is not set CONFIG_RT_USING_CONSOLE=y CONFIG_RT_CONSOLEBUF_SIZE=128 -CONFIG_RT_CONSOLE_DEVICE_NAME="uart1" +CONFIG_RT_CONSOLE_DEVICE_NAME="uart2" CONFIG_RT_VER_NUM=0x50201 # CONFIG_RT_USING_STDC_ATOMIC is not set CONFIG_RT_BACKTRACE_LEVEL_MAX_NR=32 @@ -419,7 +419,7 @@ CONFIG_PKG_MODBUS_MASTER_SAMPLE=y CONFIG_MB_SAMPLE_TEST_SLAVE_ADDR=1 CONFIG_MB_MASTER_USING_PORT_NUM=1 CONFIG_MB_MASTER_USING_PORT_BAUDRATE=115200 -CONFIG_PKG_MODBUS_SLAVE=y +# CONFIG_PKG_MODBUS_SLAVE is not set # # advanced configuration diff --git a/apps/chrg/applications/bsp/chrg_pin.h b/apps/chrg/applications/bsp/chrg_pin.h index 387a5e5..bcde43b 100644 --- a/apps/chrg/applications/bsp/chrg_pin.h +++ b/apps/chrg/applications/bsp/chrg_pin.h @@ -14,7 +14,7 @@ #define TMR_NAME_LED2 "tmr_led2" #define TMR_NAME_LED3 "tmr_led3" -#define PIN_LED1 GET_PIN(A, 8) //GET_PIN(C, 13) +#define PIN_LED1 GET_PIN(C, 13) #define PIN_LED2 GET_PIN(C, 14) #define PIN_LED3 GET_PIN(C, 15) diff --git a/apps/chrg/applications/utils/chrg_source.c b/apps/chrg/applications/utils/chrg_source.c index f4dcc60..107497f 100644 --- a/apps/chrg/applications/utils/chrg_source.c +++ b/apps/chrg/applications/utils/chrg_source.c @@ -28,5 +28,65 @@ void source_get_vc (rt_uint16_t vol, rt_uint16_t cur) chrg_north_send(data, len); } +void source_get_pd (void) +{ + rt_size_t len = 0; + rt_uint8_t data[8] = {0}; + + data[0] = 0x05; + data[1] = 0x00; + data[2] = ID_SOURCE; + data[3] = SRC_CMD_GET_PROTOCOL; + data[4] = calc_crc8(data, 4); + + len = 0x05; + + chrg_north_send(data, len); +} + +void source_set_cc_lvl (rt_uint8_t lvl) +{ + rt_size_t len = 0; + rt_uint8_t data[8] = {0}; + + data[0] = 0x06; + data[1] = 0x00; + data[2] = ID_SOURCE; + data[3] = SRC_CMD_SET_CC_LEVEL; + data[4] = lvl; + data[5] = calc_crc8(data, 5); + + len = 0x06; + + chrg_north_send(data, len); +} + +void source_set_pd (rt_uint8_t pro, rt_uint8_t src, rt_uint8_t pps, + rt_uint16_t vmax, rt_uint16_t vmin, rt_int16_t max_cur) +{ + rt_size_t len = 0; + rt_uint8_t data[12] = {0}; + + data[0] = 0x0B; + data[1] = 0x00; + data[2] = ID_SOURCE; + data[3] = SRC_CMD_SET_PROTOCOL; + data[4] = pro; + data[5] = src; + data[6] = pps; + + u16_to_u8v(vmax, &data[7]); + u16_to_u8v(vmin, &data[9]); + u16_to_u8v(max_cur, &data[11]); + + data[13] = calc_crc8(data, 13); + + len = 0x0E; + + chrg_north_send(data, len); +} + + + diff --git a/apps/chrg/project.uvprojx b/apps/chrg/project.uvprojx index 1e9090c..2702925 100644 --- a/apps/chrg/project.uvprojx +++ b/apps/chrg/project.uvprojx @@ -10,6 +10,7 @@ chrg 0x4 ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC 0 @@ -597,7 +598,7 @@ __RT_IPC_SOURCE__ - + @@ -653,7 +654,7 @@ __RT_IPC_SOURCE__ - + @@ -709,7 +710,7 @@ __RT_IPC_SOURCE__ - + @@ -765,7 +766,7 @@ __RT_IPC_SOURCE__ - + @@ -821,7 +822,7 @@ __RT_IPC_SOURCE__ - + @@ -877,7 +878,7 @@ __RT_IPC_SOURCE__ - + @@ -933,7 +934,7 @@ __RT_IPC_SOURCE__ - + @@ -989,7 +990,7 @@ __RT_IPC_SOURCE__ - + @@ -1045,7 +1046,7 @@ __RT_IPC_SOURCE__ - + @@ -1101,7 +1102,7 @@ __RT_IPC_SOURCE__ - + @@ -1157,7 +1158,7 @@ __RT_IPC_SOURCE__ - + @@ -1213,7 +1214,7 @@ __RT_IPC_SOURCE__ - + @@ -1269,7 +1270,7 @@ __RT_IPC_SOURCE__ - + @@ -1325,7 +1326,7 @@ __RT_IPC_SOURCE__ - + @@ -1381,7 +1382,7 @@ __RT_IPC_SOURCE__ - + @@ -1437,7 +1438,7 @@ __RT_IPC_SOURCE__ - + @@ -1493,7 +1494,7 @@ __RT_IPC_SOURCE__ - + @@ -1549,7 +1550,7 @@ __RT_IPC_SOURCE__ - + @@ -1605,7 +1606,7 @@ __RT_IPC_SOURCE__ - + @@ -1921,7 +1922,7 @@ __RT_KERNEL_SOURCE__ - + @@ -1977,7 +1978,7 @@ __RT_KERNEL_SOURCE__ - + @@ -2033,7 +2034,7 @@ __RT_KERNEL_SOURCE__ - + @@ -2089,7 +2090,7 @@ __RT_KERNEL_SOURCE__ - + @@ -2145,7 +2146,7 @@ __RT_KERNEL_SOURCE__ - + @@ -2201,7 +2202,7 @@ __RT_KERNEL_SOURCE__ - + @@ -2257,7 +2258,7 @@ __RT_KERNEL_SOURCE__ - + @@ -2313,7 +2314,7 @@ __RT_KERNEL_SOURCE__ - + @@ -2369,7 +2370,7 @@ __RT_KERNEL_SOURCE__ - + @@ -2425,7 +2426,7 @@ __RT_KERNEL_SOURCE__ - + @@ -2481,7 +2482,7 @@ __RT_KERNEL_SOURCE__ - + @@ -2537,7 +2538,7 @@ __RT_KERNEL_SOURCE__ - + @@ -2593,7 +2594,7 @@ __RT_KERNEL_SOURCE__ - + @@ -2649,7 +2650,7 @@ __RT_KERNEL_SOURCE__ - + @@ -2705,7 +2706,7 @@ __RT_KERNEL_SOURCE__ - + diff --git a/apps/chrg/rtconfig.h b/apps/chrg/rtconfig.h index cd8e06f..cc1342b 100644 --- a/apps/chrg/rtconfig.h +++ b/apps/chrg/rtconfig.h @@ -103,7 +103,7 @@ #define RT_USING_DEVICE #define RT_USING_CONSOLE #define RT_CONSOLEBUF_SIZE 128 -#define RT_CONSOLE_DEVICE_NAME "uart1" +#define RT_CONSOLE_DEVICE_NAME "uart2" #define RT_VER_NUM 0x50201 #define RT_BACKTRACE_LEVEL_MAX_NR 32 /* end of RT-Thread Kernel */ @@ -232,7 +232,6 @@ #define MB_SAMPLE_TEST_SLAVE_ADDR 1 #define MB_MASTER_USING_PORT_NUM 1 #define MB_MASTER_USING_PORT_BAUDRATE 115200 -#define PKG_MODBUS_SLAVE /* advanced configuration */