Selaa lähdekoodia

1.编写QSPI FLASH驱动,芯片型号GD25Q128ESIGR
2.修改注释

zhanghongyi 3 kuukautta sitten
vanhempi
commit
b4cc77da0d

+ 56 - 2
Core/Src/fmc.c

@@ -146,6 +146,7 @@ static void HAL_FMC_MspInit(void){
   PE0   ------> FMC_NBL0
   PE0   ------> FMC_NBL0
   PE1   ------> FMC_NBL1
   PE1   ------> FMC_NBL1
   */
   */
+  /* GPIO_InitStruct */
   GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
   GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
                           |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_11|GPIO_PIN_12
                           |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_11|GPIO_PIN_12
                           |GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
                           |GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
@@ -156,6 +157,7 @@ static void HAL_FMC_MspInit(void){
 
 
   HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
   HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
 
 
+  /* GPIO_InitStruct */
   GPIO_InitStruct.Pin = GPIO_PIN_0;
   GPIO_InitStruct.Pin = GPIO_PIN_0;
   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
   GPIO_InitStruct.Pull = GPIO_NOPULL;
   GPIO_InitStruct.Pull = GPIO_NOPULL;
@@ -164,6 +166,7 @@ static void HAL_FMC_MspInit(void){
 
 
   HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
   HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
 
 
+  /* GPIO_InitStruct */
   GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
   GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
   GPIO_InitStruct.Pull = GPIO_NOPULL;
   GPIO_InitStruct.Pull = GPIO_NOPULL;
@@ -172,6 +175,7 @@ static void HAL_FMC_MspInit(void){
 
 
   HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);
   HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);
 
 
+  /* GPIO_InitStruct */
   GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_4
   GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_4
                           |GPIO_PIN_5|GPIO_PIN_8|GPIO_PIN_15;
                           |GPIO_PIN_5|GPIO_PIN_8|GPIO_PIN_15;
   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
@@ -181,6 +185,7 @@ static void HAL_FMC_MspInit(void){
 
 
   HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
   HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
 
 
+  /* GPIO_InitStruct */
   GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10
   GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10
                           |GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14
                           |GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14
                           |GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1;
                           |GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1;
@@ -191,6 +196,7 @@ static void HAL_FMC_MspInit(void){
 
 
   HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
   HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
 
 
+  /* GPIO_InitStruct */
   GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_14
   GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_14
                           |GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1;
                           |GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1;
   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
@@ -225,10 +231,51 @@ static void HAL_FMC_MspDeInit(void){
     return;
     return;
   }
   }
   FMC_DeInitialized = 1;
   FMC_DeInitialized = 1;
-  /* Peripheral clock disable */
+  /* Peripheral clock enable */
   __HAL_RCC_FMC_CLK_DISABLE();
   __HAL_RCC_FMC_CLK_DISABLE();
 
 
-  /* Deinitialize the same FMC GPIO pins configured in HAL_FMC_MspInit() */
+  /** FMC GPIO Configuration
+  PF0   ------> FMC_A0
+  PF1   ------> FMC_A1
+  PF2   ------> FMC_A2
+  PF3   ------> FMC_A3
+  PF4   ------> FMC_A4
+  PF5   ------> FMC_A5
+  PC0   ------> FMC_SDNWE
+  PH2   ------> FMC_SDCKE0
+  PH3   ------> FMC_SDNE0
+  PF11   ------> FMC_SDNRAS
+  PF12   ------> FMC_A6
+  PF13   ------> FMC_A7
+  PF14   ------> FMC_A8
+  PF15   ------> FMC_A9
+  PG0   ------> FMC_A10
+  PG1   ------> FMC_A11
+  PE7   ------> FMC_D4
+  PE8   ------> FMC_D5
+  PE9   ------> FMC_D6
+  PE10   ------> FMC_D7
+  PE11   ------> FMC_D8
+  PE12   ------> FMC_D9
+  PE13   ------> FMC_D10
+  PE14   ------> FMC_D11
+  PE15   ------> FMC_D12
+  PD8   ------> FMC_D13
+  PD9   ------> FMC_D14
+  PD10   ------> FMC_D15
+  PD14   ------> FMC_D0
+  PD15   ------> FMC_D1
+  PG2   ------> FMC_A12
+  PG4   ------> FMC_BA0
+  PG5   ------> FMC_BA1
+  PG8   ------> FMC_SDCLK
+  PD0   ------> FMC_D2
+  PD1   ------> FMC_D3
+  PG15   ------> FMC_SDNCAS
+  PE0   ------> FMC_NBL0
+  PE1   ------> FMC_NBL1
+  */
+
   HAL_GPIO_DeInit(GPIOF, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
   HAL_GPIO_DeInit(GPIOF, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
                           |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_11|GPIO_PIN_12
                           |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_11|GPIO_PIN_12
                           |GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15);
                           |GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15);
@@ -261,3 +308,10 @@ void HAL_SDRAM_MspDeInit(SDRAM_HandleTypeDef* sdramHandle){
 
 
   /* USER CODE END SDRAM_MspDeInit 1 */
   /* USER CODE END SDRAM_MspDeInit 1 */
 }
 }
+/**
+  * @}
+  */
+
+/**
+  * @}
+  */

+ 30 - 3
Core/Src/ltdc.c

@@ -26,6 +26,7 @@
 
 
 LTDC_HandleTypeDef hltdc;
 LTDC_HandleTypeDef hltdc;
 
 
+/* LTDC init function */
 void MX_LTDC_Init(void)
 void MX_LTDC_Init(void)
 {
 {
 
 
@@ -114,7 +115,7 @@ void HAL_LTDC_MspInit(LTDC_HandleTypeDef* ltdcHandle)
 
 
   /* USER CODE END LTDC_MspInit 0 */
   /* USER CODE END LTDC_MspInit 0 */
 
 
-  /** Configure PLL3 as the LTDC pixel clock source (64/32*129/8 = 32.25MHz)
+  /** Initializes the peripherals clock
   */
   */
     PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
     PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
     PeriphClkInitStruct.PLL3.PLL3M = 32;
     PeriphClkInitStruct.PLL3.PLL3M = 32;
@@ -130,6 +131,7 @@ void HAL_LTDC_MspInit(LTDC_HandleTypeDef* ltdcHandle)
       Error_Handler();
       Error_Handler();
     }
     }
 
 
+    /* LTDC clock enable */
     __HAL_RCC_LTDC_CLK_ENABLE();
     __HAL_RCC_LTDC_CLK_ENABLE();
 
 
     __HAL_RCC_GPIOI_CLK_ENABLE();
     __HAL_RCC_GPIOI_CLK_ENABLE();
@@ -148,7 +150,7 @@ void HAL_LTDC_MspInit(LTDC_HandleTypeDef* ltdcHandle)
     PH12     ------> LTDC_R6
     PH12     ------> LTDC_R6
     PG6     ------> LTDC_R7
     PG6     ------> LTDC_R7
     PG7     ------> LTDC_CLK
     PG7     ------> LTDC_CLK
-    PA8     ------> LTDC_B3  (AF13, other LTDC pins use AF14)
+    PA8     ------> LTDC_B3
     PH13     ------> LTDC_G2
     PH13     ------> LTDC_G2
     PH14     ------> LTDC_G3
     PH14     ------> LTDC_G3
     PH15     ------> LTDC_G4
     PH15     ------> LTDC_G4
@@ -214,9 +216,34 @@ void HAL_LTDC_MspDeInit(LTDC_HandleTypeDef* ltdcHandle)
   /* USER CODE BEGIN LTDC_MspDeInit 0 */
   /* USER CODE BEGIN LTDC_MspDeInit 0 */
 
 
   /* USER CODE END LTDC_MspDeInit 0 */
   /* USER CODE END LTDC_MspDeInit 0 */
+    /* Peripheral clock disable */
     __HAL_RCC_LTDC_CLK_DISABLE();
     __HAL_RCC_LTDC_CLK_DISABLE();
 
 
-    /* Deinitialize the same LTDC GPIO pins configured in HAL_LTDC_MspInit() */
+    /**LTDC GPIO Configuration
+    PI9     ------> LTDC_VSYNC
+    PI10     ------> LTDC_HSYNC
+    PF10     ------> LTDC_DE
+    PH8     ------> LTDC_R2
+    PH9     ------> LTDC_R3
+    PH10     ------> LTDC_R4
+    PH11     ------> LTDC_R5
+    PH12     ------> LTDC_R6
+    PG6     ------> LTDC_R7
+    PG7     ------> LTDC_CLK
+    PA8     ------> LTDC_B3
+    PH13     ------> LTDC_G2
+    PH14     ------> LTDC_G3
+    PH15     ------> LTDC_G4
+    PI0     ------> LTDC_G5
+    PI1     ------> LTDC_G6
+    PI2     ------> LTDC_G7
+    PG13     ------> LTDC_R0
+    PG14     ------> LTDC_B0
+    PI4     ------> LTDC_B4
+    PI5     ------> LTDC_B5
+    PI6     ------> LTDC_B6
+    PI7     ------> LTDC_B7
+    */
     HAL_GPIO_DeInit(GPIOI, GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_0|GPIO_PIN_1
     HAL_GPIO_DeInit(GPIOI, GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_0|GPIO_PIN_1
                           |GPIO_PIN_2|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6
                           |GPIO_PIN_2|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6
                           |GPIO_PIN_7);
                           |GPIO_PIN_7);

+ 165 - 2
Core/Src/main.c

@@ -28,9 +28,11 @@
 /* Private includes ----------------------------------------------------------*/
 /* Private includes ----------------------------------------------------------*/
 /* USER CODE BEGIN Includes */
 /* USER CODE BEGIN Includes */
 #include "stdio.h"
 #include "stdio.h"
+#include "string.h"
 #include "Int_sdram.h"
 #include "Int_sdram.h"
 #include "Int_mpu.h"
 #include "Int_mpu.h"
 #include "Int_lcd.h"
 #include "Int_lcd.h"
+#include "Int_flash.h"
 /* USER CODE END Includes */
 /* USER CODE END Includes */
 
 
 /* Private typedef -----------------------------------------------------------*/
 /* Private typedef -----------------------------------------------------------*/
@@ -58,12 +60,168 @@
 void SystemClock_Config(void);
 void SystemClock_Config(void);
 static void MPU_Config(void);
 static void MPU_Config(void);
 /* USER CODE BEGIN PFP */
 /* USER CODE BEGIN PFP */
-
+void Int_flash_test(void);
 /* USER CODE END PFP */
 /* USER CODE END PFP */
 
 
 /* Private user code ---------------------------------------------------------*/
 /* Private user code ---------------------------------------------------------*/
 /* USER CODE BEGIN 0 */
 /* USER CODE BEGIN 0 */
-
+void Int_flash_test(void)
+{
+    uint8_t wbuf[256];
+    uint8_t rbuf[256];
+    uint16_t id;
+    uint32_t i;
+    uint8_t pass;
+
+    printf("\r\n======== QSPI FLASH TEST ========\r\n");
+
+    /* 1. Initialize and read chip ID */
+    id = Int_flash_read_id();
+    printf("Raw ID (0x90): 0x%04X\r\n", id);
+
+    if (Int_flash_init() != 0)
+    {
+        printf("[FAIL] Int_flash_init\r\n");
+        printf("ID = 0x%04X (expected 0x%04X)\r\n",
+               (unsigned int)Int_flash_read_id(), (unsigned int)INT_FLASH_ID_GD25Q128);
+        return;
+    }
+    id = Int_flash_read_id();
+    printf("Flash ID: 0x%04X\r\n", id);
+    if (id != INT_FLASH_ID_GD25Q128)
+    {
+        printf("[WARN] Expected GD25Q128 (0x%04X)\r\n", INT_FLASH_ID_GD25Q128);
+    }
+
+    /* 2. Read the first 16 bytes of flash (diagnostic, no erase) */
+    Int_flash_read(rbuf, 0, 16);
+    printf("First 16 bytes: ");
+    for (i = 0; i < 16; i++)
+    {
+        printf("%02X ", rbuf[i]);
+    }
+    printf("\r\n");
+
+    /* 3. Erase sector 0 (4KB) and verify all bytes = 0xFF */
+    Int_flash_erase_sector(0);
+    Int_flash_read(rbuf, 0, 256);
+    pass = 1;
+    for (i = 0; i < 256; i++)
+    {
+        if (rbuf[i] != 0xFF)
+        {
+            pass = 0;
+            break;
+        }
+    }
+    printf("Sector0 erase verify: %s\r\n", pass ? "PASS" : "FAIL");
+
+    /* 4. Write + readback within a single page (no cross-page) */
+    for (i = 0; i < 128; i++)
+    {
+        wbuf[i] = (uint8_t)i;
+    }
+    Int_flash_write(wbuf, 0, 128);
+    Int_flash_read(rbuf, 0, 128);
+    pass = 1;
+    for (i = 0; i < 128; i++)
+    {
+        if (rbuf[i] != wbuf[i])
+        {
+            pass = 0;
+            break;
+        }
+    }
+    printf("Write/Read 128B (page 0): %s\r\n", pass ? "PASS" : "FAIL");
+
+    /* 5. Write spanning page boundary (page 0 ends at addr 255) */
+    for (i = 0; i < 64; i++)
+    {
+        wbuf[i] = (uint8_t)(0xA0 + i);
+    }
+    Int_flash_write(wbuf, 200, 64);   /* spans address 200..263 (crosses page 0/1) */
+    Int_flash_read(rbuf, 200, 64);
+    pass = 1;
+    for (i = 0; i < 64; i++)
+    {
+        if (rbuf[i] != wbuf[i])
+        {
+            pass = 0;
+            break;
+        }
+    }
+    printf("Write/Read 64B (cross-page): %s\r\n", pass ? "PASS" : "FAIL");
+
+    /* 6. Write spanning sector boundary (sector0 lasts 0..4095) */
+    for (i = 0; i < 32; i++)
+    {
+        wbuf[i] = (uint8_t)(0x50 + i);
+    }
+    Int_flash_write(wbuf, 4080, 32);  /* spans address 4080..4111 (crosses sector 0/1) */
+    Int_flash_read(rbuf, 4080, 32);
+    pass = 1;
+    for (i = 0; i < 32; i++)
+    {
+        if (rbuf[i] != wbuf[i])
+        {
+            pass = 0;
+            break;
+        }
+    }
+    printf("Write/Read 32B (cross-sector): %s\r\n", pass ? "PASS" : "FAIL");
+
+    /* 7. Rewrite same location after erase (address already erased to 0xFF) */
+    for (i = 0; i < 32; i++)
+    {
+        wbuf[i] = (uint8_t)(0xC0 + i);
+    }
+    Int_flash_write(wbuf, 16, 32);
+    Int_flash_read(rbuf, 16, 32);
+    pass = 1;
+    for (i = 0; i < 32; i++)
+    {
+        if (rbuf[i] != wbuf[i])
+        {
+            pass = 0;
+            break;
+        }
+    }
+    printf("Write/Read 32B (re-write sector0): %s\r\n", pass ? "PASS" : "FAIL");
+
+    /* 8. Write full 256B page and read back */
+    for (i = 0; i < 256; i++)
+    {
+        wbuf[i] = (uint8_t)(i ^ 0x5A);
+    }
+    Int_flash_write(wbuf, 4096, 256);  /* sector 1 start */
+    Int_flash_read(rbuf, 4096, 256);
+    pass = 1;
+    for (i = 0; i < 256; i++)
+    {
+        if (rbuf[i] != wbuf[i])
+        {
+            pass = 0;
+            break;
+        }
+    }
+    printf("Write/Read 256B page: %s\r\n", pass ? "PASS" : "FAIL");
+
+    /* 9. Block erase (64KB) test on block 1 */
+    Int_flash_erase_block(1);
+    Int_flash_read(rbuf, 0x10000, 64);
+    pass = 1;
+    for (i = 0; i < 64; i++)
+    {
+        if (rbuf[i] != 0xFF)
+        {
+            pass = 0;
+            break;
+        }
+    }
+    printf("Block1 erase verify: %s\r\n", pass ? "PASS" : "FAIL");
+
+    printf("======== QSPI FLASH TEST DONE ========\r\n\r\n");
+}
 /* USER CODE END 0 */
 /* USER CODE END 0 */
 
 
 /**
 /**
@@ -80,6 +238,8 @@ int main(void)
   /* MPU Configuration--------------------------------------------------------*/
   /* MPU Configuration--------------------------------------------------------*/
   MPU_Config();
   MPU_Config();
 
 
+  /* Enable the CPU Cache */
+
   /* Enable I-Cache---------------------------------------------------------*/
   /* Enable I-Cache---------------------------------------------------------*/
   SCB_EnableICache();
   SCB_EnableICache();
 
 
@@ -113,6 +273,7 @@ int main(void)
   printf("hello h743\r\n");
   printf("hello h743\r\n");
   Int_sdram_init();
   Int_sdram_init();
   Int_sdram_test();
   Int_sdram_test();
+  Int_flash_test();
   Int_lcd_init();
   Int_lcd_init();
   Int_lcd_clear(LCD_COLOR_RED);
   Int_lcd_clear(LCD_COLOR_RED);
   printf("System Init OK\r\n");
   printf("System Init OK\r\n");
@@ -198,6 +359,8 @@ void SystemClock_Config(void)
 
 
 /* USER CODE END 4 */
 /* USER CODE END 4 */
 
 
+ /* MPU Configuration */
+
 void MPU_Config(void)
 void MPU_Config(void)
 {
 {
 
 

+ 10 - 10
Core/Src/quadspi.c

@@ -40,9 +40,9 @@ void MX_QUADSPI_Init(void)
   hqspi.Instance = QUADSPI;
   hqspi.Instance = QUADSPI;
   hqspi.Init.ClockPrescaler = 2;
   hqspi.Init.ClockPrescaler = 2;
   hqspi.Init.FifoThreshold = 4;
   hqspi.Init.FifoThreshold = 4;
-  hqspi.Init.SampleShifting = QSPI_SAMPLE_SHIFTING_NONE;
+  hqspi.Init.SampleShifting = QSPI_SAMPLE_SHIFTING_HALFCYCLE;
   hqspi.Init.FlashSize = 23;
   hqspi.Init.FlashSize = 23;
-  hqspi.Init.ChipSelectHighTime = QSPI_CS_HIGH_TIME_1_CYCLE;
+  hqspi.Init.ChipSelectHighTime = QSPI_CS_HIGH_TIME_4_CYCLE;
   hqspi.Init.ClockMode = QSPI_CLOCK_MODE_0;
   hqspi.Init.ClockMode = QSPI_CLOCK_MODE_0;
   hqspi.Init.FlashID = QSPI_FLASH_ID_1;
   hqspi.Init.FlashID = QSPI_FLASH_ID_1;
   hqspi.Init.DualFlash = QSPI_DUALFLASH_DISABLE;
   hqspi.Init.DualFlash = QSPI_DUALFLASH_DISABLE;
@@ -91,29 +91,29 @@ void HAL_QSPI_MspInit(QSPI_HandleTypeDef* qspiHandle)
     */
     */
     GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
     GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
-    GPIO_InitStruct.Pull = GPIO_NOPULL;
-    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
+    GPIO_InitStruct.Pull = GPIO_PULLUP;
+    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
     GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
     GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
     HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
     HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
 
 
     GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
     GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
-    GPIO_InitStruct.Pull = GPIO_NOPULL;
-    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
+    GPIO_InitStruct.Pull = GPIO_PULLUP;
+    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
     GPIO_InitStruct.Alternate = GPIO_AF10_QUADSPI;
     GPIO_InitStruct.Alternate = GPIO_AF10_QUADSPI;
     HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
     HAL_GPIO_Init(GPIOF, &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.Speed = GPIO_SPEED_FREQ_LOW;
+    GPIO_InitStruct.Pull = GPIO_PULLUP;
+    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
     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_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.Speed = GPIO_SPEED_FREQ_LOW;
+    GPIO_InitStruct.Pull = GPIO_PULLUP;
+    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
     GPIO_InitStruct.Alternate = GPIO_AF10_QUADSPI;
     GPIO_InitStruct.Alternate = GPIO_AF10_QUADSPI;
     HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
     HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
 
 

+ 56 - 0
Int/Inc/Int_flash.h

@@ -0,0 +1,56 @@
+#ifndef __INT_FLASH_H
+#define __INT_FLASH_H
+
+#include "main.h"
+
+/* GD25Q128:128Mbit = 16MB */
+#define INT_FLASH_SIZE              0x1000000   /* 16MB */
+#define INT_FLASH_SECTOR_SIZE       0x1000      /* 4KB 扇区 */
+#define INT_FLASH_BLOCK_SIZE        0x10000     /* 64KB 块 */
+#define INT_FLASH_PAGE_SIZE         0x100       /* 256B 页 */
+
+/* 厂商/设备 ID */
+#define INT_FLASH_ID_GD25Q128       0xC817      /* GD25Q128 */
+#define INT_FLASH_ID_W25Q128        0xEF17      /* W25Q128  */
+
+/* SPI NOR Flash 命令 */
+#define INT_FLASH_CMD_WRITE_ENABLE          0x06
+#define INT_FLASH_CMD_WRITE_DISABLE         0x04
+#define INT_FLASH_CMD_READ_STATUS_1         0x05
+#define INT_FLASH_CMD_READ_STATUS_2         0x35
+#define INT_FLASH_CMD_READ_STATUS_3         0x15
+#define INT_FLASH_CMD_WRITE_STATUS_1        0x01
+#define INT_FLASH_CMD_WRITE_STATUS_2        0x31
+#define INT_FLASH_CMD_WRITE_STATUS_3        0x11
+#define INT_FLASH_CMD_READ_DATA             0x03
+#define INT_FLASH_CMD_FAST_READ             0x0B
+#define INT_FLASH_CMD_FAST_READ_QUAD        0xEB
+#define INT_FLASH_CMD_PAGE_PROGRAM          0x02
+#define INT_FLASH_CMD_PAGE_PROGRAM_QUAD     0x32
+#define INT_FLASH_CMD_BLOCK_ERASE           0xD8
+#define INT_FLASH_CMD_SECTOR_ERASE          0x20
+#define INT_FLASH_CMD_CHIP_ERASE            0xC7
+#define INT_FLASH_CMD_MANUF_DEVICE_ID       0x90
+#define INT_FLASH_CMD_JEDEC_ID              0x9F
+#define INT_FLASH_CMD_ENABLE_4BYTE_ADDR     0xB7
+#define INT_FLASH_CMD_EXIT_4BYTE_ADDR       0xE9
+#define INT_FLASH_CMD_SOFT_RESET            0x99
+
+/* 初始化 QSPI 与 Flash,并检测芯片 ID */
+uint8_t  Int_flash_init(void);
+/* 读取厂商/设备 ID(0x90 返回 2 字节,GD25Q128 = 0xC817) */
+uint16_t Int_flash_read_id(void);
+/* 读取数据(最多 65535 字节) */
+uint8_t  Int_flash_read(uint8_t *pbuf, uint32_t addr, uint32_t datalen);
+/* 写入数据,自动执行扇区擦除(安全写入) */
+uint8_t  Int_flash_write(uint8_t *pbuf, uint32_t addr, uint32_t datalen);
+/* 擦除一个 4KB 扇区(按扇区序号) */
+uint8_t  Int_flash_erase_sector(uint32_t saddr);
+/* 擦除一个 64KB 块(按块序号) */
+uint8_t  Int_flash_erase_block(uint32_t baddr);
+/* 整片擦除 */
+uint8_t  Int_flash_erase_chip(void);
+/* 等待 Flash 空闲(忙时阻塞直到空闲) */
+void     Int_flash_wait_busy(void);
+
+#endif

+ 4 - 4
Int/Inc/Int_lcd.h

@@ -3,11 +3,11 @@
 
 
 #include "main.h"
 #include "main.h"
 
 
-#define INT_LCD_WIDTH           800
-#define INT_LCD_HEIGHT          480
-#define INT_LCD_FRAME_BUF_ADDR  ((uint32_t)(0xC0000000))
+#define INT_LCD_WIDTH           800          /* 屏幕宽度 */
+#define INT_LCD_HEIGHT          480          /* 屏幕高度 */
+#define INT_LCD_FRAME_BUF_ADDR  ((uint32_t)(0xC0000000))   /* 帧缓冲地址(SDRAM 起始) */
 
 
-/* RGB565 color defines */
+/* RGB565 颜色定义 */
 #define LCD_COLOR_WHITE         0xFFFF
 #define LCD_COLOR_WHITE         0xFFFF
 #define LCD_COLOR_BLACK         0x0000
 #define LCD_COLOR_BLACK         0x0000
 #define LCD_COLOR_RED           0xF800
 #define LCD_COLOR_RED           0xF800

+ 2 - 2
Int/Inc/Int_sdram.h

@@ -3,8 +3,8 @@
 
 
 #include "main.h"
 #include "main.h"
 
 
-#define INT_SDRAM_BASE_ADDR     ((uint32_t)(0xC0000000))
-#define INT_SDRAM_SIZE          ((uint32_t)(32 * 1024 * 1024))
+#define INT_SDRAM_BASE_ADDR     ((uint32_t)(0xC0000000))   /* SDRAM 起始地址 */
+#define INT_SDRAM_SIZE          ((uint32_t)(32 * 1024 * 1024))   /* SDRAM 大小 32MB */
 
 
 void Int_sdram_init(void);
 void Int_sdram_init(void);
 void Int_sdram_test(void);
 void Int_sdram_test(void);

+ 323 - 0
Int/Src/Int_flash.c

@@ -0,0 +1,323 @@
+#include "Int_flash.h"
+#include "quadspi.h"
+#include <string.h>
+
+extern QSPI_HandleTypeDef hqspi;
+
+/* SPI Flash 地址位数:2 = 24位地址,3 = 32位地址(探测 ID 后更新) */
+static volatile uint8_t g_int_flash_addrw = 2;
+
+/* 4KB 扇区读-改-写缓冲区 */
+static uint8_t g_int_flash_buf[4096];
+
+/*
+ * 发送一条 QSPI 命令
+ * mode 位域定义:
+ *   [1:0] 指令模式 (0=无, 1=单线, 2=双线, 3=四线)
+ *   [3:2] 地址模式 (0=无, 1=单线, 2=双线, 3=四线)
+ *   [5:4] 地址宽度 (0=8位, 1=16位, 2=24位, 3=32位)
+ *   [7:6] 数据模式 (0=无, 1=单线, 2=双线, 3=四线)
+ */
+static void Int_flash_send_cmd(uint8_t cmd, uint32_t addr, uint8_t mode, uint8_t dummy)
+{
+    QSPI_CommandTypeDef qc = {0};
+
+    qc.Instruction = cmd;
+    qc.Address = addr;
+    qc.DummyCycles = dummy;
+
+    switch ((mode >> 0) & 0x03)
+    {
+        case 1: qc.InstructionMode = QSPI_INSTRUCTION_1_LINE; break;
+        case 2: qc.InstructionMode = QSPI_INSTRUCTION_2_LINES; break;
+        case 3: qc.InstructionMode = QSPI_INSTRUCTION_4_LINES; break;
+        default: qc.InstructionMode = QSPI_INSTRUCTION_NONE; break;
+    }
+
+    switch ((mode >> 2) & 0x03)
+    {
+        case 1: qc.AddressMode = QSPI_ADDRESS_1_LINE; break;
+        case 2: qc.AddressMode = QSPI_ADDRESS_2_LINES; break;
+        case 3: qc.AddressMode = QSPI_ADDRESS_4_LINES; break;
+        default: qc.AddressMode = QSPI_ADDRESS_NONE; break;
+    }
+
+    switch ((mode >> 4) & 0x03)
+    {
+        case 0: qc.AddressSize = QSPI_ADDRESS_8_BITS; break;
+        case 1: qc.AddressSize = QSPI_ADDRESS_16_BITS; break;
+        case 2: qc.AddressSize = QSPI_ADDRESS_24_BITS; break;
+        default: qc.AddressSize = QSPI_ADDRESS_32_BITS; break;
+    }
+
+    switch ((mode >> 6) & 0x03)
+    {
+        case 1: qc.DataMode = QSPI_DATA_1_LINE; break;
+        case 2: qc.DataMode = QSPI_DATA_2_LINES; break;
+        case 3: qc.DataMode = QSPI_DATA_4_LINES; break;
+        default: qc.DataMode = QSPI_DATA_NONE; break;
+    }
+
+    qc.SIOOMode = QSPI_SIOO_INST_EVERY_CMD;
+    qc.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE;
+    qc.DdrMode = QSPI_DDR_MODE_DISABLE;
+    qc.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY;
+
+    HAL_QSPI_Command(&hqspi, &qc, 5000);
+}
+
+/* QSPI 接收 datalen 个字节存入 buf */
+static uint8_t Int_flash_receive(uint8_t *buf, uint32_t datalen)
+{
+    hqspi.Instance->DLR = datalen - 1;
+    if (HAL_QSPI_Receive(&hqspi, buf, 5000) == HAL_OK)
+    {
+        return 0;
+    }
+    return 1;
+}
+
+/* QSPI 从 buf 发送 datalen 个字节 */
+static uint8_t Int_flash_transmit(uint8_t *buf, uint32_t datalen)
+{
+    hqspi.Instance->DLR = datalen - 1;
+    if (HAL_QSPI_Transmit(&hqspi, buf, 5000) == HAL_OK)
+    {
+        return 0;
+    }
+    return 1;
+}
+
+/* 写使能(置位 SR1 的 WEL 位) */
+static void Int_flash_write_enable(void)
+{
+    Int_flash_send_cmd(INT_FLASH_CMD_WRITE_ENABLE, 0, 0x01, 0);
+}
+
+/* 写禁止(清除 SR1 的 WEL 位) */
+//static void Int_flash_write_disable(void)
+//{
+//    Int_flash_send_cmd(INT_FLASH_CMD_WRITE_DISABLE, 0, 0x01, 0);
+//}
+
+/* 读取状态寄存器(1~3),数据单线模式 */
+static uint8_t Int_flash_read_sr(uint8_t regno)
+{
+    uint8_t byte = 0;
+    uint8_t command = INT_FLASH_CMD_READ_STATUS_1;
+
+    switch (regno)
+    {
+        case 2: command = INT_FLASH_CMD_READ_STATUS_2; break;
+        case 3: command = INT_FLASH_CMD_READ_STATUS_3; break;
+        default: command = INT_FLASH_CMD_READ_STATUS_1; break;
+    }
+
+    Int_flash_send_cmd(command, 0, 0x41, 0);   /* 单线数据,无地址,单线指令 */
+    Int_flash_receive(&byte, 1);
+    return byte;
+}
+
+/* 写状态寄存器(1~3),数据单线模式 */
+static void Int_flash_write_sr(uint8_t regno, uint8_t sr)
+{
+    uint8_t command = INT_FLASH_CMD_WRITE_STATUS_1;
+
+    switch (regno)
+    {
+        case 2: command = INT_FLASH_CMD_WRITE_STATUS_2; break;
+        case 3: command = INT_FLASH_CMD_WRITE_STATUS_3; break;
+        default: command = INT_FLASH_CMD_WRITE_STATUS_1; break;
+    }
+
+    Int_flash_send_cmd(command, 0, 0x41, 0);   /* 单线数据,无地址,单线指令 */
+    Int_flash_transmit(&sr, 1);
+}
+
+/* 使能 QE 位(SR2 bit1),以使用 IO2/IO3 四线模式 */
+static void Int_flash_qe_enable(void)
+{
+    uint8_t stareg2 = Int_flash_read_sr(2);
+
+    if ((stareg2 & 0x02) == 0)
+    {
+        Int_flash_write_enable();
+        stareg2 |= (1 << 1);
+        Int_flash_write_sr(2, stareg2);
+    }
+}
+
+/* 编程一个页(最多 256 字节),四线 I/O,不跨页边界 */
+static void Int_flash_write_page(uint8_t *pbuf, uint32_t addr, uint16_t datalen)
+{
+    Int_flash_write_enable();
+    /* 四线数据 | 24/32位单线地址 | 单线指令 */
+    Int_flash_send_cmd(INT_FLASH_CMD_PAGE_PROGRAM_QUAD, addr,
+                       (3 << 6) | (g_int_flash_addrw << 4) | (1 << 2) | (1 << 0), 0);
+    Int_flash_transmit(pbuf, datalen);
+    Int_flash_wait_busy();
+}
+
+void Int_flash_wait_busy(void)
+{
+    while ((Int_flash_read_sr(1) & 0x01) == 0x01);
+}
+
+uint8_t Int_flash_init(void)
+{
+    /* QSPI 外设已由 MX_QUADSPI_Init() 提前初始化 */
+
+    Int_flash_qe_enable();
+    g_int_flash_addrw = 2;
+
+    if (Int_flash_read_id() == INT_FLASH_ID_GD25Q128)
+    {
+        return 0;
+    }
+    return 1;
+}
+
+uint16_t Int_flash_read_id(void)
+{
+    uint8_t temp[2];
+    uint16_t deviceid;
+
+    /* 单线数据 2B | 24位单线地址 | 单线指令 */
+    Int_flash_send_cmd(INT_FLASH_CMD_MANUF_DEVICE_ID, 0,
+                       (1 << 6) | (2 << 4) | (1 << 2) | (1 << 0), 0);
+    Int_flash_receive(temp, 2);
+    deviceid = (uint16_t)((temp[0] << 8) | temp[1]);
+
+    return deviceid;
+}
+
+uint8_t Int_flash_read(uint8_t *pbuf, uint32_t addr, uint32_t datalen)
+{
+    /* 四线数据 | 24/32位四线地址 | 单线指令,6 个空转周期 */
+    Int_flash_send_cmd(INT_FLASH_CMD_FAST_READ_QUAD, addr,
+                       (3 << 6) | (g_int_flash_addrw << 4) | (3 << 2) | (1 << 0), 6);
+    return Int_flash_receive(pbuf, datalen);
+}
+
+uint8_t Int_flash_erase_sector(uint32_t saddr)
+{
+    uint32_t byteaddr = saddr * INT_FLASH_SECTOR_SIZE;
+
+    Int_flash_write_enable();
+    Int_flash_wait_busy();
+    /* 无数据 | 24/32位单线地址 | 单线指令 */
+    Int_flash_send_cmd(INT_FLASH_CMD_SECTOR_ERASE, byteaddr,
+                       (0 << 6) | (g_int_flash_addrw << 4) | (1 << 2) | (1 << 0), 0);
+    Int_flash_wait_busy();
+    return 0;
+}
+
+uint8_t Int_flash_erase_block(uint32_t baddr)
+{
+    uint32_t byteaddr = baddr * INT_FLASH_BLOCK_SIZE;
+
+    Int_flash_write_enable();
+    Int_flash_wait_busy();
+    /* 无数据 | 24/32位单线地址 | 单线指令 */
+    Int_flash_send_cmd(INT_FLASH_CMD_BLOCK_ERASE, byteaddr,
+                       (0 << 6) | (g_int_flash_addrw << 4) | (1 << 2) | (1 << 0), 0);
+    Int_flash_wait_busy();
+    return 0;
+}
+
+uint8_t Int_flash_erase_chip(void)
+{
+    Int_flash_write_enable();
+    Int_flash_wait_busy();
+    /* 无数据 | 无地址 | 单线指令 */
+    Int_flash_send_cmd(INT_FLASH_CMD_CHIP_ERASE, 0, 0x01, 0);
+    Int_flash_wait_busy();
+    return 0;
+}
+
+/* 按页边界逐段写入(不跨页),确保每个 PAGE_PROGRAM 都在单个 256 字节页内 */
+static void Int_flash_write_nocheck(uint8_t *pbuf, uint32_t addr, uint32_t datalen)
+{
+    uint16_t pagerem;
+
+    pagerem = INT_FLASH_PAGE_SIZE - (addr % INT_FLASH_PAGE_SIZE);
+    if (datalen <= pagerem)
+    {
+        pagerem = datalen;
+    }
+
+    while (1)
+    {
+        Int_flash_write_page(pbuf, addr, pagerem);
+
+        if (datalen == pagerem)
+        {
+            break;
+        }
+
+        pbuf += pagerem;
+        addr += pagerem;
+        datalen -= pagerem;
+        pagerem = (datalen > INT_FLASH_PAGE_SIZE) ? INT_FLASH_PAGE_SIZE : datalen;
+    }
+}
+
+uint8_t Int_flash_write(uint8_t *pbuf, uint32_t addr, uint32_t datalen)
+{
+    uint32_t secpos;
+    uint16_t secoff;
+    uint16_t secremain;
+    uint16_t i;
+    uint8_t *flash_buf = g_int_flash_buf;
+
+    secpos = addr / INT_FLASH_SECTOR_SIZE;
+    secoff = addr % INT_FLASH_SECTOR_SIZE;
+    secremain = INT_FLASH_SECTOR_SIZE - secoff;
+
+    if (datalen <= secremain)
+    {
+        secremain = datalen;
+    }
+
+    while (1)
+    {
+        Int_flash_read(flash_buf, secpos * INT_FLASH_SECTOR_SIZE, INT_FLASH_SECTOR_SIZE);
+
+        for (i = 0; i < secremain; i++)
+        {
+            if (flash_buf[secoff + i] != 0xFF)
+            {
+                break;
+            }
+        }
+
+        if (i < secremain)
+        {
+            Int_flash_erase_sector(secpos);
+            for (i = 0; i < secremain; i++)
+            {
+                flash_buf[secoff + i] = pbuf[i];
+            }
+            Int_flash_write_nocheck(flash_buf, secpos * INT_FLASH_SECTOR_SIZE,
+                                    INT_FLASH_SECTOR_SIZE);
+        }
+        else
+        {
+            Int_flash_write_nocheck(pbuf, addr, secremain);
+        }
+
+        if (datalen == secremain)
+        {
+            break;
+        }
+
+        secpos++;
+        secoff = 0;
+        pbuf += secremain;
+        addr += secremain;
+        datalen -= secremain;
+        secremain = (datalen > INT_FLASH_SECTOR_SIZE) ? INT_FLASH_SECTOR_SIZE : datalen;
+    }
+
+    return 0;
+}

+ 2 - 2
Int/Src/Int_lcd.c

@@ -17,7 +17,7 @@ void Int_lcd_bl_off(void)
 
 
 static void Int_lcd_reset(void)
 static void Int_lcd_reset(void)
 {
 {
-    /* LCD hardware reset: HIGH -> LOW(50ms) -> HIGH(200ms) */
+    /* LCD 硬件复位:高 -> 低(50ms) -> 高(200ms) */
     HAL_GPIO_WritePin(GPIOD, GPIO_PIN_11, GPIO_PIN_SET);
     HAL_GPIO_WritePin(GPIOD, GPIO_PIN_11, GPIO_PIN_SET);
     HAL_Delay(10);
     HAL_Delay(10);
     HAL_GPIO_WritePin(GPIOD, GPIO_PIN_11, GPIO_PIN_RESET);
     HAL_GPIO_WritePin(GPIOD, GPIO_PIN_11, GPIO_PIN_RESET);
@@ -37,7 +37,7 @@ static void Int_lcd_layer_init(void)
     layer.PixelFormat = LTDC_PIXEL_FORMAT_RGB565;
     layer.PixelFormat = LTDC_PIXEL_FORMAT_RGB565;
     layer.Alpha = 255;
     layer.Alpha = 255;
     layer.Alpha0 = 0;
     layer.Alpha0 = 0;
-    /* PAxCA blending mode: alpha factor / constant alpha (matching reference) */
+    /* PAxCA 混合模式:alpha 因子 / 常量 alpha */
     layer.BlendingFactor1 = (uint32_t)6 << 8;
     layer.BlendingFactor1 = (uint32_t)6 << 8;
     layer.BlendingFactor2 = (uint32_t)7;
     layer.BlendingFactor2 = (uint32_t)7;
     layer.FBStartAdress = INT_LCD_FRAME_BUF_ADDR;
     layer.FBStartAdress = INT_LCD_FRAME_BUF_ADDR;

+ 12 - 12
Int/Src/Int_mpu.c

@@ -1,15 +1,15 @@
 #include "Int_mpu.h"
 #include "Int_mpu.h"
 
 
 /*
 /*
- * Configure a single MPU region.
- * base  - region base address
- * size  - region size (MPU_REGION_SIZE_xxx)
- * rnum  - region number (MPU_REGION_NUMBERx)
- * de    - DisableExec (0 = instruction fetch allowed)
- * ap    - access permission (MPU_REGION_FULL_ACCESS, etc.)
- * sen   - IsShareable (MPU_ACCESS_SHAREABLE/NOT_SHAREABLE)
- * cen   - IsCacheable (MPU_ACCESS_CACHEABLE/NOT_CACHEABLE)
- * ben   - IsBufferable (MPU_ACCESS_BUFFERABLE/NOT_BUFFERABLE)
+ * 配置单个 MPU 区域
+ * base  - 区域基地址
+ * size  - 区域大小(MPU_REGION_SIZE_xxx)
+ * rnum  - 区域编号(MPU_REGION_NUMBERx)
+ * de    - DisableExec(0 = 允许取指)
+ * ap    - 访问权限(MPU_REGION_FULL_ACCESS 等)
+ * sen   - 是否可共享(MPU_ACCESS_SHAREABLE/NOT_SHAREABLE)
+ * cen   - 是否可缓存(MPU_ACCESS_CACHEABLE/NOT_CACHEABLE)
+ * ben   - 是否可缓冲(MPU_ACCESS_BUFFERABLE/NOT_BUFFERABLE)
  */
  */
 static void Int_mpu_set_region(uint32_t base, uint32_t size, uint8_t rnum,
 static void Int_mpu_set_region(uint32_t base, uint32_t size, uint8_t rnum,
                                 uint8_t de, uint8_t ap,
                                 uint8_t de, uint8_t ap,
@@ -47,7 +47,7 @@ void Int_mpu_config(void)
                        MPU_REGION_FULL_ACCESS, MPU_ACCESS_NOT_SHAREABLE,
                        MPU_REGION_FULL_ACCESS, MPU_ACCESS_NOT_SHAREABLE,
                        MPU_ACCESS_CACHEABLE, MPU_ACCESS_BUFFERABLE);
                        MPU_ACCESS_CACHEABLE, MPU_ACCESS_BUFFERABLE);
 
 
-    /* SRAM1~3 288KB (MPU region 512KB) */
+    /* SRAM1~3 288KB(MPU 区域 512KB) */
     Int_mpu_set_region(0x30000000, MPU_REGION_SIZE_512KB, MPU_REGION_NUMBER3, 0,
     Int_mpu_set_region(0x30000000, MPU_REGION_SIZE_512KB, MPU_REGION_NUMBER3, 0,
                        MPU_REGION_FULL_ACCESS, MPU_ACCESS_NOT_SHAREABLE,
                        MPU_REGION_FULL_ACCESS, MPU_ACCESS_NOT_SHAREABLE,
                        MPU_ACCESS_CACHEABLE, MPU_ACCESS_BUFFERABLE);
                        MPU_ACCESS_CACHEABLE, MPU_ACCESS_BUFFERABLE);
@@ -57,12 +57,12 @@ void Int_mpu_config(void)
                        MPU_REGION_FULL_ACCESS, MPU_ACCESS_NOT_SHAREABLE,
                        MPU_REGION_FULL_ACCESS, MPU_ACCESS_NOT_SHAREABLE,
                        MPU_ACCESS_CACHEABLE, MPU_ACCESS_BUFFERABLE);
                        MPU_ACCESS_CACHEABLE, MPU_ACCESS_BUFFERABLE);
 
 
-    /* FMC 64MB, Non-Cacheable */
+    /* FMC 64MB,非缓存 */
     Int_mpu_set_region(0x60000000, MPU_REGION_SIZE_64MB, MPU_REGION_NUMBER5, 0,
     Int_mpu_set_region(0x60000000, MPU_REGION_SIZE_64MB, MPU_REGION_NUMBER5, 0,
                        MPU_REGION_FULL_ACCESS, MPU_ACCESS_NOT_SHAREABLE,
                        MPU_REGION_FULL_ACCESS, MPU_ACCESS_NOT_SHAREABLE,
                        MPU_ACCESS_NOT_CACHEABLE, MPU_ACCESS_NOT_BUFFERABLE);
                        MPU_ACCESS_NOT_CACHEABLE, MPU_ACCESS_NOT_BUFFERABLE);
 
 
-    /* SDRAM 32MB, Non-Cacheable (framebuffer, align with reference) */
+    /* SDRAM 32MB,非缓存 */
     Int_mpu_set_region(0xC0000000, MPU_REGION_SIZE_32MB, MPU_REGION_NUMBER6, 0,
     Int_mpu_set_region(0xC0000000, MPU_REGION_SIZE_32MB, MPU_REGION_NUMBER6, 0,
                        MPU_REGION_FULL_ACCESS, MPU_ACCESS_NOT_SHAREABLE,
                        MPU_REGION_FULL_ACCESS, MPU_ACCESS_NOT_SHAREABLE,
                        MPU_ACCESS_NOT_CACHEABLE, MPU_ACCESS_NOT_BUFFERABLE);
                        MPU_ACCESS_NOT_CACHEABLE, MPU_ACCESS_NOT_BUFFERABLE);

+ 2 - 2
Int/Src/Int_sdram.c

@@ -32,14 +32,14 @@ void Int_sdram_init(void)
 
 
     Int_sdram_send_cmd(0, FMC_SDRAM_CMD_AUTOREFRESH_MODE, 8, 0);
     Int_sdram_send_cmd(0, FMC_SDRAM_CMD_AUTOREFRESH_MODE, 8, 0);
 
 
-    /* Mode register: BL=1(000), CAS=3(011), Sequential, Single-write(1<<9) */
+    /* 模式寄存器:BL=1(000), CAS=3(011), 顺序突发, 单次写入(1<<9) */
     mode_register = (uint32_t)(0x0000 |
     mode_register = (uint32_t)(0x0000 |
                                0x0030 |
                                0x0030 |
                                0x0000 |
                                0x0000 |
                                0x0200);
                                0x0200);
     Int_sdram_send_cmd(0, FMC_SDRAM_CMD_LOAD_MODE, 1, mode_register);
     Int_sdram_send_cmd(0, FMC_SDRAM_CMD_LOAD_MODE, 1, mode_register);
 
 
-    /* Refresh count: 64ms/8192rows = 7.8125us; at 100MHz: 781.25-20 = 761 */
+    /* 刷新次数:64ms/8192行 = 7.8125us;按100MHz计算:781.25-20 = 761 */
     HAL_SDRAM_ProgramRefreshRate(&hsdram1, 761);
     HAL_SDRAM_ProgramRefreshRate(&hsdram1, 761);
 }
 }
 
 

+ 5 - 0
MDK-ARM/STMH7_temperature_control_board.uvprojx

@@ -460,6 +460,11 @@
               <FileType>1</FileType>
               <FileType>1</FileType>
               <FilePath>../Int/Src/Int_lcd.c</FilePath>
               <FilePath>../Int/Src/Int_lcd.c</FilePath>
             </File>
             </File>
+            <File>
+              <FileName>Int_flash.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>../Int/Src/Int_flash.c</FilePath>
+            </File>
           </Files>
           </Files>
         </Group>
         </Group>
         <Group>
         <Group>

+ 21 - 1
STMH7_temperature_control_board.ioc

@@ -198,9 +198,15 @@ PB14.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH
 PB14.Locked=true
 PB14.Locked=true
 PB14.PinState=GPIO_PIN_RESET
 PB14.PinState=GPIO_PIN_RESET
 PB14.Signal=GPIO_Output
 PB14.Signal=GPIO_Output
+PB2.GPIOParameters=GPIO_Speed,GPIO_PuPd
+PB2.GPIO_PuPd=GPIO_PULLUP
+PB2.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH
 PB2.Locked=true
 PB2.Locked=true
 PB2.Mode=Single Bank 1
 PB2.Mode=Single Bank 1
 PB2.Signal=QUADSPI_CLK
 PB2.Signal=QUADSPI_CLK
+PB6.GPIOParameters=GPIO_Speed,GPIO_PuPd
+PB6.GPIO_PuPd=GPIO_PULLUP
+PB6.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH
 PB6.Locked=true
 PB6.Locked=true
 PB6.Mode=Single Bank 1
 PB6.Mode=Single Bank 1
 PB6.Signal=QUADSPI_BK1_NCS
 PB6.Signal=QUADSPI_BK1_NCS
@@ -260,13 +266,25 @@ PF2.Signal=FMC_A2
 PF3.Signal=FMC_A3
 PF3.Signal=FMC_A3
 PF4.Signal=FMC_A4
 PF4.Signal=FMC_A4
 PF5.Signal=FMC_A5
 PF5.Signal=FMC_A5
+PF6.GPIOParameters=GPIO_Speed,GPIO_PuPd
+PF6.GPIO_PuPd=GPIO_PULLUP
+PF6.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH
 PF6.Mode=Single Bank 1
 PF6.Mode=Single Bank 1
 PF6.Signal=QUADSPI_BK1_IO3
 PF6.Signal=QUADSPI_BK1_IO3
+PF7.GPIOParameters=GPIO_Speed,GPIO_PuPd
+PF7.GPIO_PuPd=GPIO_PULLUP
+PF7.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH
 PF7.Locked=true
 PF7.Locked=true
 PF7.Mode=Single Bank 1
 PF7.Mode=Single Bank 1
 PF7.Signal=QUADSPI_BK1_IO2
 PF7.Signal=QUADSPI_BK1_IO2
+PF8.GPIOParameters=GPIO_Speed,GPIO_PuPd
+PF8.GPIO_PuPd=GPIO_PULLUP
+PF8.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH
 PF8.Mode=Single Bank 1
 PF8.Mode=Single Bank 1
 PF8.Signal=QUADSPI_BK1_IO0
 PF8.Signal=QUADSPI_BK1_IO0
+PF9.GPIOParameters=GPIO_Speed,GPIO_PuPd
+PF9.GPIO_PuPd=GPIO_PULLUP
+PF9.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH
 PF9.Mode=Single Bank 1
 PF9.Mode=Single Bank 1
 PF9.Signal=QUADSPI_BK1_IO1
 PF9.Signal=QUADSPI_BK1_IO1
 PG0.Signal=FMC_A10
 PG0.Signal=FMC_A10
@@ -377,10 +395,12 @@ ProjectManager.UAScriptAfterPath=
 ProjectManager.UAScriptBeforePath=
 ProjectManager.UAScriptBeforePath=
 ProjectManager.UnderRoot=false
 ProjectManager.UnderRoot=false
 ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_FMC_Init-FMC-false-HAL-true,4-MX_QUADSPI_Init-QUADSPI-false-HAL-true,5-MX_USART1_UART_Init-USART1-false-HAL-true,6-MX_I2C2_Init-I2C2-false-HAL-true,7-MX_LTDC_Init-LTDC-false-HAL-true,0-MX_CORTEX_M7_Init-CORTEX_M7-false-HAL-true
 ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_FMC_Init-FMC-false-HAL-true,4-MX_QUADSPI_Init-QUADSPI-false-HAL-true,5-MX_USART1_UART_Init-USART1-false-HAL-true,6-MX_I2C2_Init-I2C2-false-HAL-true,7-MX_LTDC_Init-LTDC-false-HAL-true,0-MX_CORTEX_M7_Init-CORTEX_M7-false-HAL-true
+QUADSPI.ChipSelectHighTime=QSPI_CS_HIGH_TIME_4_CYCLE
 QUADSPI.ClockPrescaler=2
 QUADSPI.ClockPrescaler=2
 QUADSPI.FifoThreshold=4
 QUADSPI.FifoThreshold=4
 QUADSPI.FlashSize=23
 QUADSPI.FlashSize=23
-QUADSPI.IPParameters=ClockPrescaler,FifoThreshold,FlashSize
+QUADSPI.IPParameters=ClockPrescaler,FifoThreshold,FlashSize,ChipSelectHighTime,SampleShifting
+QUADSPI.SampleShifting=QSPI_SAMPLE_SHIFTING_HALFCYCLE
 RCC.ADCFreq_Value=166000000
 RCC.ADCFreq_Value=166000000
 RCC.AHB12Freq_Value=240000000
 RCC.AHB12Freq_Value=240000000
 RCC.AHB4Freq_Value=240000000
 RCC.AHB4Freq_Value=240000000