嵌入式技术william hill官网
直播中

LL-LING宁

9年用户 1343经验值
擅长:电源/新能源
私信 关注
[问答]

使用STM32H743 uart3的dma接收数据失败这是什么原因呢?

我现在使用STM32H743 uart3 的dma 接收数据,程序一运行,出现

Warning: There is no enough buffer for saving data, please increase the RT_SERIAL_RB_BUFSZ option.
rning: There is no enougmsh

这是什么原因呢?

回帖(9)

bigbangboom

2023-2-20 14:37:24
RT_SERIAL_RB_BUFSZ 你查找一下现在的大小
举报

fanB

2023-2-20 14:37:34
开启DMA模式接收需要使用buffer,并且buffer的尺寸要正确设定。
举报

LL-LING宁

2023-2-20 14:37:43
我使用
` config.baud_rate = BAUD_RATE_9600;
config.data_bits = DATA_BITS_8;
config.stop_bits = STOP_BITS_1;
config.bufsz = 1024*4; //修改缓冲区 buff size 为 512
config.parity = PARITY_NONE; //无奇偶校验位

/ step3:控制串口设备。通过控制接口传入命令控制字,与控制参数 /
rt_device_control(serial, RT_DEVICE_CTRL_CONFIG, &config);
`
配置的这个bufsz 可以么?是这样用么?谢谢
举报

fanB

2023-2-20 14:37:52
你修改的位置不对呀。
举报

LL-LING宁

2023-2-20 14:38:04
这里也改了

define RT_USING_DEVICE_IPC
define RT_PIPE_BUFSZ 512
define RT_USING_SERIAL
define RT_SERIAL_USING_DMA
define RT_SERIAL_RB_BUFSZ 4096
define RT_USING_PIN
不行,仿真运行的时候只要一执行

result=rt_device_open(serial, RT_DEVICE_FLAG_DMA_RX);
在串口终端就会打印出

ope[W/UART] Warning: There is no enough buffer for saving data, please increase the RT_SERIAL_RB_BUFSZ option.
ning: There is no enougmsh >
举报

LL-LING宁

2023-2-20 14:38:13
现在串口打印的信息又多了一些:

msh >Serial_com_sample
init message queue success!.
o[W/UART] Warning: There is no enough buffer for saving data, please increase the RT_SERIAL_RB_BUFSZ option.
input the receiver callback!
input the receiver buf is :
nput the receiver buf is thread: recv msg from msg queue, the content:?
msh >thread:Serial_c?stack overflow
thread   pri  status      sp     stack size max used left tick  error
-------- ---  ------- ---------- ----------  ------  ---------- ---
Serial_c  15  running 0x00001480 0x00000800    03%   0x00000005 -02
tshell    20  suspend 0x00000110 0x00001000    08%   0x00000004 000
tidle0    31  ready   0x00000054 0x00000400    08%   0x00000017 000
什么问题呢?不知道从哪入手了
举报

LL-LING宁

2023-2-20 14:38:20
把任务堆栈改成
static char Serial_com_t_stack[1024*8];
后变为 这样了,没有堆栈错误了 ,还是有以前的错误

msh >Serial_com_sample
init message queue success!.
o[W/UART] Warning: There is no enough buffer for saving data, please increase the RT_SERIAL_RB_BUFSZ option.
input the receiver callback!
input the receiver buf is :
nput the receiver buf is thread: recv msg from msg queue, the content:?
msh >
举报

LL-LING宁

2023-2-20 14:38:25
现在我调试代码是一进入 串口3的接收回调函数 ,终端就会打印出

[W/UART] Warning: There is no enough buffer for saving data, please increase the RT_SERIAL_RB_BUFSZ option.
举报

LL-LING宁

2023-2-20 14:38:36
我的dma配置代码有问题么?

