AnsweredAssumed Answered

STM32F407 GPIO not toggles on 168MHz SysClk

Question asked by STM32user on Oct 16, 2015
Latest reply on Oct 19, 2015 by STM32user
Good day,

I use CooCox 1.7.8 and STM32F4DISCOVERY as programmator.
Problem is, that after re-configuring SysClk to PLL running on 168MHz
(which is confirmed through observing 84MHz on MCO1 output) ToggleBit
command produce no effect on LED's. If decrease SysClk to 42MHz, everything is working.

Please see code below:

#include "stm32f4xx.h"  

#include "stm32f4xx_gpio.h" </p>



#include  "stm32f4xx_rcc.h"

GPIO_InitTypeDef GPIO_InitStruct;


int i, k=0, l=0; </p>



int main(void)


 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);

 GPIO_InitStruct.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_10; // we want to configure LED's: D1, D3
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT; // we want it to be an Output

GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz; //this sets the GPIO modules clock speed

GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; // this sets the pin type to push / pull (as opposed to open drain)

 GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL; // this disables the pull-down resistor

 GPIO_Init(GPIOE, &GPIO_InitStruct);


 GPIO_SetBits(GPIOE, GPIO_Pin_8|GPIO_Pin_10);

// LED1, LED3 On

 for (i=0; i<50000; i++); //Wait

 GPIO_ResetBits(GPIOE, GPIO_Pin_8|GPIO_Pin_10); // LED1, LED3 Off

 /* Output HSE clock on MCO1 pin(PA8) ****************************************/

 /* Enable the GPIOA peripheral */

 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

 /* Configure MCO1 pin(PA8) in alternate function */

 GPIO_InitStruct.GPIO_Pin = GPIO_Pin_8;

 GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz;

 GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;

 GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;

 GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;

 GPIO_Init(GPIOA, &GPIO_InitStruct);

  /* (PLL_clock/2) selected to output on MCO1 pin (PA8)*/

 RCC_MCO1Config(RCC_MCO1Source_PLLCLK, RCC_MCO1Div_2);



RCC_PLLConfig(RCC_PLLSource_HSI, 0x08, 0xA8, 0x02, 0x07);

//PLLM=8 (2MHz), PLLN=168 (336MHz), PLLP=2 (SYS=168), PLLQ=7 (USB=48)

 RCC_PLLCmd(ENABLE); //Enable PLL using HSI

 while(!RCC_GetFlagStatus(RCC_FLAG_PLLRDY)); //Wait till PLL frequency established (23)



//Choose PLL as SYSCLK

 for (i=0; i<16800; i++); //Wait



GPIO_ToggleBits(GPIOE, GPIO_Pin_8|GPIO_Pin_10);

// LED1, LED3 On

 for (i=0; i<1680; i++); //Wait

 GPIO_ToggleBits(GPIOE, GPIO_Pin_8|GPIO_Pin_10);


// LED1, LED3 On

 for (i=0; i<1680; i++); //Wait




As well, under debugger last while(1) reach its end successfully
(using breakpoints) but after it hangs.

Thanks in advance,