Reduce flash clock for stability.

This commit is contained in:
Yilin Sun 2023-04-16 22:33:20 +08:00
parent 47699ff981
commit b8306f40ae
Signed by: imi415
GPG Key ID: 17F01E106F9F5E0A
2 changed files with 17 additions and 17 deletions

View File

@ -9,8 +9,8 @@
#define APP_FLASH_COMMAND_TIMEOUT (5000) #define APP_FLASH_COMMAND_TIMEOUT (5000)
#define LED_G_Pin GPIO_PIN_1 #define LED_G_Pin GPIO_PIN_1
#define LED_G_GPIO_Port GPIOA #define LED_G_GPIO_Port GPIOA
#define APP_DBG_LED_SET(x) HAL_GPIO_WritePin(LED_G_GPIO_Port, LED_G_Pin, x) #define APP_DBG_LED_SET(x) HAL_GPIO_WritePin(LED_G_GPIO_Port, LED_G_Pin, x)
@ -73,12 +73,11 @@ static void GPIO_Init(void) {
GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(LED_G_GPIO_Port, &GPIO_InitStruct); HAL_GPIO_Init(LED_G_GPIO_Port, &GPIO_InitStruct);
} }
static int QSPI_Init(void) { static int QSPI_Init(void) {
hqspi.Instance = QUADSPI; hqspi.Instance = QUADSPI;
hqspi.Init.ClockPrescaler = 0; hqspi.Init.ClockPrescaler = 7;
hqspi.Init.FifoThreshold = 4; hqspi.Init.FifoThreshold = 4;
hqspi.Init.SampleShifting = QSPI_SAMPLE_SHIFTING_HALFCYCLE; hqspi.Init.SampleShifting = QSPI_SAMPLE_SHIFTING_HALFCYCLE;
hqspi.Init.FlashSize = APP_FLASH_BITS; hqspi.Init.FlashSize = APP_FLASH_BITS;
@ -190,7 +189,7 @@ int Flash_ProgramPage(uint32_t addr, uint8_t *data, uint32_t len) {
} }
QSPI_CommandTypeDef cmd = { QSPI_CommandTypeDef cmd = {
.Instruction = 0x32, /* Quad input page program with 4 byte address */ .Instruction = 0x32, /* Quad input page program */
.InstructionMode = QSPI_INSTRUCTION_1_LINE, .InstructionMode = QSPI_INSTRUCTION_1_LINE,
.Address = addr, .Address = addr,
.AddressMode = QSPI_ADDRESS_1_LINE, .AddressMode = QSPI_ADDRESS_1_LINE,
@ -241,20 +240,21 @@ int Flash_EraseChip(void) {
return -3; return -3;
} }
APP_DBG_LED_SET(1); APP_DBG_LED_SET(1);
return 0; return 0;
} }
int Flash_Map(void) { int Flash_Map(void) {
QSPI_CommandTypeDef cmd = { QSPI_CommandTypeDef cmd = {
.Instruction = 0xEB, /* Fast read quad IO */ .Instruction = 0xEB, /* Fast read quad IO */
.InstructionMode = QSPI_INSTRUCTION_1_LINE, .InstructionMode = QSPI_INSTRUCTION_1_LINE,
.AddressMode = QSPI_ADDRESS_4_LINES, .AddressMode = QSPI_ADDRESS_4_LINES,
.AddressSize = QSPI_ADDRESS_24_BITS, .AddressSize = QSPI_ADDRESS_24_BITS,
.AlternateByteMode = QSPI_ALTERNATE_BYTES_4_LINES, .AlternateByteMode = QSPI_ALTERNATE_BYTES_4_LINES,
.DataMode = QSPI_DATA_4_LINES, .AlternateBytesSize = QSPI_ALTERNATE_BYTES_8_BITS,
.DummyCycles = 4U, .AlternateBytes = 0xF0,
.DataMode = QSPI_DATA_4_LINES,
.DummyCycles = 4U,
}; };
QSPI_MemoryMappedTypeDef mmap = { QSPI_MemoryMappedTypeDef mmap = {

View File

@ -35,28 +35,28 @@ void HAL_QSPI_MspInit(QSPI_HandleTypeDef* qspiHandle) {
GPIO_InitStruct.Pin = GPIO_PIN_2; GPIO_InitStruct.Pin = GPIO_PIN_2;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI; GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_2; GPIO_InitStruct.Pin = GPIO_PIN_2;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI; GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13; GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI; GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_6; GPIO_InitStruct.Pin = GPIO_PIN_6;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF10_QUADSPI; GPIO_InitStruct.Alternate = GPIO_AF10_QUADSPI;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
} }