strange coherency problem with dma buffer

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, utzig, tfAteba, barthess

User avatar
alex31
Posts: 374
Joined: Fri May 25, 2012 10:23 am
Location: toulouse, france
Has thanked: 38 times
Been thanked: 61 times
Contact:

strange coherency problem with dma buffer

Postby alex31 » Wed Jul 08, 2020 9:20 pm

Hello,

My question is not chibios specific.

I have received a bug report on open source software that i wrote, on a dshot driver which basically fill a buffer which is transmitted (DMA) to a timer in pwm mode to make a pulse coded numeric signal respecting the dshot protocol. The bug report is : 7% of the frames are not correct.

The processor used is a F7, because of cache coherency problem, i took care of putting the global variable buffer in ram3, a ram section which is uncached, so the bug is not due to that common cause.

After some tries, i finally find a fix : declaring all the dma buffer volatile. I had to change all the API to add volatile on all functions which take that buffer address as a parameter.

I still don't understand why i had to declare this buffer volatile, since it is writen to by the CPU, *then* read by the DMA controler, there is never concurrent access.

If one has advice or explanation, i need to understand !

Thanks
Alexandre

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: strange coherency problem with dma buffer

Postby Giovanni » Thu Jul 09, 2020 8:36 am

It depends on the code that access the DMA buffer, adding volatile enforces the compiler to not attempt optimizations on buffer accesses.

You need to compare the asm code with and without volatile.

Giovanni

User avatar
alex31
Posts: 374
Joined: Fri May 25, 2012 10:23 am
Location: toulouse, france
Has thanked: 38 times
Been thanked: 61 times
Contact:

Re: strange coherency problem with dma buffer

Postby alex31 » Fri Jul 10, 2020 2:21 pm

Finally, volatile fixing the problem was sot sufficient, real problem belongs to DMA bandwidth, and seems to be fixed playing with DMA priority.

ADC dma/irq priority == PWM dma/irq priority, no volatile : 7% of malformed dshot frame
ADC dma/irq priority < PWM dma/irq priority, dma buffer not volatile : 0.1 % of malformed dshot frame
ADC dma/irq priority < PWM dma/irq priority, dma buffer volatile : 0 % of malformed dshot frame

hope that this DMA priority change resolving the problem is not itself a side affect of a root cause that has not yet been discovered ...

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: strange coherency problem with dma buffer

Postby Giovanni » Fri Jul 10, 2020 2:51 pm

If you have multiple DMAs try splitting buffers in different SRAMs, that should mitigate bandwidth issues (try to keep each DMA master on a specific SRAM slave).

Giovanni


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 15 guests