USART(Serial) interrupt

miki
Wed Jun 01, 2016 3:05 am
I read somewhere there is serial interrupt implemented in libmaple.
May somebody share on how to use it?
I need to process a serial frame,in interrupt on RX .

RogerClark
Wed Jun 01, 2016 9:43 am
I think the libmaple uses the uses interrupts to read the USART when an incoming character is received, and puts it into the input ring buffer

So if you want to call your own function as well as the character going into the ring buffer, you would need to modify the code in cores\maple\libmaple\usart_f1

e.g.

void __irq_usart1(void) {
usart_irq(&usart1_rb, USART1_BASE);
}


miki
Wed Jun 01, 2016 12:13 pm
The interrupt handler is called automatically as soon as a character is received and the appropriate flag is set.
So this function is the interrupt handler? It is fired automatically?

RogerClark
Wed Jun 01, 2016 9:14 pm
@miki

I presume it is fired straight away, but the best option is for you to write some code and do some research, or to read the master programming manual for the F103


miki
Thu Jun 02, 2016 4:01 pm
I tried some code on Serial3 and I saw it is nod defined. I used Generic F103C series
Serial and Serial2 are compiling.
I want to use USART3 because it is 5V tolerant.USAR2 is not,and I keep USART1 for debugging.
Or maybe Serial2 it is USART3 ?Confusing.Yes I see that in boards.cpp for generic,

mrburnette
Thu Jun 02, 2016 5:39 pm
miki wrote:I tried some code on Serial3 and I saw it is nod defined. I used Generic F103C series
Serial and Serial2 are compiling.
I want to use USART3 because it is 5V tolerant.USAR2 is not,and I keep USART1 for debugging.
Or maybe Serial2 it is USART3 ?Confusing.Yes I see that in boards.cpp for generic,

miki
Thu Jun 02, 2016 7:53 pm
I want to bypass maple handler and use mine inside the arduino sketch to have better control and more checks
I don’T know how to proceed.I can replace __irq_usart3() in usart_f1.c but it seems too complicated and too personalized with declaring specific variables used only inside my sketch.I need to process data in the interrupt and have more control.
How can I use the original STM32 USART interrupt handlers?.
I read reference manual but did not find what I’m looking for.On avr it is simple you know the name of the vector and you call it inside the sketch.I want to do the same.

mrburnette
Thu Jun 02, 2016 8:22 pm
miki wrote:I want to bypass maple handler and use mine inside the arduino sketch to have better control and more checks
I don’T know how to proceed.
<…>

miki
Thu Jun 02, 2016 9:04 pm
Respectfully,

I need to insert something similar on my sketch.I need my handle override default handler from maple.

uint16_t x;
uint16_t index;
#define BUFFER_SIZE

void USART_3 interrupt handler() {//?????

if((USART3_BASE->SR &0x0F)==0) // Check overrun, noise error,framing ,parity error
{
if(index==0){
if((USART3_BASE->DR&0xff)==x){
index++;
start a timer for 5ooous;
interrupt on timer output compare;
}
}
else{
buffer[(index++)-1]=USART3_BASE->DR&0xff;
if(index>BUFFER_SIZE){
disable timer interrrupt;
index=0;
}
}
}
else
index=0;
}


mrburnette
Fri Jun 03, 2016 1:53 pm
miki wrote:Respectfully,

I need to insert something similar on my sketch.I need my handle override default handler from maple.
<…>


miki
Fri Jun 03, 2016 8:04 pm
I tries to use maple own handler .
declaring extern in usartf1.c file ,….and calling it in my sketch but I received error “expected identifier or ‘(‘ before string constant extern “c” void.….”
extern "C" void __irq_usart3(void);


mrburnette
Fri Jun 03, 2016 11:04 pm
miki wrote:
<…>
I want to be able to use my handler or maple handler in my sketch.

miki
Sat Jun 04, 2016 12:56 am
Thanks!
for your effort.
I solved the problem It was so simple.
And it think the some modification can be made permanent in maple core for all versions.
Now I can play whatever I want in my sketch.I already test it and working ok.

miki
Tue Aug 30, 2016 4:40 pm
From maple library maker 4 yers ago just in case.
mbolivar
“In general, IRQ handlers need C linkage. Within a C++ file, this means you either put them within an extern “C” block, or you declare them extern “C” with

extern “C” void __irq_whatever(void) { … }

Within a C file, they’ll have C linkage already, so the extern linkage specifier is unnecessary.

Regarding how to release code which overrides IRQ handlers as a library, this is currently a pain, since you have to get your users to comment out the handlers in the copy of libmaple that comes with the IDE. That’s obviously not ideal, so in the next version, we’ll be making the libmaple IRQ handlers weak, so you can override them just by declaring your own.”

He never did that.So how about now?


Riva
Thu Feb 09, 2017 8:53 am
Sorry for dragging an old post up but did the weak IRQ thing ever happen so it’s easy to replace the default IRQ handler without resorting to core file editing?

EDIT: I have answered my own question by trying a sample sketch and the answer is no, the weak attribute did not get implemented.
What likely problems would it cause to the core to add the __weak attribute to the usart_f1.c interrupt definitions and would it allow a user to implement there own service routines using something like below in there code.
extern "C" void __irq_usart1(void)
{
// etc.
}


miki
Thu Feb 09, 2017 12:11 pm
In the end I commented original usart2 and 3 functions in usart_f1.c ,and used my own serial interrupt handlers in main program.
Now they are included in multiprotocol.And working excellent.
If you want to see more ,is here.
The serial handlers are in multiprotocol.ino/telemetry.ino
https://github.com/pascallanger/DIY-Mul … rduino-ide
https://github.com/pascallanger/DIY-Mul … -TX-Module

Leave a Reply

Your email address will not be published. Required fields are marked *