cancel
Showing results for 
Search instead for 
Did you mean: 

Best way to generate a fast square wave on PD2

Chris Rice
Associate III
Posted on May 31, 2018 at 22:48

Hello, first of all pardon my ignorance, I'm a little new to STM32 development.  We are working on a project on an STM32F769, and my EE has asked me to generate a fairly fast (20mhz) clock output on a specific pin (PD2).  None of the 'alternate functions'  of this pin relate to a timer (e.g., some examples route a PWM out of a certain GPIO via alternate function), so I think that means I need to handle an interrupt and toggle the output, right?  Or is there another way to route a signal out a specific GPIO via hardware?

If/when i handle it in software (handle the timer interrupt and toggle the output), it's so fast that I'm afraid I'm going to load my CPU.  Are there any best practices out there to avoid this?  

Thanks for any advice.

#gpio #timers #stm32f7
5 REPLIES 5
Posted on May 31, 2018 at 22:55

20 MHz is too high for interrupts. What is the purpose of doing this? Is it required in the final application or just to test something? Or work through a design issue while you respin the board properly?

I'd probably use TIM+DMA+GPIO to bang a pattern &GPIOD->BSRR (0x00000004, 0x00040000, repeating)

Could you just find 20 MHz some place else and use wire?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Chris Rice
Associate III
Posted on May 31, 2018 at 23:00

The plan is to eliminate the need for this in final, but he is not 100% confident it can be eliminated.

So that would be, configure a DMA stream to write from memory to peripheral, iterate between two patterns in memory written to the output register?   That's ingenious... however wouldn't it also write to all other pins on the same port?  Pretty sure we couldn't have that, we are very tight on GPIO.

Chris Rice
Associate III
Posted on May 31, 2018 at 23:23

Ok I lit a fire.   Got him to switch to PA2 (with a slight mod), which has an alternate function for TIM2_CH3.  Thanks so much Clive One.

Posted on May 31, 2018 at 23:03

BSRR is Bit Set Reset Register, not the ODR, you can direct the signal to a single bit with a 32-bit wide pattern, the DMA is circular and thus repeating.

>>That's ingenious...

I'm an EE that does CS

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on May 31, 2018 at 23:07

>>The plan is to eliminate the need for this in final, but he is not 100% confident it can be eliminated.

I'd light a fire to make sure it got fixed. Heck use a 20 MHz HSE and push out of PA8, or a small 20 MHz XO and share output.

What's special about PD2? Find an LED you're driving with a GPIO/TIM pin and redeploy it

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