Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

STM32 CCM Allocator

CCM Memory

The STM32 F2, F3, and F4 families have a special block of SRAM available called CCM (Core Coupled Memory). This memory has the drawback that it cannot be used for STM32 DMA operations.

By default, the CCM memory is lumped in with the rest of memory when the NuttX heaps are created. But this can be a problem because it will be a toss of the coin if non-DMA-able CCM memory or other DMA-able memory gets returned when malloc() is called. That usually does not matter but it certainly does make a difference if you are allocating memory that will be used for DMA! In that case, getting CCM memory for you DMA buffer will cause a failure.

CONFIG_STM32_CCMEXCLUDE

There is a configuration option called CONFIG_STM32_CCMEXCLUDE that can be used to exclude CCM memory from the heap. That solves the problem of getting CCM memory when you want to allocate a DMA buffer. But then what do you do with the CCM memory? Do you let it go unused?

CCM Allocator

In order to make use of the CCM memory, a CCM memory allocator is available. This memory allocator is automatically enabled when the following options are set:

...

With these interfaces you have a (nearly) standard way to manager memory from a heap that consists of the the CCM SRAM. And, since the CCM memory, is no longer a part of the normal heap, all allocated I/O buffers will be DMA-able (unless you have included other non-DMA-able memory regions in the stack).

CCM Stacks

One particular problem that has been reported by Petteri Aimonen requires some additional work-arounds. The STM32 SPI driver supports DMA and with SPI is is sometimes necessary to do some very small transfers for which there is no real gain from using DMA. In this case, Petteri has devised a clever way to both 1) make use of the CMM memory and 2) to force fallback to non-DMA transfers for these small stack transfers.

...