Reading data from external flash using SPI - STM32L4xx with AT45DB041E
Hello,
I am trying to implement a bootloader, which will take a look each time it starts to an external flash memory (AT45DB041E) to see if something is written into it. If the external flash contains new data I need to read that data an write it to my internal flash memory. I am using STM32L4xx microcontroller and I have correctly implement the SPI peripheral in order to communicate with the external flash since I am able to read its manufacturer ID. However, I don't know how to use the read function that I have implemented. Before continue let me tell you that, this external flash is written by a LoRa module and contains a binary data from cloud which is actually a new firmware. All I need to do is to manage some how to read those data from the external flash but I don't know how to start. What buffer size should I use when I am using the at45db_read function which I have implemented? Since the external flash memory is 4MBIT I can't read it all, so where to start reading data? Is that a proper way to do (Using buffer to store data)?
This is my function where I have implemented based on datasheet of the external flash.
void at45db_read_data(uint32_t address, uint8_t *data, uint16_t size)
{
uint8_t address_bytes[4];
uint8_t opcode = CONTINUOUS_ARRAY_READ_H_MODE2;
/*Set the address bytes*/
address_bytes[0] = ((address >> 16) & 0xFF);
address_bytes[1] = ((address >> & 0xFF);
address_bytes[2] = (address & 0xFF);
address_bytes[3] = 0;
/*Select the device*/
SPIx_enable_slave(GPIO_SPIx);
/*Transmit the proper opcode*/
SPIx_transmit(SPI_PERIPH, &opcode, 1);
/*Release the slave device*/
SPIx_disable_slave(GPIO_SPIx);
/*Select the device*/
SPIx_enable_slave(GPIO_SPIx);
/*Transmit the address bytes*/
SPIx_transmit(SPI_PERIPH, address_bytes, 4);
/*Receive the data from the external flash memory*/
SPIx_receive(SPI_PERIPH, data, size);
/*Release the slave device*/
SPIx_disable_slave(GPIO_SPIx);
}
Is that the proper way or I maybe use another technic for that?