#ifdef RT_SERIAL_USING_DMA
static void stm32_dma_config(struct rt_serial_device *serial, rt_ubase_t flag)
{
    struct rt_serial_rx_fifo *rx_fifo;
    DMA_HandleTypeDef *DMA_Handle;
    struct dma_config *dma_config;
    struct stm32_uart *uart;
    RT_ASSERT(serial != RT_NULL);
    uart = rt_container_of(serial, struct stm32_uart, serial);
    if (RT_DEVICE_FLAG_DMA_RX == flag)
    {
        DMA_Handle = &uart->dma_rx.handle;
        dma_config = uart->config->dma_rx;
    }
    else if (RT_DEVICE_FLAG_DMA_TX == flag)
    {
        DMA_Handle = &uart->dma_tx.handle;
        dma_config = uart->config->dma_tx;
    }
    LOG_D("%s dma config start", uart->config->name);
    {
        rt_uint32_t tmpreg = 0x00U;
#if defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32G0)
    || defined(SOC_SERIES_STM32L0)
        /* enable DMA clock && Delay after an RCC peripheral clock enabling*/
        SET_BIT(RCC->AHBENR, dma_config->dma_rcc);
        tmpreg = READ_BIT(RCC->AHBENR, dma_config->dma_rcc);
#elif defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32L4)
    || defined(SOC_SERIES_STM32G4)
        /* enable DMA clock && Delay after an RCC peripheral clock enabling*/
        SET_BIT(RCC->AHB1ENR, dma_config->dma_rcc);
        tmpreg = READ_BIT(RCC->AHB1ENR, dma_config->dma_rcc);
#if (defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32G4)) && defined(DMAMUX1)
        /* enable DMAMUX clock for L4+ and G4 */
        __HAL_RCC_DMAMUX1_CLK_ENABLE();
#endif
#endif
        UNUSED(tmpreg);   /* To avoid compiler warnings */
    }
    if (RT_DEVICE_FLAG_DMA_RX == flag)
    {
        __HAL_LINKDMA(&(uart->handle), hdmarx, uart->dma_rx.handle);
    }
    else if (RT_DEVICE_FLAG_DMA_TX == flag)
    {
        __HAL_LINKDMA(&(uart->handle), hdmatx, uart->dma_tx.handle);
    }
#if defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32L0)
    DMA_Handle->Instance                 = dma_config->Instance;
#elif defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7)
    DMA_Handle->Instance                 = dma_config->Instance;
    DMA_Handle->Init.Channel             = dma_config->channel;
#elif defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32G0) || defined(SOC_SERIES_STM32G4)
    DMA_Handle->Instance                 = dma_config->Instance;
    DMA_Handle->Init.Request             = dma_config->request;
#endif
    DMA_Handle->Instance                    =DMA1_Stream1;
    DMA_Handle->Init.PeriphInc           = DMA_PINC_DISABLE;
    DMA_Handle->Init.MemInc              = DMA_MINC_ENABLE;
    DMA_Handle->Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
    DMA_Handle->Init.MemDataAlignment    = DMA_MDATAALIGN_BYTE;
    if (RT_DEVICE_FLAG_DMA_RX == flag)
    {
        DMA_Handle->Init.Direction           = DMA_PERIPH_TO_MEMORY;
        DMA_Handle->Init.Mode                = DMA_NORMAL ;
    }
    else if (RT_DEVICE_FLAG_DMA_TX == flag)
    {
        DMA_Handle->Init.Direction           = DMA_MEMORY_TO_PERIPH;
        DMA_Handle->Init.Mode                = DMA_NORMAL;
    }
    DMA_Handle->Init.Priority            = DMA_PRIORITY_MEDIUM;
#if defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7)
    DMA_Handle->Init.FIFOMode            = DMA_FIFOMODE_DISABLE;
#endif
    if (HAL_DMA_DeInit(DMA_Handle) != HAL_OK)
    {
        RT_ASSERT(0);
    }
    if (HAL_DMA_Init(DMA_Handle) != HAL_OK)
    {
        RT_ASSERT(0);
    }
    /* enable interrupt */
    if (flag == RT_DEVICE_FLAG_DMA_RX)
    {
        rx_fifo = (struct rt_serial_rx_fifo *)serial->serial_rx;
        /* Start DMA transfer */
        if (HAL_UART_Receive_DMA(&(uart->handle), rx_fifo->buffer, serial->config.bufsz) != HAL_OK)
        {
            /* Transfer error in reception process */
            RT_ASSERT(0);
        }
        CLEAR_BIT(uart->handle.Instance->CR3, USART_CR3_EIE);
        __HAL_UART_ENABLE_IT(&(uart->handle), UART_IT_IDLE);
    }
    /* enable irq */
    HAL_NVIC_SetPriority(dma_config->dma_irq, 0, 0);
    HAL_NVIC_EnableIRQ(dma_config->dma_irq);
    HAL_NVIC_SetPriority(uart->config->irq_type, 1, 0);
    HAL_NVIC_EnableIRQ(uart->config->irq_type);
    LOG_D("%s dma %s instance: %x", uart->config->name, flag == RT_DEVICE_FLAG_DMA_RX ? "RX" : "TX", DMA_Handle->Instance);
    LOG_D("%s dma config done", uart->config->name);
}
举报

更多回帖

发帖
×
20
完善资料,
赚取积分