Hi,
I have custom SPI slave device (CPLD) which notifies me about new data through external interrupt. The problem is that I have very limited time interval to react and begin the transfer (about 5us).
I tried to resume suspended thread from external interrupt callback (EXT driver) as shown in the following example. But It takes at least 10us (with -O2 and no OS debug for 24MHz stm32l152xx MCU). Am I doing something wrong? Is there any way to reduce this thread wake up latency?
Thread wake up from IRQ latency
Moderators: RoccoMarco, lbednarz, tfAteba
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: Thread wake up from IRQ latency
Hi,
How do you measure it? 10uS is a lot, probably it is caused by the low clock frequency. Suspend/resume is about the fastest method.
How are you measuning? using a GPIO? if so try measuring various points:
- ISR trigger.
- Where resume is called.
- Where the thread exits from suspend.
This way we can see where time is lost.
Anyway possible solutions are:
- Increase clock frequency.
- Use -O3 for critical parts.
- Execute critical code from ISR and then resume the thread.
- Use the "simplified priority handling" option, see chcore_v7m.h file. This makes kernel a bit faster.
- Disable unused features in chconf.h, this also can speed up some kernel operations.
Giovanni
How do you measure it? 10uS is a lot, probably it is caused by the low clock frequency. Suspend/resume is about the fastest method.
How are you measuning? using a GPIO? if so try measuring various points:
- ISR trigger.
- Where resume is called.
- Where the thread exits from suspend.
This way we can see where time is lost.
Anyway possible solutions are:
- Increase clock frequency.
- Use -O3 for critical parts.
- Execute critical code from ISR and then resume the thread.
- Use the "simplified priority handling" option, see chcore_v7m.h file. This makes kernel a bit faster.
- Disable unused features in chconf.h, this also can speed up some kernel operations.
Giovanni
Re: Thread wake up from IRQ latency
Yes, I am measuring using a GPIO with a logic analyzer. I cannot use clock frequency other than 24MHz because it will screw up MCO frequency.
So, assuming the TX notifier pin up as zero time starting point
So, assuming the TX notifier pin up as zero time starting point
- tx notifier up - 0us
IRQ beginning - 2.7
IRQ after calling resume - 4.5
thread wake up - 10
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: Thread wake up from IRQ latency
Hi,
You could use the MCO divider and up frequency up to 32MHz.
Giovanni
You could use the MCO divider and up frequency up to 32MHz.
Giovanni
Re: Thread wake up from IRQ latency
It seems impossible to have 32MHz SYSCLK and keep 48MHz for USB and 24MHz for MCU =(.
So the only way is to initiate transfer within ISR via CMSIS?
So the only way is to initiate transfer within ISR via CMSIS?
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: Thread wake up from IRQ latency
Hi,
What is the problem starting a transfer directly from the ISR? what driver are you using for that? SPI? the SPI driver supports starting a transfer from ISR: spiStartxxxxxI().
Giovanni
What is the problem starting a transfer directly from the ISR? what driver are you using for that? SPI? the SPI driver supports starting a transfer from ISR: spiStartxxxxxI().
Giovanni