spi_slave: fix calculation of buffer size
the previous calculation added 4 additional bytes to the buffers when the length was already dividable by 4. Signed-off-by: Christian Ambach <christian.ambach@deutschebahn.com>
This commit is contained in:
parent
96783826d8
commit
18b44f2208
@ -35,7 +35,9 @@ static const char TAG[] = __FILE__;
|
|||||||
// https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/spi_slave.html
|
// https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/spi_slave.html
|
||||||
#define BUFFER_SIZE \
|
#define BUFFER_SIZE \
|
||||||
(MAX(8, HEADER_SIZE + PAYLOAD_BUFFER_SIZE) + \
|
(MAX(8, HEADER_SIZE + PAYLOAD_BUFFER_SIZE) + \
|
||||||
(4 - MAX(8, HEADER_SIZE + PAYLOAD_BUFFER_SIZE) % 4))
|
(PAYLOAD_BUFFER_SIZE % 4 == 0 \
|
||||||
|
? 0 \
|
||||||
|
: 4 - MAX(8, HEADER_SIZE + PAYLOAD_BUFFER_SIZE) % 4))
|
||||||
DMA_ATTR uint8_t txbuf[BUFFER_SIZE];
|
DMA_ATTR uint8_t txbuf[BUFFER_SIZE];
|
||||||
DMA_ATTR uint8_t rxbuf[BUFFER_SIZE];
|
DMA_ATTR uint8_t rxbuf[BUFFER_SIZE];
|
||||||
|
|
||||||
@ -70,7 +72,11 @@ void spi_slave_task(void *param) {
|
|||||||
|
|
||||||
// set length for spi slave driver
|
// set length for spi slave driver
|
||||||
transaction_size = HEADER_SIZE + msg.MessageSize;
|
transaction_size = HEADER_SIZE + msg.MessageSize;
|
||||||
transaction_size += (4 - transaction_size % 4);
|
// SPI transaction size needs to be at least 8 bytes and dividable by 4, see
|
||||||
|
// https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/spi_slave.html
|
||||||
|
if (transaction_size % 4 != 0) {
|
||||||
|
transaction_size += (4 - transaction_size % 4);
|
||||||
|
}
|
||||||
|
|
||||||
// prepare spi transaction
|
// prepare spi transaction
|
||||||
spi_slave_transaction_t spi_transaction = {0};
|
spi_slave_transaction_t spi_transaction = {0};
|
||||||
|
Loading…
Reference in New Issue
Block a user