michallenc opened a new pull request, #15801:
URL: https://github.com/apache/nuttx/pull/15801

   ## Summary
   The message RAM does not behave correctly if lower 16 bits of buffer address 
overflow (upper 16 bits are set once in matrix driver for the entire CAN 
driver). For example message RAM starting at `0x2040fc20` would not work for 
buffers that go beyond `0x20410000` and MCAN would sent data located at 
`0x20400000` to the network. The same issue would occur even if TX buffers 
would start directly at `0x20410000`. The upper 16 bits would still have 
`0x2040` value because of RX buffers located in `0x2040ffff` range.
   
   This commit ensures the RAM is always located at the beginning of the data 
section and thus the overflow mentioned above should never occur. The 
alternative would be to use larger alignment, but the message RAM can have up 
to 4352 words and this would cause a significant padding.
   
   The RAM is also initialized to zero to ensure valid parity/ECC checksums. 
The address issue is not described anywhere in the manual, so it is possible 
this is caused by some incorrect configuration, but the context of the 
registers looks valid.
   
   This commit also fixes the compilation errors when the driver is run without 
data cache - `MCAN_ALIGN_UP` was undefined.
   
   ## Impact
   This fixes possible faults in SAMv7 MCAN driver. The error occurred only in 
the situations mentioned above, so it is not easily reproducible. Putting 
`.mcan` section before `.data` is a better solution than bigger alignment, as 
it avoids unnecessary padding and RAM usage.
   
   This also fixes compile errors when the driver is run without data cache - 
`MCAN_ALIGN_UP` was undefined. 
   
   ## Testing
   Tested on SAMv7 custom board. Before the fix, I had two TX buffers inside 
`0x2040ffff` range and two inside `0x2041ffff` range. The first two buffers 
worked as expected, but other two took data from `0x20400000` address instead 
of `0x20410000`. Locating the message RAM at the beginning of `.data` section 
solves this as overflow can never occur.
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to