STM32 Host driver to communicate with SPI Bootloader

Blog Post created by fillon.nicolas Employee on Dec 8, 2017



In some of our STM32 the bootloader (system memory) supports SPI communication to reflash the STM32 internal flash.


Here are some drivers for the Total Phase Aardvark.


Here is an example of usage.


I tested it on a Nucleo L476 and used SPI2 of the STM32 to communicate to the


Note: make sure that your STM32L476 is a revision 4 (rev 3 do not support SPI for bootloader).


Make sure to have BOOT0 connected to VDD (please see jumper below connecting BOOT0 and VDD). This will permit the STM32 to boot in Bootloader mode after reset or power cycling.


Here are my connections to the Aarvark:

On your PC you will need to install CodeBlocks: I recommend that you download CodeBlocks with mingw included(GCC/C++ Compiler), named codeblocks-16.01mingw-setup.exe on the following link :


Then open the project that is attached to this email with CodeBlock:


Make sure that the Aarvark driver is installed correctly.


In the code you will need the following calls in the main functions:


void main (void)



    //initialize Aardvark hardware

    handle = Hardware_Init();


    //Connect to Bootloader

    printf("\n Connecting to BL System Memory ... ");




    printf("\n Writing File to FLASH Memory ... ");

    WriteMemory(handle, 0x08000000,"FileUSER.bin");    // FileUSER.bin must be under project directory

//(0x08000000 is the FLASH address and it could be changed)




Then build the code on CodeBlock


Connect both Nucleo board and Aarvark.


Press reset on the Nucleo board and then press Run on the Codeblocks to run the app which will program the image to the STM32L4.


You can verify that the programming was done correctly by reading the flash using ST-LINK Utility.