|
|
@@ -65,10 +65,10 @@ void at45db_init()
|
|
|
#endif
|
|
|
|
|
|
#ifdef DATAFLASH_PAGE_SIZE
|
|
|
- AT45DB->block_size = 2112;
|
|
|
- AT45DB->blocks = 256;
|
|
|
- AT45DB->flash_mbit = 4;
|
|
|
- AT45DB->page_size = 264;
|
|
|
+ AT45DB.block_size = 2112;
|
|
|
+ AT45DB.blocks = 256;
|
|
|
+ AT45DB.flash_mbit = 4;
|
|
|
+ AT45DB.page_size = 264;
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
@@ -196,39 +196,24 @@ uint16_t at45db_wake_up_from_ultra_deep_sleep(at45db_t info)
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
-/**
|
|
|
- * @brief This functions performs a contineus array read inside the main memory of the external flash.
|
|
|
- * It starts from the specified address and continues to the next address if the size is long enough in order to take
|
|
|
- * information from the next addresses.
|
|
|
- * @param address : This is the starting address of the main memory you want to start reading from.
|
|
|
- * @param data : The buffer that will contain the return data from the main memory of the flash.
|
|
|
- * @param size : The size of data that you want to read.
|
|
|
- * @retval None.
|
|
|
- */
|
|
|
-void at45db_read_data(uint32_t address, uint8_t *data, uint16_t size)
|
|
|
+void at45db_read(uint16_t page, uint8_t *data, uint16_t size)
|
|
|
{
|
|
|
- uint8_t address_bytes[5];
|
|
|
+ uint8_t cmd[5];
|
|
|
+ uint32_t addr = (uint32_t)page << 8;
|
|
|
|
|
|
- /*Set the address bytes*/
|
|
|
- address_bytes[0] = CONTINUOUS_ARRAY_READ_H_MODE2;
|
|
|
- address_bytes[1] = ((address >> 16) & 0xFF);
|
|
|
- address_bytes[2] = ((address >> 8) & 0xFF);
|
|
|
- address_bytes[3] = (address & 0xFF);
|
|
|
- address_bytes[4] = 0;
|
|
|
+ cmd[0] = 0x0B; // high-speed read
|
|
|
+ cmd[1] = (addr >> 16) & 0xFF;
|
|
|
+ cmd[2] = (addr >> 8) & 0xFF;
|
|
|
+ cmd[3] = addr & 0xFF;
|
|
|
+ cmd[4] = 0x00; // dummy
|
|
|
|
|
|
- /*Select the device*/
|
|
|
FLASH_CS_ENABLE();
|
|
|
-
|
|
|
- /*Transmit the address bytes*/
|
|
|
- HAL_SPI_Transmit(&hspi2, address_bytes, 4, HAL_MAX_DELAY);
|
|
|
-
|
|
|
- /*Receive the data from the external flash memory*/
|
|
|
+ HAL_SPI_Transmit(&hspi2, cmd, 5, HAL_MAX_DELAY);
|
|
|
HAL_SPI_Receive(&hspi2, data, size, HAL_MAX_DELAY);
|
|
|
-
|
|
|
- /*Release the slave device*/
|
|
|
FLASH_CS_DISABLE();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* @brief Enter flash into ultra deep sleep.
|
|
|
* @param info : Structure information about the external flash operation.
|
|
|
@@ -260,54 +245,35 @@ void at45db_ultra_deep_sleep(at45db_t info)
|
|
|
}
|
|
|
|
|
|
|
|
|
-/**
|
|
|
- * @brief This function performs a programming operation into the main memory of the external flash
|
|
|
- * using the internal buffer 1 with built in erase operation.
|
|
|
- * @param addr : The starting address of the main memory.
|
|
|
- * @param buffer: The buffer that holds the data which will be stored inside the main memory.
|
|
|
- * @param size : The size of the data.
|
|
|
- * @retval None.
|
|
|
- */
|
|
|
-void at45db_program(uint32_t addr, uint8_t *buffer, uint16_t size)
|
|
|
+void at45db_write(uint16_t page, uint8_t *data, uint16_t size)
|
|
|
{
|
|
|
- /*Load data into Buffer 1*/
|
|
|
- uint8_t loadCommand[4];
|
|
|
- loadCommand[0] = 0x84; // Buffer 1 Write opcode
|
|
|
- loadCommand[1] = 0x00; // Dummy byte
|
|
|
- loadCommand[2] = 0x00; // Dummy byte
|
|
|
- loadCommand[3] = 0x00; // Buffer starting address
|
|
|
-
|
|
|
- /*Select the external flash memory*/
|
|
|
- FLASH_CS_ENABLE();
|
|
|
+ uint8_t cmd[4];
|
|
|
+ uint32_t addr = (uint32_t)page << 8;
|
|
|
|
|
|
- /*Send the proper command & data to the internal buffer 1*/
|
|
|
- HAL_SPI_Transmit(&hspi2, loadCommand, 4, HAL_MAX_DELAY);
|
|
|
- HAL_SPI_Receive(&hspi2, (uint8_t *)buffer, size, HAL_MAX_DELAY);
|
|
|
|
|
|
- /*Deselect the flash memory*/
|
|
|
+ // 1. Запись во внутренний буфер
|
|
|
+ cmd[0] = 0x84; cmd[1] = 0; cmd[2] = 0; cmd[3] = 0;
|
|
|
+ FLASH_CS_ENABLE();
|
|
|
+ HAL_SPI_Transmit(&hspi2, cmd, 4, HAL_MAX_DELAY);
|
|
|
+ HAL_SPI_Transmit(&hspi2, data, size, HAL_MAX_DELAY);
|
|
|
FLASH_CS_DISABLE();
|
|
|
|
|
|
- /*Program Buffer 1 to Main Memory Page with Built-In Erase*/
|
|
|
- uint8_t programCommand[4];
|
|
|
- programCommand[0] = 0x83; // Buffer 1 to Main Memory Page Program with Built-In Erase opcode
|
|
|
- programCommand[1] = (addr >> 16) & 0xFF; // Address byte 1
|
|
|
- programCommand[2] = (addr >> 8) & 0xFF; // Address byte 2
|
|
|
- programCommand[3] = addr & 0xFF; // Address byte 3
|
|
|
+ // 2. Перенос буфера в нужную страницу
|
|
|
+ cmd[0] = 0x83;
|
|
|
+ cmd[1] = (addr >> 16) & 0xFF;
|
|
|
+ cmd[2] = (addr >> 8) & 0xFF;
|
|
|
+ cmd[3] = addr & 0xFF;
|
|
|
|
|
|
- /*Select the external flash memory*/
|
|
|
FLASH_CS_ENABLE();
|
|
|
-
|
|
|
- /*Program the main memory. Send contents of buffer 1 to main memory*/
|
|
|
- HAL_SPI_Transmit(&hspi2, programCommand, 4, HAL_MAX_DELAY);
|
|
|
-
|
|
|
- /*Deselect the flash memory*/
|
|
|
+ HAL_SPI_Transmit(&hspi2, cmd, 4, HAL_MAX_DELAY);
|
|
|
FLASH_CS_DISABLE();
|
|
|
|
|
|
+ // 3. Ждём готовности
|
|
|
+ while (!(at45db_get_status() & 0x80))
|
|
|
+ HAL_Delay(1);
|
|
|
+}
|
|
|
|
|
|
- int is_ready = at45db_is_ready();
|
|
|
|
|
|
- while (!is_ready) {}
|
|
|
-}
|
|
|
|
|
|
void at45db_read_continuous(uint32_t addr, uint8_t *buffer, uint32_t size)
|
|
|
{
|
|
|
@@ -387,9 +353,7 @@ void at45db_chip_erase(void)
|
|
|
|
|
|
/*Check for fault operation*/
|
|
|
res = at45db_fault_check();
|
|
|
-
|
|
|
- if (res == 1)
|
|
|
- {
|
|
|
+ if (res == 1) {
|
|
|
printf("There was a fault in erase operation...\n\r");
|
|
|
}
|
|
|
else if (res == 0) {
|
|
|
@@ -495,3 +459,10 @@ void at45db_deep_sleep(at45db_t *info)
|
|
|
// SET_BIT(GPIO_SPIx->MODER, (1U<<(SPIx_GPIO_MISO_PIN*2)));
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+void at45db_wait_ready(void)
|
|
|
+{
|
|
|
+ while (!(at45db_get_status() & 0x80)) {
|
|
|
+ HAL_Delay(1);
|
|
|
+ }
|
|
|
+}
|