there are two things:eriksl wrote: ↑Tue Jun 11, 2024 9:50 amAre you replying to what ESP_Sprite says? I think he was quite clear.
Anyway, I don't think it makes sense to start up DMA for just two (or four) bytes. The overhead will be huge and most of the handling will be done by the SPI module anyway. I remember having seen a table in the documentation with break-even points for amounts of data between handling the data directly from/to the module or using DMA and I also remember the break-even point wasn't very small, somehing around 128 bytes.
- DMA releases CPU core so thread can go to sleep and CPU proceed with another tasks. i use polling now at research-development phase, and later it will be redesigned: configure-IO-and-forget until data arrived.
- I need one reusable piece of code responsible for SPI IO, where all SPI related bugs reside and SPI I/O can fail or be broken. so even if single byte, tens of them or thousands - one code, one concept(with some overhead on short chunks - well, okay, reasonable price for easy code maintenance).
and surprisingly: setting 'SPI_DMA_DISABLE' on invoking spi_bus_initialize(...) breaks everything: with DMA enabled i get from driver almost the same as see on oscilloscope screen; but with DMA disabled it naturally does sh@t, failing to acquire correctly even a single byte from the bus!(it probably requires some fine tuning... but just huck it - why doesn't it simply behave same way???)
yeah, malloc does the trick.eriksl wrote: ↑Tue Jun 11, 2024 9:50 amAlso ESP_sprite already said that malloc (and variants) already return aligned memory blocks. This is by concept a requirement of malloc. It's will always return an address aligned to the largest alignment requirement of the processor.
If you want a static or auto (stack) to be aligned, you should indeed use the alignment attributes OR use the dirty trick to declare a "large" type (like uint32_t) and cast it to a char or small char array [sizeof(uint32_t)].
it looks like stack variables when their allocation left as is, are often aligned by default too... i had to include two local variables into one structure to illustrate nearby data damage by... seems to me, SPI driver in case of misaligned buffer.
BTW, since it's not DMA hardware(writing to it's hardware FIFO, as i understand) - it's probably a driver bug.