Skip to main content
Associate III
Jul 28, 2025 8:41 AM UTC
Question

Allocating DMA buffers on Heap

Hi everyone, 

I was wondering if is it valid to allocate DMA buffers for USART/SPI etc.. on the heap using aligned_alloc() function?

My board is the NUCLEO-H743ZI2 

 

If its possible - is it good practice?

Thanks, Ariel

This topic has been closed for replies.

2 replies

Andrew Neil
Super User
Jul 28, 2025 8:58 AM UTC

"heap" is purely a software abstraction.

The DMA itself neither knows not cares anything about "heap" - it just works with hardware addresses.

The usual issues of heap in embedded applications would still apply.

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
TDK
Jul 28, 2025 12:57 PM UTC

> If its possible - is it good practice?

Dynamically allocated memory on a microcontroller is generally frowned upon, but opinions will vary. It introduces possibilities for code bugs that do not exist with static allocation.

"If you feel a post has answered your question, please click ""Accept as Solution""."