HAL_ChibiOS: ensure 32 byte alignment for DMA on H7
This commit is contained in:
parent
33699d4f4a
commit
ff21508ce8
@ -35,6 +35,12 @@
|
|||||||
|
|
||||||
#define MIN_ALIGNMENT 8
|
#define MIN_ALIGNMENT 8
|
||||||
|
|
||||||
|
#if defined(STM32H7)
|
||||||
|
#define DMA_ALIGNMENT 32
|
||||||
|
#else
|
||||||
|
#define DMA_ALIGNMENT 8
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HAL_NO_CCM
|
#ifdef HAL_NO_CCM
|
||||||
#undef CCM_RAM_SIZE_KB
|
#undef CCM_RAM_SIZE_KB
|
||||||
#endif
|
#endif
|
||||||
@ -102,7 +108,7 @@ static void *malloc_dtcm(size_t size)
|
|||||||
{
|
{
|
||||||
void *p = NULL;
|
void *p = NULL;
|
||||||
#if defined(DTCM_RAM_SIZE_KB)
|
#if defined(DTCM_RAM_SIZE_KB)
|
||||||
p = chHeapAllocAligned(&dtcm_heap, size, CH_HEAP_ALIGNMENT);
|
p = chHeapAllocAligned(&dtcm_heap, size, DMA_ALIGNMENT);
|
||||||
#else
|
#else
|
||||||
(void)size;
|
(void)size;
|
||||||
#endif
|
#endif
|
||||||
@ -153,21 +159,26 @@ void *malloc(size_t size)
|
|||||||
*/
|
*/
|
||||||
void *malloc_dma(size_t size)
|
void *malloc_dma(size_t size)
|
||||||
{
|
{
|
||||||
|
#if defined(STM32H7)
|
||||||
|
size = (size + (DMA_ALIGNMENT-1)) & ~(DMA_ALIGNMENT-1);
|
||||||
|
#endif
|
||||||
void *p;
|
void *p;
|
||||||
#if defined(DTCM_RAM_SIZE_KB)
|
#if defined(DTCM_RAM_SIZE_KB)
|
||||||
p = malloc_dtcm(size);
|
p = malloc_dtcm(size);
|
||||||
#else
|
#else
|
||||||
// if we don't have DTCM memory then assume that main heap is DMA-safe
|
// if we don't have DTCM memory then assume that main heap is DMA-safe
|
||||||
p = chHeapAllocAligned(NULL, size, MIN_ALIGNMENT);
|
p = chHeapAllocAligned(NULL, size, DMA_ALIGNMENT);
|
||||||
#endif
|
#endif
|
||||||
#if DMA_RESERVE_SIZE != 0
|
#if DMA_RESERVE_SIZE != 0
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
p = chHeapAllocAligned(&dma_reserve_heap, size, MIN_ALIGNMENT);
|
p = chHeapAllocAligned(&dma_reserve_heap, size, DMA_ALIGNMENT);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (p) {
|
if (p) {
|
||||||
memset(p, 0, size);
|
memset(p, 0, size);
|
||||||
}
|
}
|
||||||
|
osalDbgAssert((((uint32_t)p) & (DMA_ALIGNMENT-1)) == 0, "DMA alignment");
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user