cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407 GPIO not toggles on 168MHz SysClk

kvg
Associate II
Posted on October 16, 2015 at 11:31

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>

 

</b>

#include  ''stm32f4xx_rcc.h''

GPIO_InitTypeDef 

GPIO_InitStruct;  

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

 

</b>

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)  RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

 

//Choose PLL as SYSCLK

 

for

(i=0; i<16800; i++);

//Wait

 

while

(1)

 {

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,

 

Konstantin
5 REPLIES 5
Posted on October 16, 2015 at 12:01

Observe the LED pin with oscilloscope.

JW
kvg
Associate II
Posted on October 16, 2015 at 15:05

Posted on October 16, 2015 at 16:06

Do you have the FLASH latency set properly?

JW
Posted on October 16, 2015 at 17:19

As Jan indicates there is the flash wait state setting, but also where the AHB/APB clocks are set, and enable the High Performance Power mode.

CooCox has this broken interpretation of the CMSIS requirement to call SystemInit() to set up the clocks prior to setting the C Environment up and calling main()
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
kvg
Associate II
Posted on October 19, 2015 at 12:50

Thanks everyone.

FLASH->

ACR

|= FLASH_ACR_LATENCY_5WS;

 solves problem.!!.

BR.

K.

As Jan indicates there is the flash wait state setting, but also where the AHB/APB clocks are set, and enable the High Performance Power mode.

CooCox has this broken interpretation of the CMSIS requirement to call SystemInit() to set up the clocks prior to setting the C Environment up and calling main()