STM32 noob needs help with STM32H523V project

Post here first, or if you can't find a relevant section!
ag123
Posts: 1928
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: 187
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: 187
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 2544 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: 8
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: 187
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.
memotronics
Posts: 8
Joined: Fri Jun 27, 2025 8:07 pm

Re: STM32 noob needs help with STM32H523V project

Post by memotronics »

OK, I was getting similar results. With ICACHE turned on, I was getting about 120ns from the rising edge of my input signal until the output started rising. That's bypassing the HAL for the interrupt code.

Unfortunately, the test-socket I purchased on AliExpress was a piece of junk (yes, I should have known), I then soldered the MCU onto a QFP100-to-DIP adapter and managed to have the IC turned 90 degrees, and ripped it to shreds trying to desolder. So now I'm waiting on a replacment. VERY UNPRODUCTIVE AFTERNOON...
ag123
Posts: 1928
Joined: Thu Dec 19, 2019 5:30 am
Answers: 30

Re: STM32 noob needs help with STM32H523V project

Post by ag123 »

well you may want to consider buying a ready made board

e,g
https://weactstudio.aliexpress.com/
https://www.olimex.com/
etc

if one search in the online 'flea markets' (e.g. Aliexpress) there could be more offers from other than weactstudio.

then that of course there are the Nucleos and Discovery boards from ST
and for various of those boards, they may 'just works' in the core:
https://github.com/stm32duino/Arduino_Core_STM32
ag123
Posts: 1928
Joined: Thu Dec 19, 2019 5:30 am
Answers: 30

Re: STM32 noob needs help with STM32H523V project

Post by ag123 »

on a different note I'm not sure what to do about the 'interrupt latency' issue.

I've been wanting to observe usb (full speed) signals, that'd cost a good oscilloscope
or that maybe I can improve on my little logic analyzer.
viewtopic.php?t=116

using a timer driving DMA which seem to max out at like 5 MBps (more correctlty 5 M (less than 10M) samples per sec, sampling like all 8 pins or 16 piins at one go. one way I'm thinking of is that rather than using timer driving DMA directly, is to use SPI which can go to like 50 M samples per sec but only a single pin.

The trouble is usb signals travels fast on the bus, and on chip sram won't have enough to buffer that much data.
Hence, I may after all still need EXTI and trigger say on a falling edge, then that enables SPI so that DMA would capture a buffer of data.
very idealistic.

the thing is that at 12 Mhz USB sync field
https://www.beyondlogic.org/usbnutshell/usb3.shtml
should normally be 0b0000011, then in NRZI it should read 01010100
the thing is even if EXTI fires and I sttart the SPI and hence DMA, it could be well past the first few of the 0101
at 12 Mhz 1 bit is just 83 nsecs.
the round trip between EXTI firing, ISR running, then my code toggles SPI (enable) that sync byte may be well over or at least half way through it.

in a certain way, I think this may still allow observing (some) usb full speed 12 Mhz signals.
e.g. if I make do with the 'corrupted' sync byte, i'm thinking of 'count backwards'
from the EOP (which is an 'single ended zero' i.e. both d+ / d- low)
i can perhaps work the CRC, endpoint, address, and PID byte out
but that still requires detecting the EOP reliably.
i've been looking at usb1T11a
https://www.onsemi.com/products/interfa ... s/usb1t11a
but I think it still won't be easy no matter how.
Post Reply

Return to “General discussion”