Skip to main content
Associate
October 19, 2024
Solved

Writing data from RAM to Flash with DMA

  • October 19, 2024
  • 3 replies
  • 963 views

Hello, 

i'm wondering if it is possible to copy data from RAM to flash using DMA after unlocking the FLASH memory

 

static const uint32_t src[4] ={80,20,30};

static uint32_t dst = 0x080E0000;

__HAL_RCC_DMA1_CLK_ENABLE();
dma_handler.Instance = DMA1_Stream0;
dma_handler.Init.Channel = DMA_CHANNEL_0;
dma_handler.Init.Direction = DMA_MEMORY_TO_MEMORY;
dma_handler.Init.PeriphInc = DMA_PINC_ENABLE;
dma_handler.Init.MemInc = DMA_MINC_ENABLE;
dma_handler.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
dma_handler.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
dma_handler.Init.Mode = DMA_NORMAL;
dma_handler.Init.Priority = DMA_PRIORITY_LOW;
HAL_DMA_Init(&dma_handler);
//__HAL_LINKDMA(&flashHandle, hdma, dma_handler);

//HAL_GPIO_WritePin(GPIOG,GPIO_PIN_13,GPIO_PIN_SET);
HAL_FLASH_Unlock();
FLASH_Erase_Sector(FLASH_SECTOR_11, VOLTAGE_RANGE_3);

HAL_DMA_Start(&dma_handler,(uint32_t)&src,(uint32_t)&dst,4);
HAL_FLASH_Lock();

 

Nothing is happened and the value still empty

Best answer by Tesla DeLorean

Which STM32?

What exactly would be the point/value of doing it this way?

Do any of the functions return an error code?

The F2/F4 won't support memory-to-memory on DMA1

Wouldn't you need to enable the PG bit ?

3 replies

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
October 19, 2024

Which STM32?

What exactly would be the point/value of doing it this way?

Do any of the functions return an error code?

The F2/F4 won't support memory-to-memory on DMA1

Wouldn't you need to enable the PG bit ?

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
STOne-32
ST Technical Moderator
October 20, 2024

Dear @abdelwahedbaha ,

as shared by @Tesla DeLorean . It has no meaning to write to flash via DMA , Flash writing as a specific controller and software sequence to strictly follow by activation of PG bit and polling for each correct Erase/Program and also Errors checking . 

have a good start on STM32

STOne-32

Uwe Bonnes
Chief
October 20, 2024

Flash write access needs to be paced by the flash, not some other timing. As there is no such flash event to the DMA system, you can not do it. The reason why you want to do it is also unclear.