刚刚开始学习使用STM32,针对207的芯片,发现有诸多问题不得其解,特发贴请教。
程序很简单,打算利用DMA方式将内存数据通过GPIO端口传递出去,想测试一下传递速度,下面附上程序代码:
int main(void)
{
RCC_ClocksTypeDef RCC_Clocks;
SystemInit();
/* SysTick end of count event each 10ms */
RCC_GetClocksFreq(&RCC_Clocks);
SysTick_Config(RCC_Clocks.HCLK_Frequency / 100);
NVIC_SetVectorTable(NVIC_VectTab_FLASH,0x00);
// NVIC_SetVectorTable(NVIC_VectTab_RAM,0x00);
NVIC_Configuration();// NVIC configuration
GPIO_Init_Configuration();
/* Initialize LEDs and LCD available on STM322xG-EVAL board *****************/
STM_EVAL_LEDInit(LED2);
STM_EVAL_LEDInit(LED3);
STM_EVAL_LEDInit(LED4);
/* Turn on LEDs available on STM322xG-EVAL **********************************/
STM_EVAL_LEDOn(LED2);
/* Add your application code here
*/
SDCard_Control();
/* Infinite loop */
while (1)
{
/* Toggle LD4 */
STM_EVAL_LEDToggle(LED3);
/* Insert 50 ms delay */
Delay(5);
/* Toggle LD2 */
STM_EVAL_LEDToggle(LED2);
/* Insert 50 ms delay */
Delay(5);
}
}
void SDCard_Control(void)
{
uint32_t count=0;
uint32_t DMA_buffer[32];
for(count=0;count<32;count++)
DMA_buffer[count] = count+0x55;
DMA_Config();
}
void DMA_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
__IO uint32_t Timeout = TIMEOUT_MAX;
/* Enable DMA clock */
RCC_AHB1PeriphClockCmd(GPIOB_DMA_CLOCK, ENABLE);
/* Reset DMA Stream registers (for debug purpose) */
DMA_DeInit(GPIOB_DMA_STREAM);
/* Check if the DMA Stream is disabled before enabling it.
Note that this step is useful when the same Stream is used multiple times:
enabled, then disabled then re-enabled... In this case, the DMA Stream disable
will be effective only at the end of the ongoing data transfer and it will
not be possible to re-configure it before making sure that the Enable bit
has been cleared by hardware. If the Stream is used only once, this step might
be bypassed. */
while (DMA_GetCmdStatus(GPIOB_DMA_STREAM) != DISABLE)
{
}
/* Configure DMA Stream */
DMA_InitStructure.DMA_Channel = GPIOB_DMA_CHANNEL;
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)GPIOB_DMA_ADDRESS;
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)DMA_buffer;
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
DMA_InitStructure.DMA_BufferSize = 0xFFFF;
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_FIFOMode = DMA_FIFOMode_Disable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(GPIOB_DMA_STREAM, &DMA_InitStructure);
/* Enable DMA Stream Transfer Complete interrupt */
// DMA_ITConfig(GPIOB_DMA_STREAM, GPIOB_DMA_TCIF, ENABLE);
/* DMA Stream enable */
DMA_Cmd(GPIOB_DMA_STREAM, ENABLE);
/* Check if the DMA Stream has been effectively enabled.
The DMA Stream Enable bit is cleared immediately by hardware if there is an
error in the configuration parameters and the transfer is no started (ie. when
wrong FIFO threshold is configured ...) */
Timeout = TIMEOUT_MAX;
while ((DMA_GetCmdStatus(GPIOB_DMA_STREAM) != ENABLE) && (Timeout-- > 0))
{
}
/* Check if a timeout condition occurred */
if (Timeout == 0)
{
/* Manage the error: to simplify the code enter an infinite loop */
while (1)
{
}
}
/* Enable the DMA Stream IRQ Channel */
/*
NVIC_InitStructure.NVIC_IRQChannel = GPIOB_DMA_IRQ;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
*/
Timeout = TIMEOUT_MAX;
while((DMA_GetFlagStatus(GPIOB_DMA_STREAM, GPIOB_DMA_TCIF) != RESET) && (Timeout-- > 0))
{
}
DMA_DeInit(GPIOB_DMA_STREAM);
} |