求助:STM32F407 用TIM4通过DMA修改GPIOE的值,修改不了

2019-07-20 19:17发布

求教大家,我用TIM4 定时器通过DMA来修改GPIOE的值,却修改不了;调试中发现DMA也启动了,因通过寄存器发现为修改TIM4 CCR1的值是能修改了,
但GPIOE->ODR或GPIOE->BSRR却没有变化,请问是什么原因?用的STM32F407,下面是我的代码:


#define TIM4_CCR1_ADDRESS  ((uint32)0x40000834) /* TIM4 CCR1 address */
#define GPIOE_ODR_ADDRESS  ((uint32)0x40021014) /*  address */

uint16 a_SRC_Buffer[4] = {0x0023, 0x0045, 0x00d3, 0x004a};
/*
**********************************************************************************************
函 数 名: TIM_GPIO_Init     TIM4  
功    能:定时器输出通道GPIO初始化  
参    数: 无
返    回: 无
**********************************************************************************************
*/
void TIM_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  DMA_InitTypeDef          DMA_InitStructure;

  /* TIM4 clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1PERIPH_TIM4, ENABLE);

  /* GPIOA clock enable */
  RCC_AHB1PeriphClockCmd(RCC_AHB1PERIPH_GPIOD | RCC_AHB1PERIPH_GPIOE, ENABLE);

  /* DMA1 clock enable */
  RCC_AHB1PeriphClockCmd(RCC_AHB1PERIPH_DMA1, ENABLE);

  /* GPIOA Configuration: PD12(TIM4 CH1) as alternate function push-pull */
  GPIO_InitStructure.GPIO_Pin = GPIO_PIN_12;
  GPIO_InitStructure.e_GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.e_GPIO_Speed = GPIO_SPEED_100MHZ;
  GPIO_InitStructure.e_GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.e_GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOD, &GPIO_InitStructure);

  /* Connect TIM pins to AF1 */
  GPIO_PinAFConfig(GPIOD, GPIO_PIN_SOURCE12, GPIO_AF_TIM4);

  /* DeInitialize the DMA1 Stream6 */
  DMA_DeInit(DMA1_Stream6);

  DMA_InitStructure.DMA_Channel = DMA_Channel_2;
  DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32)(&(GPIOE->ODR)); //&(GPIOE->BSRRL) 值没有变化
  //DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32)(TIM4_CCR1_ADDRESS); /* 可以正常修改它的值 */
  DMA_InitStructure.DMA_Memory0BaseAddr = (uint32)a_SRC_Buffer;
  DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
  DMA_InitStructure.DMA_BufferSize = 4;
  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
  DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;//DMA_Mode_Normal;
  DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
  DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable;
  DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
  DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
  DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
  DMA_Init(DMA1_Stream6, &DMA_InitStructure);
}

/*
**********************************************************************************************
函 数 名: TIM_DMA_Output_Init
功    能:定时器DMA方式输出通道初始化  
参    数: 无
返    回: 无
**********************************************************************************************
*/
void TIM_DMA_Output_Init(void)
{
  TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
  TIM_OCInitTypeDef  TIM_OCInitStructure;

  TIM_TimeBaseStructure.TIM_Period = 1000;         
  TIM_TimeBaseStructure.TIM_Prescaler = 42 - 1;      
  TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;   
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_COUNTERMODE_UP;   
  TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);

  /* TIM Configuration in PWM Mode */
  TIM_OCInitStructure.TIM_OCMode =  TIM_OCMode_Toggle;   
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;         
  TIM_OCInitStructure.TIM_Pulse = a_SRC_Buffer[0];//0xFFF;  
  TIM_OC1Init(TIM4, &TIM_OCInitStructure);

  /* TIM4 DMA Update enable */
  TIM_DMACmd(TIM4, TIM_DMA_Update, ENABLE);
       
        TIM_SelectOutputTrigger(TIM4, TIM_TRGOSource_Update);

  /* TIM4 enable */
  TIM_Cmd(TIM4, ENABLE);

  /* TIM4 PWM Outputs Enable */
//  TIM_CtrlPWMOutputs(TIM4, ENABLE);

  /* Enable DMA2 Stream5  */
  DMA_Cmd(DMA1_Stream6, ENABLE);

//  /* Wait until DMA1 Stream6 end of Transfer */
//  while (!DMA_GetFlagStatus(DMA1_Stream6, DMA_FLAG_TCIF6))
//  {
//  }
}

void TLC7524_GPIO_Init(void)
{
  GPIO_InitTypeDef  s_GPIO_InitStructure;

  /* Enable GPIOs clock */
  RCC_AHB1PeriphClockCmd(RCC_AHB1PERIPH_GPIOD | RCC_AHB1PERIPH_GPIOE, ENABLE);

  /* GPIOI configuration */
  s_GPIO_InitStructure.GPIO_Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7;
  s_GPIO_InitStructure.e_GPIO_Mode = GPIO_Mode_OUT;
  s_GPIO_InitStructure.e_GPIO_OType = GPIO_OType_PP;
  s_GPIO_InitStructure.e_GPIO_Speed = GPIO_SPEED_100MHZ;
  s_GPIO_InitStructure.e_GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOE, &s_GPIO_InitStructure);
}


友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
19条回答
正点原子
1楼-- · 2019-07-20 21:24
帮顶
steel_2006
2楼-- · 2019-07-21 00:46
自己顶一个
civic7366
3楼-- · 2019-07-21 03:39
 精彩回答 2  元偷偷看……
adlu
4楼-- · 2019-07-21 06:26
 精彩回答 2  元偷偷看……
steel_2006
5楼-- · 2019-07-21 12:14
civic7366 发表于 2016-3-15 09:11
是不是像原子教學裡面說的 DMA1不能訪問memory (聽說GPIO算memory)

我亂猜的~我現在用TIM2_UP要寫GPIOB ...

GPIO算外设吧,也有人说DMA1通过TIM驱动不能访问GPIO,但DMA2可以,你试过DMA2没?
civic7366
6楼-- · 2019-07-21 14:07
用TIM1_UP可以修改GPIO->ODR  
GPIO->ODR  算外設位址沒錯

一周热门 更多>