luckyren 发表于 2023-8-10 11:16

HC32F460的QSPI flash映射读取全是0XDD,如果不映射直接读取flash就可以,这是为啥呢

初始化代码如下
void QSPI_FLASH_Init(void)
{
    stc_qspi_init_t stcQspiInit;
    stc_gpio_init_t stcGpioInit;

    (void)GPIO_StructInit(&stcGpioInit);
    stcGpioInit.u16PinDrv = PIN_HIGH_DRV;
    (void)GPIO_Init(QSPI_FLASH_CS_PORT,QSPI_FLASH_CS_PIN,&stcGpioInit);
    (void)GPIO_Init(QSPI_FLASH_SCK_PORT, QSPI_FLASH_SCK_PIN, &stcGpioInit);
    (void)GPIO_Init(QSPI_FLASH_IO0_PORT, QSPI_FLASH_IO0_PIN, &stcGpioInit);
    (void)GPIO_Init(QSPI_FLASH_IO1_PORT, QSPI_FLASH_IO1_PIN, &stcGpioInit);
    (void)GPIO_Init(QSPI_FLASH_IO2_PORT, QSPI_FLASH_IO2_PIN, &stcGpioInit);
    (void)GPIO_Init(QSPI_FLASH_IO3_PORT, QSPI_FLASH_IO3_PIN, &stcGpioInit);
    GPIO_SetFunc(QSPI_FLASH_CS_PORT,QSPI_FLASH_CS_PIN,QSPI_FLASH_CS_FUNC);
    GPIO_SetFunc(QSPI_FLASH_SCK_PORT, QSPI_FLASH_SCK_PIN, QSPI_FLASH_SCK_FUNC);
    GPIO_SetFunc(QSPI_FLASH_IO0_PORT, QSPI_FLASH_IO0_PIN, QSPI_FLASH_IO0_FUNC);
    GPIO_SetFunc(QSPI_FLASH_IO1_PORT, QSPI_FLASH_IO1_PIN, QSPI_FLASH_IO1_FUNC);
    GPIO_SetFunc(QSPI_FLASH_IO2_PORT, QSPI_FLASH_IO2_PIN, QSPI_FLASH_IO2_FUNC);
    GPIO_SetFunc(QSPI_FLASH_IO3_PORT, QSPI_FLASH_IO3_PIN, QSPI_FLASH_IO3_FUNC);

    FCG_Fcg1PeriphClockCmd(QSPI_FLASH_CLK, ENABLE);
    (void)QSPI_StructInit(&stcQspiInit);
    stcQspiInit.u32ClockDiv       = QSPI_CLK_DIV3;
    stcQspiInit.u32ReadMode       = QSPI_FLASH_RD_MD;
    stcQspiInit.u32PrefetchMode   = QSPI_PREFETCH_MD_EDGE_STOP;
    stcQspiInit.u32DummyCycle   = QSPI_FLASH_RD_DUMMY_CYCLE;
    stcQspiInit.u32AddrWidth      = QSPI_FLASH_ADDR_WIDTH;
    stcQspiInit.u32SetupTime      = QSPI_QSSN_SETUP_ADVANCE_QSCK1P5;
    stcQspiInit.u32ReleaseTime    = QSPI_QSSN_RELEASE_DELAY_QSCK1P5;
    stcQspiInit.u32IntervalTime   = QSPI_QSSN_INTERVAL_QSCK2;
    (void)QSPI_Init(&stcQspiInit);
}映射读取
int32_t QSPI_FLASH_Read(uint32_t u32Addr, uint8_t *pu8ReadBuf, uint32_t u32Size)
{
    uint32_t u32Count = 0U;
    int32_t i32Ret = LL_OK;
    __IO uint8_t *pu8Read;

    u32Addr += QSPI_ROM_BASE;
    if ((NULL == pu8ReadBuf) || (0UL == u32Size) || ((u32Addr + u32Size) > QSPI_ROM_END)) {
      i32Ret = LL_ERR_INVD_PARAM;
    } else {
#if (QSPI_XIP_FUNC_ENABLE == DDL_ON)
      QSPI_XipModeCmd(QSPI_FLASH_ENTER_XIP_MD, ENABLE);
#endif
      pu8Read = (__IO uint8_t *)u32Addr;
      while (u32Count < u32Size) {
            pu8ReadBuf = *pu8Read++;
#if (QSPI_XIP_FUNC_ENABLE == DDL_ON)
            if (u32Count == (u32Size - 1U)) {
                QSPI_XipModeCmd(QSPI_FLASH_EXIT_XIP_MD, DISABLE);
            }
#endif
      }
    }

    return i32Ret;
}直接读取
int32_t QSPI_FLASH_Read(uint32_t u32Addr, uint8_t *pu8ReadBuf, uint32_t u32Size)
{
    uint32_t u32TempSize = 0;
    uint8_t u8AddrBuf = {0};
    uint32_t u32AddrOffset = 0U;
    int32_t i32Ret = LL_OK;

    if ((NULL == pu8ReadBuf) || (0UL == u32Size) || ((u32Addr % W25Q64_PAGE_SIZE) != 0U)) {
      i32Ret = LL_ERR_INVD_PARAM;
    } else {
      while (u32Size != 0UL) {
            if (u32Size >= W25Q64_PAGE_SIZE) {
                u32TempSize = W25Q64_PAGE_SIZE;
            } else {
                u32TempSize = u32Size;
            }
            QSPI_FLASH_WriteInstr(W25Q64_WR_ENABLE, NULL, 0U, NULL, 0U);
            QSPI_FLASH_WordToByte(u32Addr, u8AddrBuf);
            QSPI_FLASH_ReadInstr(W25Q64_RD_DATA, u8AddrBuf, (QSPI_FLASH_ADDR_WIDTH + 1U),
                                  (uint8_t *)&pu8ReadBuf, u32TempSize);
            i32Ret = QSPI_FLASH_CheckProcessDone(500U);
            if (i32Ret != LL_OK) {
                break;
            }
            u32Addr       += u32TempSize;
            u32AddrOffset += u32TempSize;
            u32Size       -= u32TempSize;
      }
    }

    return i32Ret;
}

luckyren 发表于 2023-8-10 13:32

映射地址是:
/* QSPI memory mapping base and end address */
#define QSPI_ROM_BASE                           (0x98000000UL)
#define QSPI_ROM_END                            (0x9BFFFFFFUL)


luckyren 发表于 2023-8-11 09:31

已解决,是因为flash芯片不同,紫光芯片在使用QSPI时需要把QE打开,即寄存器2W25Q64_WR_STATUS_REG2的QE位要置1.

renyaq 发表于 2023-8-13 19:09

flash芯片不同都这样啊

chenqianqian 发表于 2023-8-14 08:41

地址都不一样的
页: [1]
查看完整版本: HC32F460的QSPI flash映射读取全是0XDD,如果不映射直接读取flash就可以,这是为啥呢