2013-12-03 11:30 AM
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-ever2013-12-03 11:52 AM
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.
2013-12-03 11:37 PM
> Consider also using a timer.
> Consider also using a timer.
... or an MCO pin driven from some of the high-speed internal clocks. JW2013-12-04 08:38 AM
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.2013-12-05 03:18 AM
2013-12-05 04:05 AM
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?