cancel
Showing results for 
Search instead for 
Did you mean: 

Newbe here: STM32F407 - how fast an interrupt can be and how fast can I read/write GPIO register

MedusaTT040
Visitor

I am new with the STM32 MCU and this is my first project

I am using a STM32F407VGT6
I started a project that read a 16bit parallel on PDx GPIO. The data is placed by an external device and a signal is set to low for 400ns. I connected that signal on PB1 and enable an interrupt on it.

The code inside the interrupt:
1 - set output pin PC9 to 0
2 - read the GPIOD (al 16 bit)
3 - shift once (divide by 2)
4 - output the result into the MCU DAC.
5 - set output pin PC9 to 0

I use PC9 on an oscilloscope to see how much each line of code is taking.
And I am very surprised by how slow the code is running at.

First, it take 6us for the interruption to be triggered
Then 3us to read PDx registry
1us to shift 
4us to output to DAC

I was hopping the interrupt would be much faster. At least to read the PDx registry within the 400ns. 400s is the time I have to read the GPIO. This is how long the data stay on the 16 bus.
To get me going, I used 2 latching buffers  74LS374 in order to give me more time. But I was hopping the STM32 would be fast enough to read within the 400ns or even faster.

Am I missing something?
I did not start using the DMA. Would that help?


My second project was to emulate a ROM and be able to read the bus, fetch a 8 bit data from RAM and output it to another GPIO port. All within 200ns. But it seems I will not be able to do that. ether.

I attached the code of my interrupt and the timings I get.

Many thanks for your help.

 

 

4 REPLIES 4

Few Hundred KHz, definitely less than.a MHz, for interrupts.

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

It will be much faster if you implement the EXTI handlers themselves (e.g. EXTI0_IRQHandler) rather than using the HAL callbacks. 12 cycles to enter the ISR, then look at disassembly to see how many cycles it takes to get through your code.

If you feel a post has answered your question, please click "Accept as Solution".
AScha.3
Chief III

You didnt state the cpu clock you have...

At 168MHz , max for F407 , going to an INT will need about 80ns . (12 x 6ns + some clocks for sync )

If you want to see/check the speed, at first check the cpu speed, you set.

Then use optimizer -O2 setting , or -Ofast .

And use only direct write to registers , port or DAC, not the HAL calls.

And not call next level of functions (callback) in INT, that adds all the time for a subroutine calling+return.

And dont expect wonders....its still a cpu, that saves+ restores all registers in a INT or function call, so some time will be needed.

If you feel a post has answered your question, please click "Accept as Solution".

ah, I did not notice I left the clock settings to default. the CPU was at 16Mhz !
Now at 168Mhz, I see a big improvement. the whole code runs in 1.5us from the signal going down.

I read the GPIOD register this way:
DAC_out = (uint16_t)GPIOD->IDR;   

 

Thank you very much