mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-21 16:18:29 -04:00
HAL_ChibiOS: avoid doing one-way SPI transfers
these transfers use dummy bytes in the hal driver, which may not be in DMA safe memory, so best to avoid them
This commit is contained in:
parent
dad1774330
commit
a3e69e715d
@ -161,10 +161,10 @@ bool DeviceBus::adjust_timer(AP_HAL::Device::PeriodicHandle h, uint32_t period_u
|
||||
void DeviceBus::bouncebuffer_setup(const uint8_t *&buf_tx, uint16_t tx_len,
|
||||
uint8_t *&buf_rx, uint16_t rx_len)
|
||||
{
|
||||
if (buf_rx) {
|
||||
if (rx_len != 0) {
|
||||
bouncebuffer_setup_read(bounce_buffer_rx, &buf_rx, rx_len);
|
||||
}
|
||||
if (buf_tx) {
|
||||
if (tx_len != 0) {
|
||||
bouncebuffer_setup_write(bounce_buffer_tx, &buf_tx, tx_len);
|
||||
}
|
||||
}
|
||||
|
@ -176,13 +176,7 @@ void SPIDevice::do_transfer(const uint8_t *send, uint8_t *recv, uint32_t len)
|
||||
|
||||
bus.bouncebuffer_setup(send, len, recv, len);
|
||||
|
||||
if (send == nullptr) {
|
||||
spiReceive(spi_devices[device_desc.bus].driver, len, recv);
|
||||
} else if (recv == nullptr) {
|
||||
spiSend(spi_devices[device_desc.bus].driver, len, send);
|
||||
} else {
|
||||
spiExchange(spi_devices[device_desc.bus].driver, len, send, recv);
|
||||
}
|
||||
spiExchange(spi_devices[device_desc.bus].driver, len, send, recv);
|
||||
|
||||
bus.bouncebuffer_finish(send, recv, len);
|
||||
|
||||
|
@ -48,6 +48,8 @@ void bouncebuffer_init(struct bouncebuffer_t **bouncebuffer, uint32_t prealloc_b
|
||||
|
||||
/*
|
||||
setup for reading from a device into memory, allocating a bouncebuffer if needed
|
||||
Note that *buf can be NULL, in which case we allocate DMA capable memory, but don't
|
||||
copy to it in bouncebuffer_finish_read(). This avoids DMA failures in dummyrx in the SPI LLD
|
||||
*/
|
||||
void bouncebuffer_setup_read(struct bouncebuffer_t *bouncebuffer, uint8_t **buf, uint32_t size)
|
||||
{
|
||||
@ -79,8 +81,10 @@ void bouncebuffer_setup_read(struct bouncebuffer_t *bouncebuffer, uint8_t **buf,
|
||||
void bouncebuffer_finish_read(struct bouncebuffer_t *bouncebuffer, const uint8_t *buf, uint32_t size)
|
||||
{
|
||||
if (bouncebuffer && buf == bouncebuffer->dma_buf) {
|
||||
osalDbgAssert((bouncebuffer->busy == true), "bouncebuffer finish_read");
|
||||
memcpy(bouncebuffer->orig_buf, buf, size);
|
||||
osalDbgAssert((bouncebuffer->busy == true), "bouncebuffer finish_read");
|
||||
if (bouncebuffer->orig_buf) {
|
||||
memcpy(bouncebuffer->orig_buf, buf, size);
|
||||
}
|
||||
bouncebuffer->busy = false;
|
||||
}
|
||||
}
|
||||
@ -104,7 +108,9 @@ void bouncebuffer_setup_write(struct bouncebuffer_t *bouncebuffer, const uint8_t
|
||||
osalDbgAssert((bouncebuffer->dma_buf != NULL), "bouncebuffer write allocate");
|
||||
bouncebuffer->size = size;
|
||||
}
|
||||
memcpy(bouncebuffer->dma_buf, *buf, size);
|
||||
if (*buf) {
|
||||
memcpy(bouncebuffer->dma_buf, *buf, size);
|
||||
}
|
||||
*buf = bouncebuffer->dma_buf;
|
||||
#if defined(STM32H7)
|
||||
osalDbgAssert((((uint32_t)*buf)&31) == 0, "bouncebuffer write align");
|
||||
|
Loading…
Reference in New Issue
Block a user