Speed-up erase and program.

Signed-off-by: Yilin Sun <imi415@imi.moe>
This commit is contained in:
Yilin Sun 2023-02-11 10:46:01 +08:00
parent 02c3f7b616
commit fbae9f1ed9
Signed by: imi415
GPG Key ID: 17F01E106F9F5E0A
3 changed files with 17 additions and 18 deletions

View File

@ -89,7 +89,7 @@ static void GPIO_Init(void) {
static int QSPI_Init(void) {
hqspi.Instance = QUADSPI;
hqspi.Init.ClockPrescaler = 1;
hqspi.Init.ClockPrescaler = 0;
hqspi.Init.FifoThreshold = 4;
hqspi.Init.SampleShifting = QSPI_SAMPLE_SHIFTING_NONE;
hqspi.Init.FlashSize = APP_FLASH_BITS;
@ -271,7 +271,6 @@ int Flash_Map(void) {
}
int Flash_UnMap(void) {
/* De-init and re-init QSPI, as HAL driver has too much magic. */
HAL_StatusTypeDef ret;
do {
ret = HAL_QSPI_Abort(&hqspi);

View File

@ -1,6 +1,6 @@
#include "FlashConfig.h"
#include "FlashOS.h"
#include "FlashOperations.h"
#include "FlashConfig.h"
/*
* Initialize Flash Programming Functions
@ -11,7 +11,11 @@
*/
int Init(unsigned long adr, unsigned long clk, unsigned long fnc) {
if (Flash_Init() != 0) return 1;
if (Flash_Map() != 0) return 1;
/* Verify operation */
if (fnc == 3) {
if (Flash_Map() != 0) return 1;
}
return 0;
}
@ -22,6 +26,10 @@ int Init(unsigned long adr, unsigned long clk, unsigned long fnc) {
* Return Value: 0 - OK, 1 - Failed
*/
int UnInit(unsigned long fnc) {
if (fnc == 3) {
if (Flash_UnMap() != 0) return 1;
}
if (Flash_Deinit() != 0) return 1;
return 0;
}
@ -31,9 +39,7 @@ int UnInit(unsigned long fnc) {
* Return Value: 0 - OK, 1 - Failed
*/
int EraseChip(void) {
if (Flash_UnMap() != 0) return 1;
if (Flash_EraseChip() != 0) return 1;
if (Flash_Map() != 0) return 1;
return 0;
}
@ -44,10 +50,7 @@ int EraseChip(void) {
*/
int EraseSector(unsigned long adr) {
uint32_t sector_offset = (adr - APP_FLASH_BASE) & ~(APP_FLASH_SECTOR_SIZE - 1);
if (Flash_UnMap() != 0) return 1;
if (Flash_EraseSector(sector_offset) != 0) return 1;
if (Flash_Map() != 0) return 1;
return 0;
}
@ -60,10 +63,7 @@ int EraseSector(unsigned long adr) {
*/
int ProgramPage(unsigned long adr, unsigned long size, unsigned char *buffer) {
uint32_t page_start = (adr - APP_FLASH_BASE);
if (Flash_UnMap() != 0) return 1;
if (Flash_ProgramPage(page_start, buffer, size) != 0) return 1;
if (Flash_Map() != 0) return 1;
return 0;
}

View File

@ -40,42 +40,42 @@ void HAL_QSPI_MspInit(QSPI_HandleTypeDef* qspiHandle) {
GPIO_InitStruct.Pin = GPIO_PIN_9 | GPIO_PIN_14;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_6;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF10_QUADSPI;
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_6 | GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF10_QUADSPI;
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_2 | GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_2;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}