野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 26354|回复: 0

求指教:DMA外设到存储没有返回值

[复制链接]
发表于 2020-11-13 11:16:15 | 显示全部楼层 |阅读模式
===代码如下:
#include "stm32f10x.h"
#include <stdio.h>
#include <string.h>




//PC2 LED1
//PC3 LED2
//PA0 KEY1
//PA9 UART_TX
//PA10 UART_RX


void USART1_Configuration(void);
void RCC_Configuration(void);
void GPIO_Configuration(void);
int fputc(int ch, FILE *f);
void DMA_Configuration(void);






uint8_t SrcBuf[12] = "xxxxxxxxxxx";




//UART重定向
int fputc(int ch, FILE *f)
{
    if (ch == '\n')
    {
        while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);


        USART_SendData(USART1, '\r');
    }


    while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);


    USART_SendData(USART1, ch);
    return ch;
}






void RCC_Configuration(void)
{
    SystemInit();
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
}




//
void GPIO_Configuration(void)
{
    GPIO_InitTypeDef GPIO_Stucturue;
    GPIO_StructInit(&GPIO_Stucturue);               //
    GPIO_Stucturue.GPIO_Pin = GPIO_Pin_9;           //usart1 TX
    GPIO_Stucturue.GPIO_Mode = GPIO_Mode_AF_PP;     //复用推挽输出
    GPIO_Init(GPIOA, &GPIO_Stucturue);
    GPIO_Stucturue.GPIO_Pin = GPIO_Pin_10;   //RX
    GPIO_Stucturue.GPIO_Mode = GPIO_Mode_IN_FLOATING; //浮空输入//复用开漏输入
    GPIO_Init(GPIOA, &GPIO_Stucturue);
}




void USART1_Configuration(void)
{
    USART_InitTypeDef USART_InitStructure;
    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_Tx;
    USART_Init(USART1, &USART_InitStructure);
    USART_Cmd(USART1, ENABLE);
}


void DMA_Configuration(void)
{
    DMA_InitTypeDef DMA_InitStructure;
    DMA_DeInit(DMA1_Channel5);
    DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&USART1->DR;//DR地址,
    DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)SrcBuf;//数组名即为数组首地址
    DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;//从外设读取数据
    DMA_InitStructure.DMA_BufferSize = 11;
    DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
    DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
    DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
    DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
    DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
    DMA_InitStructure.DMA_Priority = DMA_Priority_High;
    DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;//存储器到存储器ENABLE,存储器到外设DISABLE
    DMA_Init(DMA1_Channel5, &DMA_InitStructure);
}




int main()
{
    uint8_t flag = 1;
    RCC_Configuration();
    GPIO_Configuration();
    USART1_Configuration();
    //存储器到存储器DMA
    DMA_Configuration();
    //发送第一位数据之前,先清除TC标志,否则容易造成第一位发送不出去
    USART_ClearFlag(USART1, USART_FLAG_TC);
    USART_DMACmd(USART1, USART_DMAReq_Rx, ENABLE);
    DMA_Cmd(DMA1_Channel5, ENABLE);
    printf("hello\n");


    while (flag)
    {
        if (strstr(SrcBuf, "LED")) //uint8_t SrcBuf[12] = "xxxxxxxxxxx";
    {
        printf(SrcBuf);
            flag = 0;
        }
        printf("NO");
        flag = 0;
    }
}
===串口调试助手发送LED+回车,无返回值;
野火论坛202011131115141904..png
===求大哥们帮忙分析一下;小弟不才,在此谢过


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-11-25 04:49 , Processed in 0.030169 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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