使用stm32f103ze,移植完成nano的3.1.5版本。在增加uart2的dma接收配置时,出现问题,代码图下 #include "drive_uart.h"
#define LEN_UART2_RECV_BUFF 100
UART_HandleTypeDef UART2_Handler; //UART2句柄
DMA_HandleTypeDef UART2RxDMA_Handler;
unsigned char g_uart2_buff[LEN_UART2_RECV_BUFF]={0};
unsigned char hdma_usart2_rx=0;
void uart2_init_console(u32 bound)
{
//UART 初始化设置
UART2_Handler.Instance=USART2; //USART2
UART2_Handler.Init.BaudRate=bound; //波特率
UART2_Handler.Init.WordLength=UART_WORDLENGTH_8B; //字长为8位数据格式
UART2_Handler.Init.StopBits=UART_STOPBITS_1; //一个停止位
UART2_Handler.Init.Parity=UART_PARITY_NONE; //无奇偶校验位
UART2_Handler.Init.HwFlowCtl=UART_HWCONTROL_NONE; //无硬件流控
UART2_Handler.Init.Mode=UART_MODE_TX_RX;
HAL_UART_Init(&UART2_Handler);
}
void dma_usart2_rx_config()
{
__HAL_RCC_DMA1_CLK_ENABLE();
UART2RxDMA_Handler.Instance = DMA1_Channel6;
UART2RxDMA_Handler.Init.Direction = DMA_PERIPH_TO_MEMORY; //外设到内存
UART2RxDMA_Handler.Init.PeriphInc = DMA_PINC_DISABLE;
UART2RxDMA_Handler.Init.MemInc = DMA_MINC_ENABLE;
UART2RxDMA_Handler.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
UART2RxDMA_Handler.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
UART2RxDMA_Handler.Init.Mode = DMA_CIRCULAR;
UART2RxDMA_Handler.Init.Priority=DMA_PRIORITY_MEDIUM;
HAL_DMA_DeInit(&UART2RxDMA_Handler);
HAL_DMA_Init(&UART2RxDMA_Handler);
__HAL_LINKDMA(&UART2_Handler, hdmatx, UART2RxDMA_Handler);
HAL_UART_Receive_DMA(&UART2_Handler, g_uart2_buff, LEN_UART2_RECV_BUFF);
}
unsigned char buffer_data_num_index()
{
return (LEN_UART2_RECV_BUFF - __HAL_DMA_GET_COUNTER(&UART2RxDMA_Handler));
}
void dma_usart2_init()
{
uart2_init_console(115200);
dma_usart2_rx_config();
}
其中 dma_usart2_init 在 main 函数中调用。当在 dma_usart2_rx_config 函数中增加 HAL_UART_Receive_DMA 时,程序启动时会报错,信息如下 \ | / - RT - Thread Operating System
/ | \ 3.1.5 build Aug 13 2023
2006 - 2020 Copyright by rt-thread team
psr: 0x01000000
r00: 0x08001f5f
r01: 0x00000000
r02: 0x00000064
r03: 0x00001000
r04: 0x20000208
r05: 0x00000064
r06: 0xdeadbeef
r07: 0xdeadb
\ | / - RT - Thread Operating System
/ | \ 3.1.5 build Aug 13 2023
2006 - 2020 Copyright by rt-thread team
psr: 0x01000000
r00: 0x08001f5f
r01: 0x00000000
r02: 0x00000064
r03: 0x00001000
r04: 0x20000208
r05: 0x00000064
r06: 0xdeadbeef
r07: 0xdeadbeef
r08: 0xdeadbeef
r09: 0xdeadbeef
r10: 0xdeadbeef
r11: 0xdeadbeef
r12: 0x00000008
lr: 0x0800279f
pc: 0x08001942
hard fault on thread: main
thread pri status sp stack size max used left tick error
tshell 21 ready 0x00000040 0x00000400 06% 0x0000000a 000
tidle 31 ready 0x00000044 0x00000100 26% 0x00000020 000
main 10 ready 0x00000044 0x00000400 23% 0x00000013 000
bus fault:
SCB_CFSR_BFSR:0x04 IMPRECISERR
|