I'm using an STM32L4 board and my flash memory looks like this: 

> 
> |\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> 
>  |  
> 
>  | USER application  
> 
>  |  
> 
>  |  
> 
>  |\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> 
>  |Vector table(UA)  
> 
>  |\_\_\_\_\_\_\_\_\_\_\_\_\_\_ 0x8000 - 8000  
> 
>  |  
> 
>  | Custom Bootloader  
> 
>  |  
> 
>  |  
> 
>  |\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> 
>  |Vector table(BL)  
> 
>  |\_\_\_\_\_\_\_\_\_\_\_\_\_\_ 0x8000 - 0000
> 
> 
> 

My board is connected to another board using UART (Let's define the other board as Master and my board as Slave).  

Master board shall be able to upgrade the user application of Slave board via UART. The idea is to send a binary file via UART and write it in the user application section.

According to ST's application note, there is a command called Write Memory command:

> 
> The Write Memory command is used to write data to any valid memory address (see note below) i.e. RAM, Flash memory, option byte area  
> 
>  When the bootloader receives the Write Memory command, it transmits
>  the ACK byte to the application. After the transmission of the ACK
>  byte, the bootloader waits for an address (4 bytes, byte 1 is the
>  address MSB and byte 4 is the LSB) and a checksum byte, it then checks
>  the received address. For the Option byte area, the start address must
>  be the base address of the Option byte area (see note) to avoid
>  writing inopportunely in this area. 
> 
> 
> if the received address is valid and the checksum is correct, the
>  bootloader transmits an ACK byte, otherwise it transmits a NACK byte
>  and aborts the command. When the address is valid and the checksum is
>  correct, the bootloader: 
> 
> 
> • gets a byte, N, which contains the number of data bytes to be
>  received 
> 
> 
> • receives the user data ((N + 1) bytes) and the checksum (XOR of N
>  and of all data bytes) 
> 
> 
> • programs the user data to memory starting from the received address 
> 
> 
> • at the end of the command, if the write operation was successful,
>  the bootloader transmits the ACK byte; otherwise it transmits a NACK
>  byte to the application and aborts the command
> 
> 
> **• The maximum length of the block to be written for the STM32 is 256 bytes**
> 
> 
> 

This means that I can only upgrade 256 bytes by a packet coming from Master board to Slave board. 

Now let's say that Master board has an SD card that contains a binary file and I want to flash this file to the user application section. How can I do this? Should read the binary file, and send a series of 256 bytes, each 256 in a packet?