You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.
The text was updated successfully, but these errors were encountered: