Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]: PX4IO F7 DMA buffer review (dcache flush and alignment) #12075

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/drivers/px4io/px4io_serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class PX4IO_serial_f7 : public PX4IO_serial
/**
* IO Buffer storage
*/
static uint8_t _io_buffer_storage[];
static uint8_t _io_buffer_storage[] __attribute__((aligned(ARMV7M_DCACHE_LINESIZE)));
};

#else
Expand Down
16 changes: 7 additions & 9 deletions src/drivers/px4io/px4io_serial_f7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,10 @@
#define rCR3 REG(STM32_USART_CR3_OFFSET)
#define rGTPR REG(STM32_USART_GTPR_OFFSET)

#define CACHE_LINE_SIZE 32
#define DMA_BUFFER_MASK (ARMV7M_DCACHE_LINESIZE - 1)
#define DMA_ALIGN_UP(n) (((n) + DMA_BUFFER_MASK) & ~DMA_BUFFER_MASK)

#define ROUND_UP_TO_POW2_CT(size, alignment) (((uintptr_t)((size) + ((alignment) - 1u))) & (~((uintptr_t)((alignment) - 1u))))
#define ALIGNED_IO_BUFFER_SIZE ROUND_UP_TO_POW2_CT(sizeof(IOPacket), CACHE_LINE_SIZE)

uint8_t PX4IO_serial_f7::_io_buffer_storage[ALIGNED_IO_BUFFER_SIZE + CACHE_LINE_SIZE];
uint8_t PX4IO_serial_f7::_io_buffer_storage[DMA_ALIGN_UP(sizeof(IOPacket))];

PX4IO_serial_f7::PX4IO_serial_f7() :
_tx_dma(nullptr),
Expand Down Expand Up @@ -119,9 +117,9 @@ int
PX4IO_serial_f7::init()
{
/* initialize base implementation */
int r;
int r = PX4IO_serial::init((IOPacket *)&_io_buffer_storage[0]);

if ((r = PX4IO_serial::init((IOPacket *)ROUND_UP_TO_POW2_CT((uintptr_t)_io_buffer_storage, CACHE_LINE_SIZE))) != 0) {
if (r != 0) {
return r;
}

Expand Down Expand Up @@ -289,7 +287,7 @@ PX4IO_serial_f7::_bus_exchange(IOPacket *_packet)

/* Clean _current_packet, so DMA can see the data */
arch_clean_dcache((uintptr_t)_current_packet,
(uintptr_t)_current_packet + ALIGNED_IO_BUFFER_SIZE);
(uintptr_t)_current_packet + sizeof(_current_packet));

/* start TX DMA - no callback if we also expect a reply */
/* DMA setup time ~3µs */
Expand Down Expand Up @@ -459,7 +457,7 @@ PX4IO_serial_f7::_do_interrupt()
if (_rx_dma_status == _dma_status_waiting) {
/* Invalidate _current_packet, so we get fresh data from RAM */
arch_invalidate_dcache((uintptr_t)_current_packet,
(uintptr_t)_current_packet + ALIGNED_IO_BUFFER_SIZE);
(uintptr_t)_current_packet + sizeof(_current_packet));

/* verify that the received packet is complete */
size_t length = sizeof(*_current_packet) - stm32_dmaresidual(_rx_dma);
Expand Down