新手上路
- 积分
- 22
- 金钱
- 22
- 注册时间
- 2018-1-21
- 在线时间
- 3 小时
|
1金钱
程序是想当我用电脑通过串口向板子任意发送一个数据时,板子会向电脑回复分别用CPU和DMA搬运同一组数据所花费的时间,可是当我用串口调试助手向板子发信息时却不会接到任何回复,麻烦大佬看看我的程序哪有问题,谢谢了
使用的是3.5版的库函数
代码如下
main.c
[mw_shl_code=c,true]#include"stm32f10x.h"
#include"stdio.h"
#include"string.h"
#define BufferSize 32
vu16 CurrDataCounter = 0;
vu32 Tick = 0;
uc32 SRC_Const_Buffer[BufferSize] =
{
0x01020304, 0x05060708, 0x090a0b0c, 0x0d0e0f10,
0x11121314, 0x15161718, 0x191a1b1c, 0x1d1e1f20,
0x01020304, 0x05060708, 0x090a0b0c, 0x0d0e0f10,
0x11121314, 0x15161718, 0x191a1b1c, 0x1d1e1f20,
0x01020304, 0x05060708, 0x090a0b0c, 0x0d0e0f10,
0x11121314, 0x15161718, 0x191a1b1c, 0x1d1e1f20,
0x01020304, 0x05060708, 0x090a0b0c, 0x0d0e0f10,
0x11121314, 0x15161718, 0x191a1b1c, 0x1d1e1f20,
};
u32 DST_Buffer[BufferSize];
void RCC_Configuration(void);
void NVIC_Configuration(void);
void GPIO_Configuration(void);
void USART_Configuration(void);
void DMA_Configuration(void);
void SysTick_Configuration(void);
int main(void)
{
u8 i = 0;
u8 TickCntCPU = 0;
u8 TickCntDMA = 0;
RCC_Configuration();
NVIC_Configuration();
GPIO_Configuration();
USART_Configuration();
DMA_Configuration();
SysTick_Configuration();
Tick = 0;
for(i = 0; i < BufferSize; i ++)
{
DST_Buffer = SRC_Const_Buffer;
}
TickCntCPU = Tick;
for(i = 0; i < BufferSize; i ++)
{
DST_Buffer = 0;
}
Tick = 0;
DMA_Cmd(DMA1_Channel6, ENABLE);
while(CurrDataCounter != 0);
TickCntDMA = Tick;
if(USART_GetFlagStatus(USART1, USART_IT_RXNE) == SET)
{
USART_ClearFlag(USART1,USART_FLAG_RXNE);
if(strncmp((const char*)SRC_Const_Buffer, (const char*)DST_Buffer, BufferSize) == 0)
{
printf("\r\nTransmit Success! \r\n");
}
else
{
printf("\r\nTransmit Fault! \r\n");
}
printf("\t\nThe CPU transfer, time consume: %dus! \n\r", TickCntCPU);
printf("\t\nThe DMA transfer, time consume: %dus! \n\r", TickCntDMA);
}
while(1);
}
void RCC_Configuration()
{
ErrorStatus HSEStartUpStatus;
RCC_DeInit();
RCC_HSEConfig(RCC_HSE_ON);
HSEStartUpStatus = RCC_WaitForHSEStartUp();
if(HSEStartUpStatus == SUCCESS)
{
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_PCLK2Config(RCC_HCLK_Div1);
RCC_PCLK1Config(RCC_HCLK_Div2);
FLASH_SetLatency(FLASH_Latency_2);
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
RCC_PLLCmd(ENABLE);
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
while(RCC_GetSYSCLKSource() != 0x08);
}
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
#ifdef VECT_TAB_RAM
NVIC_SetVectorTable(NVIC_VectTab_RAM , 0x0);
#else
NVIC_SetVectorTable(NVIC_VectTab_FLASH , 0x0);
#endif
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel6_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void DMA_Configuration(void)
{
DMA_InitTypeDef DMA_InitStructure;
DMA_DeInit(DMA1_Channel6);
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)SRC_Const_Buffer;
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)DST_Buffer;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = BufferSize;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Enable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Enable;
DMA_Init(DMA1_Channel6 , &DMA_InitStructure);
DMA_ITConfig(DMA1_Channel6, DMA_IT_TC, ENABLE);
CurrDataCounter = DMA_GetCurrDataCounter(DMA1_Channel6);
}
void SysTick_Configuration(void)
{
SysTick_Config(9);
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);
}
void USART_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
USART_ClockInitTypeDef USART_ClockInitStructure;
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_ClockInit(USART1, &USART_ClockInitStructure);
USART_InitStructure.USART_BaudRate = 9600;
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_Init(USART1, &USART_InitStructure);
USART_Cmd(USART1, ENABLE);
}
int fputc(int ch, FILE * f)
{
USART_SendData(USART1, (u8)ch);
while(USART_GetFlagStatus(USART1,USART_FLAG_TC) == RESET);
return ch;
}
[/mw_shl_code]
stm32f10x_it.c
[mw_shl_code=c,true]
#include "stm32f10x_it.h"
extern vu16 CurrDataCounter;
extern vu32 Tick;
void SysTick_Handler(void)
{
Tick ++;
}
void DMA1_Channel6_IRQHandler(void)
{
CurrDataCounter = DMA_GetCurrDataCounter(DMA1_Channel6);
DMA_ClearITPendingBit(DMA1_IT_GL6);
}
[/mw_shl_code]
|
|