搜索
bottom↓
回复: 9

请问STM32的UART3 的 tx模式是必须用dma 么? poll 不行么?

[复制链接]

出0入0汤圆

发表于 2011-8-17 23:17:35 | 显示全部楼层 |阅读模式
rt—thread 给的例程里面

uart3 如果注_册的话会是dma模式

我在实际使用的时候想还是用polling 模式。

所以在初始化的时候改了一下

#ifdef RT_USING_UART2
        USART_InitStructure.USART_BaudRate = 115200;
        USART_InitStructure.USART_WordLength = USART_WordLength_8b;
        USART_InitStructure.USART_StopBits = USART_StopBits_1;
        USART_InitStructure.USART_Parity = USART_Parity_No;
        USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
        USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
        USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;
        USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;
        USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;
        USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;
        USART_Init(USART2, &USART_InitStructure);
        USART_ClockInit(USART2, &USART_ClockInitStructure);

        /* register uart2 */
        rt_hw_serial_register(&uart2_device, "uart2",
                RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM,
                &uart2);

        /* Enable USART2 DMA Rx request */
        USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
#endif

#ifdef RT_USING_UART3
        USART_InitStructure.USART_BaudRate = 115200;
        USART_InitStructure.USART_WordLength = USART_WordLength_8b;
        USART_InitStructure.USART_StopBits = USART_StopBits_1;
        USART_InitStructure.USART_Parity = USART_Parity_No;
        USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
        USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
        USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;
        USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;
        USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;
        USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;
        USART_Init(USART3, &USART_InitStructure);
        USART_ClockInit(USART3, &USART_ClockInitStructure);

        //uart3_dma_tx.dma_channel= UART3_TX_DMA;

        /* register uart3 */
        rt_hw_serial_register(&uart3_device, "uart3",
                RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM,
                &uart3);

        /* Enable USART3 DMA Tx request */
//        USART_DMACmd(USART3, USART_DMAReq_Tx , ENABLE);

        /* enable interrupt */
        USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
#endif


也就是变得和uart2 完全一致了。

可是我在使用的过程中发现类似的

  rt_device_write(&uart3_device, 0,cmd0 ,rt_strlen(cmd0)); 不工作


而 rt_device_write(&uart2_device, 0,cmd0 ,rt_strlen(cmd0)); 正常工作。

我在初始化注_册的时候uart2 和3 完全一样的步骤。只是名称不一样。

请问stm32 的uart 3 是必须要dma模式发送么 ?

阿莫论坛20周年了!感谢大家的支持与爱护!!

一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。

出0入0汤圆

发表于 2011-8-18 09:27:04 | 显示全部楼层
UART3采用DMA不是必须的,估计你哪里还没设置好吧

出0入0汤圆

 楼主| 发表于 2011-8-18 12:58:52 | 显示全部楼层
比了一下,除了名称都一样了啊。

出0入0汤圆

 楼主| 发表于 2011-8-18 23:21:36 | 显示全部楼层
void rt_hw_usart_init()
{
        USART_InitTypeDef USART_InitStructure;
        USART_ClockInitTypeDef USART_ClockInitStructure;

        RCC_Configuration();

        GPIO_Configuration();

        NVIC_Configuration();

        //DMA_Configuration();

        /* uart init */
#ifdef RT_USING_UART1
        USART_InitStructure.USART_BaudRate = 115200;
        USART_InitStructure.USART_WordLength = USART_WordLength_8b;
        USART_InitStructure.USART_StopBits = USART_StopBits_1;
        USART_InitStructure.USART_Parity = USART_Parity_No;
        USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
        USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
        USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;
        USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;
        USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;
        USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;
        USART_Init(USART1, &USART_InitStructure);
        USART_ClockInit(USART1, &USART_ClockInitStructure);

        /* register uart1 */
        rt_hw_serial_register(&uart1_device, "uart1",
                RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM,
                &uart1);

        /* enable interrupt */
        USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
#endif

#ifdef RT_USING_UART2
        USART_InitStructure.USART_BaudRate = 115200;
        USART_InitStructure.USART_WordLength = USART_WordLength_8b;
        USART_InitStructure.USART_StopBits = USART_StopBits_1;
        USART_InitStructure.USART_Parity = USART_Parity_No;
        USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
        USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
        USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;
        USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;
        USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;
        USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;
        USART_Init(USART2, &USART_InitStructure);
        USART_ClockInit(USART2, &USART_ClockInitStructure);

        /* register uart2 */
        rt_hw_serial_register(&uart2_device, "uart2",
                RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM,
                &uart2);

        /* Enable USART2 DMA Rx request */
        USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
#endif

#ifdef RT_USING_UART3
        USART_InitStructure.USART_BaudRate = 115200;
        USART_InitStructure.USART_WordLength = USART_WordLength_8b;
        USART_InitStructure.USART_StopBits = USART_StopBits_1;
        USART_InitStructure.USART_Parity = USART_Parity_No;
        USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
        USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
        USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;
        USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;
        USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;
        USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;
        USART_Init(USART3, &USART_InitStructure);
        USART_ClockInit(USART3, &USART_ClockInitStructure);

        //uart3_dma_tx.dma_channel= UART3_TX_DMA;

        /* register uart3 */
        rt_hw_serial_register(&uart3_device, "uart3",
                RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM,
                &uart3);

        /* Enable USART3 DMA Tx request */
//        USART_DMACmd(USART3, USART_DMAReq_Tx , ENABLE);

        /* enable interrupt */
        USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
#endif

出0入0汤圆

 楼主| 发表于 2011-8-18 23:22:08 | 显示全部楼层
static void RCC_Configuration(void)
{
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);

#ifdef RT_USING_UART1
        /* Enable USART1 and GPIOA clocks */
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
#endif

#ifdef RT_USING_UART2

#if (defined(STM32F10X_LD) || defined(STM32F10X_MD) || defined(STM32F10X_CL))
    /* Enable AFIO and GPIOD clock */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOD, ENABLE);

    /* Enable the USART2 Pins Software Remapping */
    GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
