diff --git a/src/FlashOperations.c b/src/FlashOperations.c index 80fcd60..7d6bc33 100644 --- a/src/FlashOperations.c +++ b/src/FlashOperations.c @@ -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); diff --git a/src/FlashPrg.c b/src/FlashPrg.c index d200ee3..6b4f8e2 100644 --- a/src/FlashPrg.c +++ b/src/FlashPrg.c @@ -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; } diff --git a/src/stm32h7xx_hal_msp.c b/src/stm32h7xx_hal_msp.c index 4e9444c..48390b7 100644 --- a/src/stm32h7xx_hal_msp.c +++ b/src/stm32h7xx_hal_msp.c @@ -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); }