STM32 noob needs help with STM32H523V project

Post here first, or if you can't find a relevant section!
ag123
Posts: 1918
Joined: Thu Dec 19, 2019 5:30 am
Answers: 30

Re: STM32 noob needs help with STM32H523V project

Post by ag123 »

500 nsecs could be challenging, but nevertheless you have a H5 practically a newest chip, hence it is still worth trying.

for exti, I dug through the codes and found this:
https://github.com/stm32duino/Arduino_C ... terrupts.h
https://github.com/stm32duino/Arduino_C ... rrupts.cpp

so I'd guess the codes may be like

Code: Select all

callback_function_t callback() {
	//my ISR code here
}

void setup() {
	attachInterrupt(PAxx, callback, RISING);
}
and there is no need to hack the 'low level' interrupt vectors etc ;)
and as usual, keep the codes in your callback lean as is possible those gets in the way of interrupt handing throughput.
stm32 f4, g4 and h5 has that 'ART accelerator' on chip cache, so maybe it'd make a difference after all.
the theory goes that if your codes (maybe say ISR as well) is in the cache, ART accelerator can make that going from like 4-8 wait states to *zero* wait states, so if the bus is 250 Mhz, then 500 nsecs seemed 'extremely easy'
if this is feasible, it opens the door to a lot of things, e.g. it becomes possible to do usb full speed 12 Mhz in *software*, doing NRZI, bit stuffing, CRC, PID, clock recovery, full blown usb protocol handling everything in *software* - use case usb protocol sniffer.
this feat is deemed 'impossible' on simple mcus, traditionally deemed a USB "serial interface engine"
https://www.usb.org/sites/default/files/siewp.pdf
if one can do this whole thing in codes, it changes the game

there is 'another way', is to use Timer and DMA to read the ports, that can go quite fast into the Mhz ranges, but that this is not ISR, it is just reading data from ports verbatim.
ozcar
Posts: 186
Joined: Wed Apr 29, 2020 9:07 pm
Answers: 5

Re: STM32 noob needs help with STM32H523V project

Post by ozcar »

From what I have seen on other processors, 500ns would be very "ambitious" using attachInterrupt(). I did a quick test now using that on H503, and the time from the interrupt until the ISR was entered varied a bit depending on the optimisation selected, but I could not even get it down to 1μs. So, unless you can invent some magic way to execute your ISR in negative time, you might be out of luck with that.

I did not have a chance to see what it looks like if I cut out the stm32duino code and go directly into my ISR. BTW the code ag123 pointed you to shows the #define you need so that stm32duino core does not define the ISRs, it is HAL_EXTI_MODULE_DISABLED.
ozcar
Posts: 186
Joined: Wed Apr 29, 2020 9:07 pm
Answers: 5

Re: STM32 noob needs help with STM32H523V project

Post by ozcar »

I got to do another test to see what sort of delay you would get going directly into your ISR instead of going via the attachInterrupt callback. To do this all I did was set a GPIO pin high in the stm32duino ISR, and with my attachInterrutp callback still in place, set the same GPIO pin low again.

So this is what I got (on H503, 250MHz):

DS1Z_QuickPrint3.png
DS1Z_QuickPrint3.png (35.93 KiB) Viewed 251 times

The top trace is the pin the interrupt was set on ("RISING"), and the lower trace is the GPIO set high first thing in the actual ISR, and low first thing in my callback. From that the ISR was entered around 160ns after the interrupt pin went high, so there might be some hope for you.

Actually, from that you can see from when the bottom trace goes low, that my callback was entered just under 800ns after the rising edge on the interrupt pin, which is less than I saw in my first test. The reason for that is that I changed from using digitalWriteFast() for flipping the diagnostic GPIO pin, to using GPIOB->BSRR = GPIO_BSRR_BS8 and GPIOB->BSRR = GPIO_BSRR_BR8. I didn't look to see what digitalWriteFast() does, but it looks like at this level it does not take much to make or break things.

Good luck.
memotronics
Posts: 5
Joined: Fri Jun 27, 2025 8:07 pm

Re: STM32 noob needs help with STM32H523V project

Post by memotronics »

ozcar wrote: Tue Jul 08, 2025 10:03 pm I got to do another test to see what sort of delay you would get going directly into your ISR instead of going via the attachInterrupt callback. To do this all I did was set a GPIO pin high in the stm32duino ISR, and with my attachInterrutp callback still in place, set the same GPIO pin low again.

So this is what I got (on H503, 250MHz)...
I want to make sure I understand this: The directly-invoked ISR fired after roughly 160ns, and the attach-interrupt-invoked ISR fired after 800ns?

And while I'm at it, I really want to thank everyone for their help. I just wish my stinking 100-pin socket wasn't stuck in customs so I could get started for real :(
ozcar
Posts: 186
Joined: Wed Apr 29, 2020 9:07 pm
Answers: 5

Re: STM32 noob needs help with STM32H523V project

Post by ozcar »

memotronics wrote: Sat Jul 12, 2025 1:12 am
I want to make sure I understand this: The directly-invoked ISR fired after roughly 160ns, and the attach-interrupt-invoked ISR fired after 800ns?
Yes, that is about it, the stm32duino-provided ISR (EXTI8_IRQHandler() for the pin I was using) got control after 160ns, and my attachInterrupt routine after 7??ns. What it does to account for the say 600ns difference, I don't know. Well, it has to be HAL_GPIO_EXTI_IRQHandler() processing, as that is all that EXTI8_IRQHandler() does, but I did not delve into the HAL code.

BTW, the fall of the interrupt line (top trace) would be a rough indication of the time for the interrupt to complete (so, including the "tail end"). That is because the test signal, if you want to call it that, was generated by the mainline code (two GPIOs tied together), and that was set low again when the mainline got control back after the interrupt processing.
Post Reply

Return to “General discussion”