okenido
Posts: 76
Joined: Thu Aug 02, 2018 11:47 am

Bare metal UART w/FIQ stops working

Wed Apr 29, 2020 12:11 am

I'm using the bare metal library Circle (https://github.com/rsta2/circle) for my project and i'm facing a weird problem.

I have UART0 setup in FIQ mode to receive some serial data, with the provided class CSerialDevice which works fine in a minimal example (https://github.com/rsta2/circle/blob/ma ... serial.cpp)


However in my application, the UART stops working after a random amount of time.
I checked the ARM_IC_FIQ_CONTROL register (address 0x3F00B20C on RPI3B) and it's normally 0xB9, telling it's enabled (0x80) and mapped to the UART peripheral (0x39).
When the UART stops working, this register suddently reads 0. The last interrupt doesn't trigger any error code.

I read the BCM2835 datasheet (https://www.raspberrypi.org/app/uploads ... herals.pdf) about UART and the document about its PL011 UART implementation and i can't find any reason for the FIQ control register to be cleared automatically by something.

It seems I can simply re-write 0xB9 to the register to make the UART work again (how inconvenient and hacky!)

I was first suspecting a memory leak/corruption in my code that could overwrite that memory address. But chances that it writes to this address specifically without affecting the rest of the operation are quite small - so i'm triple checking my code but I'd also like to get your impressions on that. What would you check/investigate for this issue?

macload1
Posts: 21
Joined: Mon Jul 07, 2014 6:50 am

Re: Bare metal UART w/FIQ stops working

Wed Apr 29, 2020 10:18 am

Dear okenido,
I already had such a problem on a different hardware and something that really helped me to debug that kind of problem was setting a breakpoint on the modification of that register. In my case it was a memory leak, that modified a pointer, and it was easy to find with the breakpoint. Do you have a debugger for your setup?
Best regards,
macload1

okenido
Posts: 76
Joined: Thu Aug 02, 2018 11:47 am

Re: Bare metal UART w/FIQ stops working

Wed Apr 29, 2020 12:36 pm

Thanks, I was able to somewhat locate the error because it triggered an exception (which was silently ignored because I had everything setup for a release) which in turn disabled the FIQ (found in Circle's exception handler).

I have some code that is writing to an invalid memory location. It should not happen as the value used to index the array is (should :mrgreen: ) always be in range.

It's a complex application with multicore, let's go down the rabbit hole...

okenido
Posts: 76
Joined: Thu Aug 02, 2018 11:47 am

Re: Bare metal UART w/FIQ stops working

Wed Apr 29, 2020 3:15 pm

Nailed it!

I had a parallel processing that was modifying a variable that could be potentially used by another core. When it was modified at the wrong timing it accessed an array with an index of -1.
That was causing the exception.

Damn it sounds so dumb, but the symptoms made it super hard to find (UART just stopping with the rest still working).

Spent a lot of time on this one but also learned a lot, which is great. Also thanks to rst who always provides great support for his library.

Return to “Bare metal, Assembly language”