msdk icon indicating copy to clipboard operation
msdk copied to clipboard

Async/DMA Peripheral Example Improvements & Doc Updates

Open BrentK-ADI opened this issue 1 year ago • 0 comments

The example projects for many of the peripherals (such as SPI, I2C, UART, etc) which leverage the mxc__req_t struct utilize a single main() to do all of the functionality whether it be Blocking, Async or DMA. In a typical application Async and DMA functionality will typically be done, then function exits and the MCU does other work while the peripheral is running the in the background.

A problem with the examples is the request structure is on the stack for main(). This isn't a problem for the examples since main never exits, but should a user go create a real application, if the request structure is on the stack, once the function exits, there is a high chance the request data is corrupted due to the stack space being reused. The peripherals only store the pointer to the provided request, not make a copy. At a minimum the examples should be modified to move the request struct into global scope to get it off the stack with comments explaining why. Also, the peripheral documentation should be updated to indicate the structure needs to be preserved during the duration of the transaction.

Alternatively, the peripheral could make a copy of the request, but that may or may not be wasted memory usage.

BrentK-ADI avatar Jul 25 '24 17:07 BrentK-ADI