cancel
Showing results for 
Search instead for 
Did you mean: 

High frequency GPIO

pentruminister
Associate II
Posted on December 03, 2013 at 20:30

Hello, i'm using STM32F4 Discovery board. I need a GPIO pin oscillating as fast as possible.

With the code bellow I get just 3 Mhz (measured with digital probe), but I suppose there are ways to get it to much higher frequencies. Please advice !!!!

  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);

  uint16_t pin = GPIO_Pin_7;

  GPIO_InitStructure.GPIO_Pin = pin;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;

  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

  GPIO_Init(GPIOD, &GPIO_InitStructure);

  while (1)

  {

    GPIO_SetBits(GPIOD, pin);

    GPIO_ResetBits(GPIOD, pin);

    

  }

#worst-forum-software-ever
5 REPLIES 5
Posted on December 03, 2013 at 20:52

Going to depend on how fast you are running the part, the code used, and how effective the compiler is.

You'd perhaps want to try writing to the register directly than calling a subroutine to do it.

while(1)
{
GPIOD->BSRRL = GPIO_Pin_7; // Set
GPIOD->BSRRH = GPIO_Pin_7; // ReSet
GPIOD->BSRRL = GPIO_Pin_7; // Set
GPIOD->BSRRH = GPIO_Pin_7; // ReSet
GPIOD->BSRRL = GPIO_Pin_7; // Set
GPIOD->BSRRH = GPIO_Pin_7; // ReSet
GPIOD->BSRRL = GPIO_Pin_7; // Set
GPIOD->BSRRH = GPIO_Pin_7; // ReSet
}

Consider also using a timer.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on December 04, 2013 at 08:37

> Consider also using a timer.

> Consider also using a timer.

... or an MCO pin driven from some of the high-speed internal clocks.

JW
Posted on December 04, 2013 at 17:38

Depends a lot on what higher frequency we're talking about, and what it's expects to drive. The faster you go the less control/adjustment you are going to be able to effect. The prescalers/dividers are all integer.

MCO1 you're perhaps looking at up to 84 or 90 MHz depending on which F4 part you are using.

MCO2 can use the I2S PLL which certainly provides for some more interesting opportunities.

The pin Speed setting is more related to how aggressively the pin is driven, but you'll also need to evaluate the traces and loading.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
pentruminister
Associate II
Posted on December 05, 2013 at 12:18

Many thanks !!!! With Clive's code, it reached a frequency between 6 and 8 Mhz (digital probe only goes so far).

Posted on December 05, 2013 at 13:05

What speed are you running the processor? Right now you look to be running it off the internal HSI clock, not at 168 MHz via the PLL. You'll want to examine system_stm32f4xx.c and SystemInit(), and confirm it's being called by your start up code.

What tool chain are you using?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..