using usart2

This commit is contained in:
wmano
2025-08-18 21:47:05 +08:00
parent 52a3ed5862
commit 830ba4d3eb
18 changed files with 685 additions and 329 deletions
+5
View File
@@ -73,3 +73,8 @@ __pychache__
_rt_thread
~*
si4
.picasa.ini
DebugConfig
Objects
*.uvguix.*
*.uvoptx
+10
View File
@@ -1497,6 +1497,16 @@ CONFIG_BSP_USING_UART1=y
CONFIG_BSP_USING_UART2=y
# CONFIG_BSP_UART2_RX_USING_DMA is not set
# CONFIG_BSP_UART2_TX_USING_DMA is not set
CONFIG_BSP_USING_UART3=y
# CONFIG_BSP_UART3_RX_USING_DMA is not set
# CONFIG_BSP_UART3_TX_USING_DMA is not set
CONFIG_BSP_USING_UART4=y
# CONFIG_BSP_UART4_RX_USING_DMA is not set
# CONFIG_BSP_UART4_TX_USING_DMA is not set
# CONFIG_BSP_USING_UART5 is not set
CONFIG_BSP_USING_UART6=y
# CONFIG_BSP_UART6_RX_USING_DMA is not set
# CONFIG_BSP_UART6_TX_USING_DMA is not set
# CONFIG_BSP_USING_RNG is not set
# CONFIG_BSP_USING_UDID is not set
# end of On-chip Peripheral Drivers
+49
View File
@@ -0,0 +1,49 @@
#include <rtthread.h>
#include <rtdevice.h>
static rt_device_t serial_usart2;
rt_err_t usart2_rx_irq(rt_device_t dev, rt_size_t size)
{
rt_kprintf("rx_irq\r\n");
return RT_EOK;
}
rt_err_t usart2_open(void)
{
rt_err_t ret;
serial_usart2 = rt_device_find("uart2");
if (RT_NULL == serial_usart2) {
rt_kprintf("can't find usart2.\r\n");
return RT_ERROR;
}
ret = rt_device_open(serial_usart2, RT_DEVICE_OFLAG_RDWR|RT_DEVICE_FLAG_INT_RX);
if (RT_EOK != ret) {
rt_kprintf("open usart2 failed.\r\n");
return RT_ERROR;
}
struct serial_configure uart2_set_parg={ \
BAUD_RATE_115200, /* 115200 bits/s */ \
DATA_BITS_8, /* 8 databits */ \
STOP_BITS_1, /* 1 stopbit */ \
PARITY_NONE, /* No parity */ \
BIT_ORDER_LSB, /* LSB first sent */ \
NRZ_NORMAL, /* Normal mode */ \
RT_SERIAL_RB_BUFSZ, /* Buffer size */ \
0 \
};
rt_device_control(serial_usart2, RT_DEVICE_CTRL_CONFIG, &uart2_set_parg);
rt_device_set_rx_indicate(serial_usart2, usart2_rx_irq);
return RT_EOK;
}
INIT_APP_EXPORT(usart2_open);
@@ -1,81 +1,8 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* File Name : stm32f4xx_hal_msp.c
* Description : This file provides code for the MSP Initialization
* and de-Initialization codes.
******************************************************************************
** This notice applies to any and all portions of this file
* that are not between comment pairs USER CODE BEGIN and
* USER CODE END. Other portions of this file, whether
* inserted by the user or by software development tools
* are owned by their respective copyright owners.
*
* COPYRIGHT(c) 2018 STMicroelectronics
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
#include <drv_common.h>
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN TD */
/* USER CODE END TD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN Define */
/* USER CODE END Define */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN Macro */
/* USER CODE END Macro */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* External functions --------------------------------------------------------*/
/* USER CODE BEGIN ExternalFunctions */
/* USER CODE END ExternalFunctions */
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
@@ -108,9 +35,6 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(huart->Instance==USART1) {
/* USER CODE BEGIN USART1_MspInit 0 */
/* USER CODE END USART1_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_USART1_CLK_ENABLE();
@@ -125,14 +49,7 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* USER CODE BEGIN USART1_MspInit 1 */
/* USER CODE END USART1_MspInit 1 */
} else if(huart->Instance==USART2) {
/* USER CODE BEGIN USART2_MspInit 0 */
/* USER CODE END USART2_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_USART2_CLK_ENABLE();
@@ -147,10 +64,52 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
} else if(huart->Instance==USART3) {
/* Peripheral clock enable */
__HAL_RCC_USART3_CLK_ENABLE();
/* USER CODE BEGIN USART2_MspInit 1 */
__HAL_RCC_GPIOB_CLK_ENABLE();
/**USART3 GPIO Configuration
PB10 ------> USART3_TX
PB11 ------> USART3_RX
*/
GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF7_USART3;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
} else if(huart->Instance==UART4) {
/* Peripheral clock enable */
__HAL_RCC_UART4_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
/**UART2 GPIO Configuration
PC10 ------> UART4_TX
PC11 ------> UART4_RX
*/
GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF8_UART4;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
} else if(huart->Instance==USART6) {
/* Peripheral clock enable */
__HAL_RCC_USART6_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
/**USART6 GPIO Configuration
PC6 ------> USART6_TX
PC7 ------> USART6_RX
*/
GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF8_USART6;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/* USER CODE END USART2_MspInit 1 */
}
}
@@ -166,9 +125,6 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
{
if(huart->Instance==USART1) {
/* USER CODE BEGIN USART1_MspDeInit 0 */
/* USER CODE END USART1_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_USART1_CLK_DISABLE();
@@ -177,14 +133,7 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
PA3 ------> USART1_RX
*/
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10);
/* USER CODE BEGIN USART1_MspDeInit 1 */
/* USER CODE END USART1_MspDeInit 1 */
} else if(huart->Instance==USART2) {
/* USER CODE BEGIN USART2_MspDeInit 0 */
/* USER CODE END USART2_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_USART2_CLK_DISABLE();
@@ -193,10 +142,34 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
PA3 ------> USART2_RX
*/
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3);
} else if(huart->Instance==USART3) {
/* Peripheral clock disable */
__HAL_RCC_USART3_CLK_DISABLE();
/* USER CODE BEGIN USART2_MspDeInit 1 */
/**USART3 GPIO Configuration
PB10 ------> USART3_TX
PB11 ------> USART3_RX
*/
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10|GPIO_PIN_11);
} else if(huart->Instance==UART4) {
/* Peripheral clock disable */
__HAL_RCC_UART4_CLK_DISABLE();
/**UART4 GPIO Configuration
PC10 ------> UART4_TX
PC11 ------> UART4_RX
*/
HAL_GPIO_DeInit(GPIOC, GPIO_PIN_10|GPIO_PIN_11);
} else if(huart->Instance==USART6) {
/* Peripheral clock disable */
__HAL_RCC_USART6_CLK_DISABLE();
/**USART6 GPIO Configuration
PC6 ------> USART6_TX
PC7 ------> USART6_RX
*/
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_6|GPIO_PIN_7);
/* USER CODE END USART2_MspDeInit 1 */
}
}
+139 -2
View File
@@ -52,7 +52,7 @@ menu "On-chip Peripheral Drivers"
config BSP_UART1_DMA_PING_BUFSIZE
int "Set UART1 RX DMA ping-pong buffer size"
range 32 65535
depends on RT_USING_SERIAL_V2 && BSP_UART1_RX_USING_DMA
depends on BSP_UART4_RX_USING_DMA && RT_USING_SERIAL_V2
default 32
config BSP_USING_UART2
@@ -86,8 +86,145 @@ menu "On-chip Peripheral Drivers"
config BSP_UART2_DMA_PING_BUFSIZE
int "Set UART2 RX DMA ping-pong buffer size"
range 32 65535
depends on RT_USING_SERIAL_V2 && BSP_UART2_RX_USING_DMA
depends on BSP_UART4_RX_USING_DMA && RT_USING_SERIAL_V2
default 32
config BSP_USING_UART3
bool "Enable UART3"
default y
config BSP_UART3_RX_USING_DMA
bool "Enable UART3 RX DMA"
depends on BSP_USING_UART3
select RT_SERIAL_USING_DMA
default n
config BSP_UART3_TX_USING_DMA
bool "Enable UART3 TX DMA"
depends on BSP_USING_UART3
select RT_SERIAL_USING_DMA
default n
config BSP_UART3_RX_BUFSIZE
int "Set UART3 RX buffer size"
range 64 65535
depends on BSP_USING_UART3 && RT_USING_SERIAL_V2
default 64
config BSP_UART3_TX_BUFSIZE
int "Set UART3 TX buffer size"
range 0 65535
depends on BSP_USING_UART3 && RT_USING_SERIAL_V2
default 0
config BSP_UART3_DMA_PING_BUFSIZE
int "Set UART3 RX DMA ping-pong buffer size"
range 32 65535
depends on BSP_UART4_RX_USING_DMA && RT_USING_SERIAL_V2
default 32
config BSP_USING_UART4
bool "Enable UART4"
default y
config BSP_UART4_RX_USING_DMA
bool "Enable UART4 RX DMA"
depends on BSP_USING_UART4
select RT_SERIAL_USING_DMA
default n
config BSP_UART4_TX_USING_DMA
bool "Enable UART4 TX DMA"
depends on BSP_USING_UART4
select RT_SERIAL_USING_DMA
default n
config BSP_UART4_RX_BUFSIZE
int "Set UART4 RX buffer size"
range 64 65535
depends on BSP_USING_UART4 && RT_USING_SERIAL_V2
default 64
config BSP_UART4_TX_BUFSIZE
int "Set UART4 TX buffer size"
range 0 65535
depends on BSP_USING_UART4 && RT_USING_SERIAL_V2
default 0
config BSP_UART4_DMA_PING_BUFSIZE
int "Set UART4 RX DMA ping-pong buffer size"
range 32 65535
depends on BSP_UART4_RX_USING_DMA && RT_USING_SERIAL_V2
default 32
config BSP_USING_UART5
bool "Enable UART5"
default y
config BSP_UART5_RX_USING_DMA
bool "Enable UART5 RX DMA"
depends on BSP_USING_UART5
select RT_SERIAL_USING_DMA
default n
config BSP_UART5_TX_USING_DMA
bool "Enable UART5 TX DMA"
depends on BSP_USING_UART5
select RT_SERIAL_USING_DMA
default n
config BSP_UART5_RX_BUFSIZE
int "Set UART5 RX buffer size"
range 64 65535
depends on BSP_USING_UART5 && RT_USING_SERIAL_V2
default 64
config BSP_UART5_TX_BUFSIZE
int "Set UART5 TX buffer size"
range 0 65535
depends on BSP_USING_UART5 && RT_USING_SERIAL_V2
default 0
config BSP_UART5_DMA_PING_BUFSIZE
int "Set UART5 RX DMA ping-pong buffer size"
range 32 65535
depends on BSP_UART5_RX_USING_DMA && RT_USING_SERIAL_V2
default 32
config BSP_USING_UART6
bool "Enable UART6"
default y
config BSP_UART6_RX_USING_DMA
bool "Enable UART6 RX DMA"
depends on BSP_USING_UART6
select RT_SERIAL_USING_DMA
default n
config BSP_UART6_TX_USING_DMA
bool "Enable UART6 TX DMA"
depends on BSP_USING_UART6
select RT_SERIAL_USING_DMA
default n
config BSP_UART6_RX_BUFSIZE
int "Set UART6 RX buffer size"
range 64 65535
depends on BSP_USING_UART6 && RT_USING_SERIAL_V2
default 64
config BSP_UART6_TX_BUFSIZE
int "Set UART6 TX buffer size"
range 0 65535
depends on BSP_USING_UART6 && RT_USING_SERIAL_V2
default 0
config BSP_UART6_DMA_PING_BUFSIZE
int "Set UART6 RX DMA ping-pong buffer size"
range 32 65535
depends on BSP_UART6_RX_USING_DMA && RT_USING_SERIAL_V2
default 32
endif
source "$(RTT_DIR)/bsp/stm32/libraries/HAL_Drivers/drivers/Kconfig"
-9
View File
@@ -1,12 +1,3 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-11-06 SummerGift first version
*/
#include <board.h>
#include <drv_common.h>
-9
View File
@@ -1,12 +1,3 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-11-5 SummerGift first version
*/
#ifndef __BOARD_H__
#define __BOARD_H__
+3 -3
View File
@@ -2,10 +2,10 @@
/*-Editor annotation file-*/
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
/*-Specials-*/
define symbol __ICFEDIT_intvec_start__ = 0x08000000;
define symbol __ICFEDIT_intvec_start__ = 0x08010000;
/*-Memory Regions-*/
define symbol __ICFEDIT_region_ROM_start__ = 0x08000000;
define symbol __ICFEDIT_region_ROM_end__ = 0x080FFFFF;
define symbol __ICFEDIT_region_ROM_start__ = 0x08010000;
define symbol __ICFEDIT_region_ROM_end__ = 0x0803FFFF;
define symbol __ICFEDIT_region_RAM1_start__ = 0x20000000;
define symbol __ICFEDIT_region_RAM1_end__ = 0x2001FFFF;
define symbol __ICFEDIT_region_RAM2_start__ = 0x10000000;
+1 -1
View File
@@ -7,7 +7,7 @@
/* Program Entry, set to mark it as "used" and avoid gc */
MEMORY
{
CODE (rx) : ORIGIN = 0x08000000, LENGTH = 1024k /* 1024KB flash */
CODE (rx) : ORIGIN = 0x08010000, LENGTH = 256k /* 256KB flash */
RAM1 (rw) : ORIGIN = 0x20000000, LENGTH = 128k /* 128K sram */
RAM2 (rw) : ORIGIN = 0x10000000, LENGTH = 64k /* 64K sram */
}
+15
View File
@@ -0,0 +1,15 @@
; *************************************************************
; *** Scatter-Loading Description File generated by uVision ***
; *************************************************************
LR_IROM1 0x08010000 0x00040000 { ; load region size_region
ER_IROM1 0x08010000 0x00040000 { ; load address = execution address
*.o (RESET, +First)
*(InRoot$$Sections)
.ANY (+RO)
}
RW_IRAM1 0x20000000 0x00020000 { ; RW data
.ANY (+RW +ZI)
}
}
+209 -204
View File
@@ -275,8 +275,8 @@
</OCR_RVCT3>
<OCR_RVCT4>
<Type>1</Type>
<StartAddress>0x8000000</StartAddress>
<Size>0x100000</Size>
<StartAddress>0x8010000</StartAddress>
<Size>0x40000</Size>
</OCR_RVCT4>
<OCR_RVCT5>
<Type>1</Type>
@@ -337,9 +337,9 @@
<v6Rtti>0</v6Rtti>
<VariousControls>
<MiscControls></MiscControls>
<Define>RT_USING_LIBC, __CLK_TCK=RT_TICK_PER_SECOND, RT_USING_ARMLIBC, USE_HAL_DRIVER, __RTTHREAD__, STM32F405xx, __STDC_LIMIT_MACROS</Define>
<Define>USE_HAL_DRIVER, STM32F405xx, __RTTHREAD__, __CLK_TCK=RT_TICK_PER_SECOND, __STDC_LIMIT_MACROS, RT_USING_LIBC, RT_USING_ARMLIBC</Define>
<Undefine></Undefine>
<IncludePath>..\..\lib\freemodbus\modbus\include;..\..\rt-thread\components\drivers\phy;..\..\lib\stm32f4\STM32F4_HAL\Inc;..\..\lib\freemodbus\modbus\rtu;..\..\rt-thread\components\drivers\include;..\..\lib\freemodbus\port;.;..\..\rt-thread\bsp\stm32\libraries\HAL_Drivers\drivers;..\..\rt-thread\components\net\netdev\include;..\..\rt-thread\components\drivers\smp_call;..\..\rt-thread\components\net\sal\include\socket;..\..\lib\cmsis-core\Include;..\..\lib\stm32f4\STM32F4_CMSIS\Include;..\..\rt-thread\libcpu\arm\cortex-m4;board\CubeMX_Config\Inc;..\..\rt-thread\components\libc\compilers\common\extension\fcntl\octal;..\..\rt-thread\bsp\stm32\libraries\HAL_Drivers\drivers\config;..\..\rt-thread\libcpu\arm\common;..\..\rt-thread\include;..\..\rt-thread\components\libc\posix\io\epoll;..\..\lib\stm32f4\STM32F4_HAL\Inc\Legacy;..\..\rt-thread\components\libc\posix\ipc;..\..\rt-thread\components\libc\posix\io\poll;..\..\rt-thread\components\drivers\include;..\..\rt-thread\components\libc\compilers\common\extension;..\..\rt-thread\components\libc\compilers\common\include;..\..\rt-thread\bsp\stm32\libraries\HAL_Drivers;..\..\lib\freemodbus\modbus\ascii;board;..\..\rt-thread\components\drivers\include;applications;..\..\lib\freemodbus\modbus\tcp;..\..\rt-thread\components\finsh;..\..\rt-thread\components\drivers\include;..\..\rt-thread\components\net\sal\include\socket\sys_socket;..\..\rt-thread\components\net\sal\include;..\..\rt-thread\components\libc\posix\io\eventfd;..\..\rt-thread\components\drivers\include</IncludePath>
<IncludePath>..\..\rt-thread\components\drivers\include;..\..\lib\cmsis-core\Include;board;..\..\rt-thread\components\finsh;..\..\rt-thread\components\net\netdev\include;..\..\rt-thread\bsp\stm32\libraries\HAL_Drivers;..\..\rt-thread\components\drivers\phy;..\..\rt-thread\libcpu\arm\common;..\..\rt-thread\components\libc\compilers\common\extension\fcntl\octal;..\..\rt-thread\include;applications;..\..\rt-thread\components\libc\posix\io\poll;..\..\rt-thread\components\net\sal\include\socket\sys_socket;..\..\rt-thread\components\drivers\include;..\..\rt-thread\components\libc\posix\ipc;..\..\lib\stm32f4\STM32F4_CMSIS\Include;..\..\lib\stm32f4\STM32F4_HAL\Inc\Legacy;..\..\lib\freemodbus\modbus\ascii;..\..\lib\freemodbus\modbus\rtu;..\..\rt-thread\bsp\stm32\libraries\HAL_Drivers\drivers;..\..\rt-thread\components\drivers\include;..\..\rt-thread\components\libc\compilers\common\include;..\..\rt-thread\bsp\stm32\libraries\HAL_Drivers\drivers\config;..\..\rt-thread\components\drivers\smp_call;..\..\lib\freemodbus\port;..\..\lib\freemodbus\modbus\tcp;..\..\rt-thread\components\drivers\include;.;..\..\rt-thread\components\libc\posix\io\epoll;..\..\rt-thread\components\libc\posix\io\eventfd;..\..\rt-thread\components\net\sal\include;..\..\rt-thread\components\net\sal\include\socket;..\..\lib\freemodbus\modbus\include;..\..\rt-thread\libcpu\arm\cortex-m4;..\..\lib\stm32f4\STM32F4_HAL\Inc;..\..\rt-thread\components\drivers\include;..\..\rt-thread\components\libc\compilers\common\extension;board\CubeMX_Config\Inc</IncludePath>
</VariousControls>
</Cads>
<Aads>
@@ -388,6 +388,11 @@
<FileType>1</FileType>
<FilePath>applications\main.c</FilePath>
</File>
<File>
<FileName>usart2.c</FileName>
<FileType>1</FileType>
<FilePath>applications\usart2.c</FilePath>
</File>
</Files>
</Group>
<Group>
@@ -1145,6 +1150,16 @@
<Group>
<GroupName>Finsh</GroupName>
<Files>
<File>
<FileName>shell.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\rt-thread\components\finsh\shell.c</FilePath>
</File>
<File>
<FileName>msh.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\rt-thread\components\finsh\msh.c</FilePath>
</File>
<File>
<FileName>cmd.c</FileName>
<FileType>1</FileType>
@@ -1155,26 +1170,136 @@
<FileType>1</FileType>
<FilePath>..\..\rt-thread\components\finsh\msh_parse.c</FilePath>
</File>
<File>
<FileName>msh.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\rt-thread\components\finsh\msh.c</FilePath>
</File>
<File>
<FileName>shell.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\rt-thread\components\finsh\shell.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>FreeModbus</GroupName>
<Files>
<File>
<FileName>mbfuncholding.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\modbus\functions\mbfuncholding.c</FilePath>
</File>
<File>
<FileName>mb_m.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\modbus\mb_m.c</FilePath>
</File>
<File>
<FileName>sample_mb_master.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\samples\sample_mb_master.c</FilePath>
</File>
<File>
<FileName>user_mb_app_m.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\port\user_mb_app_m.c</FilePath>
</File>
<File>
<FileName>mbrtu.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\modbus\rtu\mbrtu.c</FilePath>
</File>
<File>
<FileName>mbfuncinput_m.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\modbus\functions\mbfuncinput_m.c</FilePath>
</File>
<File>
<FileName>mbfunccoils.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\modbus\functions\mbfunccoils.c</FilePath>
</File>
<File>
<FileName>mbutils.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\modbus\functions\mbutils.c</FilePath>
</File>
<File>
<FileName>mbcrc.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\modbus\rtu\mbcrc.c</FilePath>
</File>
<File>
<FileName>mbrtu_m.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\modbus\rtu\mbrtu_m.c</FilePath>
</File>
<File>
<FileName>sample_mb_slave.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\samples\sample_mb_slave.c</FilePath>
</File>
<File>
<FileName>porttcp.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\port\porttcp.c</FilePath>
</File>
<File>
<FileName>portserial_m.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\port\portserial_m.c</FilePath>
</File>
<File>
<FileName>porttimer.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\port\porttimer.c</FilePath>
</File>
<File>
<FileName>portserial.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\port\portserial.c</FilePath>
</File>
<File>
<FileName>mb.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\modbus\mb.c</FilePath>
</File>
<File>
<FileName>porttimer_m.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\port\porttimer_m.c</FilePath>
</File>
<File>
<FileName>mbfuncinput.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\modbus\functions\mbfuncinput.c</FilePath>
</File>
<File>
<FileName>mbfuncholding_m.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\modbus\functions\mbfuncholding_m.c</FilePath>
</File>
<File>
<FileName>mbfuncother.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\modbus\functions\mbfuncother.c</FilePath>
</File>
<File>
<FileName>port.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\port\port.c</FilePath>
</File>
<File>
<FileName>mbfuncdisc_m.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\modbus\functions\mbfuncdisc_m.c</FilePath>
</File>
<File>
<FileName>user_mb_app.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\port\user_mb_app.c</FilePath>
</File>
<File>
<FileName>mbfuncdiag.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\modbus\functions\mbfuncdiag.c</FilePath>
</File>
<File>
<FileName>portevent_m.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\port\portevent_m.c</FilePath>
</File>
<File>
<FileName>mbfuncdisc.c</FileName>
<FileType>1</FileType>
@@ -1190,126 +1315,6 @@
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\port\portevent.c</FilePath>
</File>
<File>
<FileName>mb_m.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\modbus\mb_m.c</FilePath>
</File>
<File>
<FileName>mb.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\modbus\mb.c</FilePath>
</File>
<File>
<FileName>mbfuncinput_m.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\modbus\functions\mbfuncinput_m.c</FilePath>
</File>
<File>
<FileName>port.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\port\port.c</FilePath>
</File>
<File>
<FileName>portserial.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\port\portserial.c</FilePath>
</File>
<File>
<FileName>porttimer_m.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\port\porttimer_m.c</FilePath>
</File>
<File>
<FileName>mbutils.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\modbus\functions\mbutils.c</FilePath>
</File>
<File>
<FileName>sample_mb_slave.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\samples\sample_mb_slave.c</FilePath>
</File>
<File>
<FileName>portevent_m.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\port\portevent_m.c</FilePath>
</File>
<File>
<FileName>mbfuncdiag.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\modbus\functions\mbfuncdiag.c</FilePath>
</File>
<File>
<FileName>mbfuncholding.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\modbus\functions\mbfuncholding.c</FilePath>
</File>
<File>
<FileName>portserial_m.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\port\portserial_m.c</FilePath>
</File>
<File>
<FileName>mbrtu.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\modbus\rtu\mbrtu.c</FilePath>
</File>
<File>
<FileName>mbfuncdisc_m.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\modbus\functions\mbfuncdisc_m.c</FilePath>
</File>
<File>
<FileName>porttcp.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\port\porttcp.c</FilePath>
</File>
<File>
<FileName>user_mb_app.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\port\user_mb_app.c</FilePath>
</File>
<File>
<FileName>mbfunccoils.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\modbus\functions\mbfunccoils.c</FilePath>
</File>
<File>
<FileName>mbfuncinput.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\modbus\functions\mbfuncinput.c</FilePath>
</File>
<File>
<FileName>mbfuncholding_m.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\modbus\functions\mbfuncholding_m.c</FilePath>
</File>
<File>
<FileName>porttimer.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\port\porttimer.c</FilePath>
</File>
<File>
<FileName>mbcrc.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\modbus\rtu\mbcrc.c</FilePath>
</File>
<File>
<FileName>mbfuncother.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\modbus\functions\mbfuncother.c</FilePath>
</File>
<File>
<FileName>sample_mb_master.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\samples\sample_mb_master.c</FilePath>
</File>
<File>
<FileName>mbrtu_m.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\freemodbus\modbus\rtu\mbrtu_m.c</FilePath>
</File>
</Files>
</Group>
<Group>
@@ -2161,30 +2166,30 @@
<GroupName>klibc</GroupName>
<Files>
<File>
<FileName>kerrno.c</FileName>
<FileName>rt_vsscanf.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\rt-thread\src\klibc\kerrno.c</FilePath>
</File>
<File>
<FileName>rt_vsnprintf_tiny.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\rt-thread\src\klibc\rt_vsnprintf_tiny.c</FilePath>
<FilePath>..\..\rt-thread\src\klibc\rt_vsscanf.c</FilePath>
</File>
<File>
<FileName>kstdio.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\rt-thread\src\klibc\kstdio.c</FilePath>
</File>
<File>
<FileName>rt_vsscanf.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\rt-thread\src\klibc\rt_vsscanf.c</FilePath>
</File>
<File>
<FileName>kstring.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\rt-thread\src\klibc\kstring.c</FilePath>
</File>
<File>
<FileName>rt_vsnprintf_tiny.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\rt-thread\src\klibc\rt_vsnprintf_tiny.c</FilePath>
</File>
<File>
<FileName>kerrno.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\rt-thread\src\klibc\kerrno.c</FilePath>
</File>
</Files>
</Group>
<Group>
@@ -2245,55 +2250,25 @@
<Group>
<GroupName>STM32F4-CMSIS</GroupName>
<Files>
<File>
<FileName>startup_stm32f405xx.s</FileName>
<FileType>2</FileType>
<FilePath>..\..\lib\stm32f4\STM32F4_CMSIS\Source\Templates\arm\startup_stm32f405xx.s</FilePath>
</File>
<File>
<FileName>system_stm32f4xx.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\stm32f4\STM32F4_CMSIS\Source\Templates\system_stm32f4xx.c</FilePath>
</File>
<File>
<FileName>startup_stm32f405xx.s</FileName>
<FileType>2</FileType>
<FilePath>..\..\lib\stm32f4\STM32F4_CMSIS\Source\Templates\arm\startup_stm32f405xx.s</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>STM32F4-HAL</GroupName>
<Files>
<File>
<FileName>stm32f4xx_hal.c</FileName>
<FileName>stm32f4xx_hal_pwr.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal.c</FilePath>
</File>
<File>
<FileName>stm32f4xx_hal_rcc_ex.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_rcc_ex.c</FilePath>
</File>
<File>
<FileName>stm32f4xx_hal_pwr_ex.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_pwr_ex.c</FilePath>
</File>
<File>
<FileName>stm32f4xx_hal_uart.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_uart.c</FilePath>
</File>
<File>
<FileName>stm32f4xx_hal_cryp.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_cryp.c</FilePath>
</File>
<File>
<FileName>stm32f4xx_hal_gpio.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_gpio.c</FilePath>
</File>
<File>
<FileName>stm32f4xx_hal_dma_ex.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_dma_ex.c</FilePath>
<FilePath>..\..\lib\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_pwr.c</FilePath>
</File>
<File>
<FileName>stm32f4xx_hal_crc.c</FileName>
@@ -2301,44 +2276,74 @@
<FilePath>..\..\lib\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_crc.c</FilePath>
</File>
<File>
<FileName>stm32f4xx_hal_usart.c</FileName>
<FileName>stm32f4xx_hal_rcc_ex.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_usart.c</FilePath>
<FilePath>..\..\lib\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_rcc_ex.c</FilePath>
</File>
<File>
<FileName>stm32f4xx_hal_rng.c</FileName>
<FileName>stm32f4xx_hal_dma_ex.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_rng.c</FilePath>
</File>
<File>
<FileName>stm32f4xx_hal_rcc.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_rcc.c</FilePath>
</File>
<File>
<FileName>stm32f4xx_hal_cortex.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_cortex.c</FilePath>
<FilePath>..\..\lib\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_dma_ex.c</FilePath>
</File>
<File>
<FileName>stm32f4xx_hal_cryp_ex.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_cryp_ex.c</FilePath>
</File>
<File>
<FileName>stm32f4xx_hal_cec.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_cec.c</FilePath>
</File>
<File>
<FileName>stm32f4xx_hal_dma.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_dma.c</FilePath>
</File>
<File>
<FileName>stm32f4xx_hal_pwr.c</FileName>
<FileName>stm32f4xx_hal_rng.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_pwr.c</FilePath>
<FilePath>..\..\lib\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_rng.c</FilePath>
</File>
<File>
<FileName>stm32f4xx_hal_gpio.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_gpio.c</FilePath>
</File>
<File>
<FileName>stm32f4xx_hal_cryp.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_cryp.c</FilePath>
</File>
<File>
<FileName>stm32f4xx_hal_cec.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_cec.c</FilePath>
</File>
<File>
<FileName>stm32f4xx_hal_usart.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_usart.c</FilePath>
</File>
<File>
<FileName>stm32f4xx_hal_pwr_ex.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_pwr_ex.c</FilePath>
</File>
<File>
<FileName>stm32f4xx_hal.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal.c</FilePath>
</File>
<File>
<FileName>stm32f4xx_hal_rcc.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_rcc.c</FilePath>
</File>
<File>
<FileName>stm32f4xx_hal_uart.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_uart.c</FilePath>
</File>
<File>
<FileName>stm32f4xx_hal_cortex.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\lib\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_cortex.c</FilePath>
</File>
</Files>
</Group>
+3
View File
@@ -474,6 +474,9 @@
#define BSP_STM32_UART_V1_TX_TIMEOUT 2000
#define BSP_USING_UART1
#define BSP_USING_UART2
#define BSP_USING_UART3
#define BSP_USING_UART4
#define BSP_USING_UART6
/* end of On-chip Peripheral Drivers */
/* Board extended module Drivers */
Binary file not shown.
BIN
View File
Binary file not shown.
@@ -0,0 +1,94 @@
冠达快充板(SINK)通讯协议
2025.8.13
SINK的ID为1,波特率200KTTL
1.读取变电压板电压
(要实时比较设置的快充指令和读回来的快充指令,若有不一样,则重设)
(注意vooc模式下数据返回会很慢)
发送:
0B 00 01 20 loadvh loadvl loadch loadcl nc nc CRC8 //长度+nc+id+指令+负载电压(2字节,0.01V)+负载电流(2字节,mA)+2个预留字节+CRC8校验
回复:
15 00 01 20 VH VL qc_data1 qc_data2 qc_data3 qc_data4 qc_data5 qc_data6 ver_h ver_l nc nc nc nc nc nc CRC8
//长度+nc+ID+指令+2字节电压(0.01V)+6字节快充指令+2字节版本号+6字节预留+CRC8校验
2.读取源端的PD协议数据(当前为PDO,PPS,PD3.1,AVS协议时有效)
发送:05 00 01 13 2A
回复:
XX 00 01 13 //长度(根据实际计算)+NC+ID+指令
00 00 VMINH VMINL VMAXH VMAXL CURH/PORH CURL/PORL NC NC NC NC NC NC
//源类型(1字节,00为PDO,03为APDO) + PPS类型(1字节,源类型为3时有效,00为SPR PPS,01为EPR AVS,02为SPR AVS) + 最小电压(2字节,mV) + 最大电压(2字节,mV) + 最大电流/功率(2字节,mA/W) + 预留(6字节,当PPS类型为02时有效,意义与前6字节一致)
00 00 VMINH VMINL VMAXH VMAXL CURH/PORH CURL/PORL NC NC NC NC NC NC
......
CRC8
3.设置CC线
发送:
06 00 01 17 00 2A //长度+nc+id+指令+CC(0为都选通,1为选择CC1,2为CC2,3为全断开)+CRC8校验
回复:
05 00 01 17 2A //长度+nc+id+指令+CRC8校验
4.设置CC线电平
发送:
06 00 01 16 00 2A //长度+nc+id+指令+电平等级(0-10,默认7)+CRC8校验
回复:
05 00 01 16 2A //长度+nc+id+指令+CRC8校验
5.设置快充协议(VOOC,UFCS模式下切换其他模式时,需要先把V+,V-,D+,D-,CC等和变电压有关的继电器切至悬空,至少等待1s后,等能读到数据且快充指令正确,再把继电器切回)
格式:
长度+NC+ID+6字节快充数据+CRC8
发送:
1、QC2.0,电压5V/9V/12V/20V 命令:0A 00 01 F8 5A 00 00 00 00 2A //第5个字节为电压(0.1V)
2、QC3.0,电压3.3-20V 命令:0A 00 01 F6 5A 00 00 00 00 2A //第5个字节为电压(0.1V)
3、FCP,电压5V/9V/12V 命令:0A 00 01 F2 78 00 00 00 00 2A //第5个字节为电压(0.1V)
4、AFC,命令:0A 00 01 F9 46 00 00 00 00 2A //第5个字节为变电压数据,详细参考AFC文档
5、SCP,命令:0A 00 01 F3 27 10 0F A0 00 2A //56字节为电压(mv)7、8字节为电流(mA)
6、VIVO 命令:0A 00 01 FD 27 10 00 00 00 2A //56字节为电压(mv)7、8字节为电流(mA)
7、传音/TFC,命令:0A 00 01 F7 2E E0 00 00 00/01 2A //56字节为电压(mv)7、8字节为电流(mA),9字节为RFC/TFC选择
8、PDO手动,需要设定组号,电压和产品相关,命令:0A 00 01 FB 05 00 00 00 00 2A //5字节为组号
9、PDO自动,组号设为0,自动变到指定电压,命令:0A 00 01 FB 00 2E E0 00 00 2A //5字节为组号,6,7字节为电压(mv),8、9字节为电流(mA)
10、PPS手动,需要设定组号、电压、电流,电流0最大, 命令: 0A 00 01 FC 06 4E 20 00 00 2A //5字节为组号,6,7字节为电压(mv),8、9字节为电流(mA)
11、PPS自动,组号设为0,设定电压、电流,电流0最大, 命令:0A 00 01 FC 00 4E 20 00 00 2A //5字节为组号,6,7字节为电压(mv),8、9字节为电流(mA)
12、PD3.1, 命令:0A 00 01 E1 00 2328 07d0 2A (组号设置和电压设置都支持) //5字节为组号,6,7字节为电压(mv),8、9字节为电流(mA)
13、UFCS,命令:0A 00 01 E0 00 2328 07d0 2A (组号设置和电压设置都支持) //5字节为组号,6,7字节为电压(mv),8、9字节为电流(mA)
14、VOOC,电压10/11V, 命令:0A 00 01 E2 00 0000 0000 2A //
15、AVS,命令:0A 00 01 E3 00 4e20 07d0 2A (组号设置和电压设置都支持) //5字节为组号,6,7字节为电压(mv),8、9字节为电流(mA)
回复:
回复最基本的5个字节:
长度+NC+ID+指令+CRC8
CRC8校验算法如下:
u8 get_crc(u8 *dat,u8 k)
{
u8 i,res;
res=0x55;
for(i=0;i<k;i++){ res=crc8(res,dat[i]);}
return res;
}
u8 crc8(u8 res,u8 dat)
{
u8 i,t;
for(i=0;i<8;i++)
{
t=dat^res;
if((t&0x01)==0x01){res=res^0x18;res>>=1;res|=0x80;}//
else{res>>=1;}
dat>>=1;
}
return res;
}
@@ -0,0 +1,84 @@
冠达快充板(SOURCE)通讯协议
2025.8.2
SOURCE的ID为2,波特率200K
1.读取数据
发送:
0B 00 02 20 volh voll curh curl nc nc CRC8
//长度+nc+id+指令+2字节当前电源电压(mV)+2字节当前电源电流(mA)+2个预留字节+CRC8校验
回复:
15 00 02 20 VH VL setvh setvl setch setcl NC NC verh verl NC NC NC NC NC NC CRC8
//长度+nc+ID+指令+2字节读取的电压(0.01V)+2字节source设置电压(mV)+2字节source设置电流(mA)+2字节预留+2字节版本号+6字节预留+CRC8校验
2.读取source的PD协议数据(当前为PDO,PPS,PD3.1,AVS协议时有效)
发送:05 00 02 13 2A
回复:
XX 00 02 13 //长度(根据实际计算)+NC+ID+指令
00 00 VMAXH VMAXL VMINH VMINL CURH/PORH CURL/PORL NC NC NC NC NC NC
//源类型(1字节,00为PDO,03为APDO) + PPS类型(1字节,源类型为3时有效,00为SPR PPS,01为EPR AVS,02为SPR AVS) + 最大电压(2字节,mV) + 最小电压(2字节,mA) + 最大电流/功率(2字节,mA/W) + 预留(6字节,当协议类型为02时有效,意义与前6字节一致)
00 00 VMAXH VMAXL VMINH VMINL CURH/PORH CURL/PORL NC NC NC NC NC NC
......
CRC8
3.设置CC线电平
发送:
06 00 02 16 00 2A //长度+nc+id+指令+电平等级(0xff为根据当前电流自动设置,否则为手动设定,设置方法待定)+CRC8校验
回复:
05 00 02 16 2A //长度+nc+id+指令+CRC8校验
4.设置支持的快充协议
发送:
XX 00 02 D0 //长度(根据实际计算)+NC+ID+指令
00 00 00 VMAXH VMAXL VMINH VMINL CURH/PORH CURL/PORL NC NC NC NC NC NC
//协议(1字节) + 源类型(1字节,PD协议有效,00为PDO,03为APDO) + PPS类型(1字节,PD协议有效,源类型为3时有效,00为SPR PPS,01为EPR AVS,02为SPR AVS) + 最大电压(2字节,mV) + 最小电压(2字节,mA) + 最大电流/功率(2字节,mA/W) + 预留(6字节,当协议类型为02时有效,意义与前6字节一致)
00 00 00 VMAXH VMAXL VMINH VMINL CURH/PORH CURL/PORL NC NC NC NC NC NC
......
CRC8
回复:
05 00 02 D0 CRC8
协议字节含义如下:
00 无快充
01 VIFC(暂不支持)
02 FCP
03 SCP
04 预留
05 预留
06 RFC(暂不支持)
07 QC3.0
08 QC2.0
09 AFC
0A PDO/PPS
0B 预留
0C UFCS
0D PD3.1/AVS
0E VOOC(暂不支持)
CRC8校验算法如下:
u8 get_crc(u8 *dat,u8 k)
{
u8 i,res;
res=0x55;
for(i=0;i<k;i++){ res=crc8(res,dat[i]);}
return res;
}
u8 crc8(u8 res,u8 dat)
{
u8 i,t;
for(i=0;i<8;i++)
{
t=dat^res;
if((t&0x01)==0x01){res=res^0x18;res>>=1;res|=0x80;}//
else{res>>=1;}
dat>>=1;
}
return res;
}
-1
View File
@@ -22,7 +22,6 @@ del JLinkLog.txt /s
del *.iex /s
del *.htm /s
del *.sct /s
del *.map /s
del *.dbgconf /s
+1 -1
View File
@@ -60,7 +60,7 @@ static void send_thread_entry(void *parameter)
static void mb_master_poll(void *parameter)
{
eMBMasterInit(MB_RTU, PORT_NUM, PORT_BAUDRATE, PORT_PARITY);
eMBMasterInit(MB_RTU, 6, PORT_BAUDRATE, PORT_PARITY);
eMBMasterEnable();
while (1)