cancel
Showing results for 
Search instead for 
Did you mean: 

How to write flash by an external SWD prgrammer?

peng jun
Associate II

Hi everbody. From the <<PM0075 Programming manual>> ,I have success erase the entire flash follow Mass Erase sequence, the C code as below:

FLASH_Status flashEraseAllOptionBytes_STM32(void)

{

  FLASH_Status status = FLASH_COMPLETE;

  uint32_t flash_CR,flash_SR;

    flash_CR = readMem((uint32_t)&(FLASH->CR));

    flash_CR |= CR_MER_Set;

    writeMem((uint32_t)&(FLASH->CR), flash_CR);

    flash_CR |= CR_STRT_Set;

    writeMem((uint32_t)&(FLASH->CR), flash_CR);

    status = FLASH_WaitForLastOperation(((uint32_t)0x000B0000));

  return 0x09;

}

But I don't know how to do write the flash by SWD?

3 REPLIES 3

SWD based programmers typically download a small applet to RAM which implements the FLASH Erase/Write functionality, taking data buffered in RAM and updating the FLASH.

Your tools would therefore need to be able to download the app/data to RAM, and then execute that code. Process repeats until you fully program device. I wouldn't try to drive the FLASH peripheral via the SWD directly.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
peng jun
Associate II

Thank you for your help . I don't konw how the kind of writeing app to ARM . So first , I want to write the Flash directly by SWD for Prove that my code will be ok, and second write app to ARM。 Mabe your have the code of writeing app to ARM?

Maybe I do.

You should perhaps start by looking at the FLASH examples for the specific STM32 part(s) you are targeting, and build and test those.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..