cancel
Showing results for 
Search instead for 
Did you mean: 

Change the speed of GPIO

ali2003a
Associate II
Posted on March 06, 2014 at 12:41

Hi there,

I want to change the speed of GPIO for STM32f4 discovery board. The maximun speed I can get on specified pin is 6 MHz and I want to get 20 Mhz. we know that the discovery board has external clock circuit to operate at high speed. I do not know what to do to get higher speed. By the way I am using Keil (uvision) software.

 

Thanks for any help
6 REPLIES 6
Posted on March 06, 2014 at 14:02

The way you've framed the question I'm going to assume you are trying to toggle the pin manually. Apparently poorly in C, in assembler I'm pretty sure we can push 84 MHz.

BUT, don't do that, if you want to drive pins at high frequencies, don't use interrupts, but use TIM peripherals. Higher frequencies might still be a problem as they must be integer multiples of the source clock, so you might need to alter the CPU speed to suit, or use other PLLs.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ali2003a
Associate II
Posted on March 06, 2014 at 14:23

Thanks for replay.

What I can understand that I can't change the speed of the GPIO lines of port a, b,  c, or f !

Posted on March 06, 2014 at 14:35

> What I can understand that I can't change the speed of the GPIO lines of port a, b,  c, or f !

What do you mean by ''change speed of gpio''? Please explain.

JW

ali2003a
Associate II
Posted on March 06, 2014 at 15:39

Let’s take example to illustrate what I mean from my question. Suppose I am configuring port A to be an output and then I set and reset the specified pin of port a high and low. The maximum frequency I got is 6MHz

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2 ;            // we want to configure pin 1&2

            GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;                                                           // we want these to be outputs

            GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;                                                           // pushpull

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;                         // clock speed

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;                 // these configure without pullup or down resistor connection

 

GPIO_Init(GPIOA, &GPIO_InitStructure);

// Generate pattren to measure the frequency at pin 2 of port a

GPIO_SetBits(GPIOA, GPIO_Pin_2);

             GPIO_ResetBits(GPIOA, GPIO_Pin_2);

             GPIO_SetBits(GPIOA, GPIO_Pin_2);

             GPIO_ResetBits(GPIOA, GPIO_Pin_2);

The below link shows the output frequency due set and reset command from the above code

http://tinypic.com/r/eg63qe/8

Posted on March 06, 2014 at 15:43

1. Avoid the ''library functions''. Write directly to the registers. For example:

GPIOA->BSRRL = 1 << 2;

GPIOA->BSRRH = 1 << 2;

2. Re-read Clive's answer very carefully.

JW

ali2003a
Associate II
Posted on March 07, 2014 at 10:52

Thanks for your help. It works and I am able to get 40 MHz which is the required.