[STM32F407VET6] How to send a CAN frame from timer interrupt handler? Topic is solved

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: RoccoMarco, barthess

franek.bmw
Posts: 57
Joined: Thu Mar 13, 2014 11:15 am
Has thanked: 2 times

[STM32F407VET6] How to send a CAN frame from timer interrupt handler?

Postby franek.bmw » Thu Feb 23, 2017 12:18 pm

Hello,
In my program I have to send CAN frame from timer interrupt handler. I have read that the function canTransmit() can't be used to do this.
Is there any other possibility?

Best regards,
Franek

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: [STM32F407VET6] How to send a CAN frame from timer interrupt handler?  Topic is solved

Postby Giovanni » Thu Feb 23, 2017 1:28 pm

Hi,

Currently not, the driver would require a new API function, you may wake up a thread from your ISR and do the transmission from there.

Giovanni

franek.bmw
Posts: 57
Joined: Thu Mar 13, 2014 11:15 am
Has thanked: 2 times

Re: [STM32F407VET6] How to send a CAN frame from timer interrupt handler?

Postby franek.bmw » Fri Feb 24, 2017 9:07 am

Do you plan to create such new API function?

How much time I need to wake up a thread to do the transmission? I mean time from Interrupt to canTransmit function in new thread.


Franek

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: [STM32F407VET6] How to send a CAN frame from timer interrupt handler?

Postby Giovanni » Fri Feb 24, 2017 10:21 am

Hi,

Waking up a thread from an ISR takes few microseconds (depending from the jitter introduced y=by other ISRs. Sending the frame is almost immediate so the thread would sleep most time and only execute for some uS.

I will look into adding the new API anyway.

Giovanni

rew
Posts: 380
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 13 times

Re: [STM32F407VET6] How to send a CAN frame from timer interrupt handler?

Postby rew » Fri Feb 24, 2017 10:55 am

Look at it this way. Instead of directly calling the can_transmit function, the ISR does some stack magic and instead of returning to the code it interrupted, it returns to your code calling can_transmit. This is effectively what happens. when you wake up a (high priority) thread that is just waiting for the event to happen, and calls can_transmit immediately afterwards.

I'm not sure how long the context switch takes (i.e. the meddling with the stack). I would have estimated a bit faster than what giovanni estimates, but he wrote the code and he's interested in performance so I know he must have measured it....Unless you have very hard evidence, trust giovanni on that.

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: [STM32F407VET6] How to send a CAN frame from timer interrupt handler?

Postby Giovanni » Fri Feb 24, 2017 11:03 am

Context switch is much faster that what I estimated, however there are other IRQs in the system, the jitter prevails over the pure context switch time. It is not the best case that matters, the relevant figure is the worst case and that one depends on the application and its IRQs.

Giovanni

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: [STM32F407VET6] How to send a CAN frame from timer interrupt handler?

Postby Giovanni » Fri Feb 24, 2017 1:21 pm

Hi,

I made an error, the I-class API has already been introduced, try canTryTransmitI() and canTryReceiveI().

Giovanni

rew
Posts: 380
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 13 times

Re: [STM32F407VET6] How to send a CAN frame from timer interrupt handler?

Postby rew » Sun Feb 26, 2017 9:34 am

Giovanni wrote:Context switch is much faster that what I estimated, however there are other IRQs in the system, the jitter prevails over the pure context switch time. It is not the best case that matters, the relevant figure is the worst case and that one depends on the application and its IRQs.
That depends on what you are optimizing.

I suspect that the threadstarter here wants to optimize brain-time: he simply has an application where an interrupt routine ends up figuring out that a can packet needs transmitting. So the first thing he tried is calling cantransmit from the interrupt routine. Nothing time critical, just the easiest way to program things.

Then there could be the case where processing time is scarce. Maybe an ESC with a canbus with two motors and about 100kHz PWM frequencies. (that would almost saturate an '407). So then too the status updates in the interrupt are not jitter-critical but do need to be optimized for processing time....


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 18 guests