#else
    /* Enable AFIO and GPIOA clock */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA, ENABLE);
#endif

        /* Enable USART2 clock */
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
#endif

#ifdef RT_USING_UART3
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
        /* Enable USART3 clock */
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);

        /* DMA clock enable */
//        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
#endif
}

出0入0汤圆

 楼主| 发表于 2011-8-18 23:22:48 | 显示全部楼层
static void GPIO_Configuration(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;

#ifdef RT_USING_UART1
        /* Configure USART1 Rx (PA.10) as input floating */
        GPIO_InitStructure.GPIO_Pin = UART1_GPIO_RX;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
        GPIO_Init(UART1_GPIO, &GPIO_InitStructure);

        /* Configure USART1 Tx (PA.09) as alternate function push-pull */
        GPIO_InitStructure.GPIO_Pin = UART1_GPIO_TX;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
        GPIO_Init(UART1_GPIO, &GPIO_InitStructure);
#endif

#ifdef RT_USING_UART2
        /* Configure USART2 Rx as input floating */
        GPIO_InitStructure.GPIO_Pin = UART2_GPIO_RX;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
        GPIO_Init(UART2_GPIO, &GPIO_InitStructure);

        /* Configure USART2 Tx as alternate function push-pull */
        GPIO_InitStructure.GPIO_Pin = UART2_GPIO_TX;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(UART2_GPIO, &GPIO_InitStructure);
#endif

#ifdef RT_USING_UART3
        /* Configure USART3 Rx as input floating */
        GPIO_InitStructure.GPIO_Pin = UART3_GPIO_RX;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
        GPIO_Init(UART3_GPIO, &GPIO_InitStructure);

        /* Configure USART3 Tx as alternate function push-pull */
        GPIO_InitStructure.GPIO_Pin = UART3_GPIO_TX;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(UART3_GPIO, &GPIO_InitStructure);
#endif
}

出0入0汤圆

 楼主| 发表于 2011-8-18 23:23:20 | 显示全部楼层
static void NVIC_Configuration(void)
{
        NVIC_InitTypeDef NVIC_InitStructure;

        /* Configure the NVIC Preemption Priority Bits */
        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);

#ifdef RT_USING_UART1
        /* Enable the USART1 Interrupt */
        NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);
#endif

#ifdef RT_USING_UART2
        /* Enable the USART2 Interrupt */
        NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);
#endif

#ifdef RT_USING_UART3
        /* Enable the USART3 Interrupt */
        NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);
#if 0
        /* Enable the DMA1 Channel2 Interrupt */
        NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel2_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);
#endif
#endif
}

出0入0汤圆

 楼主| 发表于 2011-8-19 08:27:07 | 显示全部楼层
我把整个程序又改回到dma 模式了(就直接用原来的程序不改动),

在rt_serial_write UART3的时候,也会进入DMA的write 模式,

但是程序马上就会进入到

USART3_IRQHandler
  B       .


按理说这个跟UART3的中断已经没关系了啊。

出0入0汤圆

发表于 2011-8-19 09:48:19 | 显示全部楼层
UART不管是中断模块,DMA模式,STM32的固件库中应该都有例程,你把你的代码与例程仔细对比下应该就能够找出问题。

基本的驱动是与OS无关的,只有当它要和上层应用纠缠在一起时,才考虑OS的问题。

出0入0汤圆

发表于 2011-9-13 20:00:07 | 显示全部楼层
可以用的。。这个我试过。是可以用POLL只是你要改一下那个结构体。uart3这个结构体这个是配置串口的
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-15 14:39

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表