本帖最后由 hpdell 于 2016-12-15 14:32 编辑
使用的硬件的 QSPI ,芯片是N25Q512A的,估计就是时钟频率与 Dummy
Clock Cycles 的周期没有搞对造成的,
再加上 芯片 N25Q512的资料也没有完全明白
static QSPI_StaticTypeDef QSPI_SendCmdData( uint8_t __Instruction, // 发送指令
uint32_t __InstructionMode, // 指令模式
uint32_t __AddressMode, // 地址模式
uint32_t __AddressSize, // 地址长度
uint32_t __DataMode, // 数据模式
uint32_t __NbData, // 数据读写字节数
uint32_t __DummyCycles, // 设置空指令周期数
uint32_t __Address, // 发送到的目的地址
uint8_t *_pBuf, // 待发送的数据
__SEND_CMD_DATA_T _SendCmdDat
)
{
QSPI_CommandTypeDef sCommand;
sCommand.SIOOMode = QSPI_SIOO_INST_EVERY_CMD; //每次都发送指令
sCommand.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE; //无交替字节
sCommand.DdrMode = QSPI_DDR_MODE_DISABLE; //关闭DDR模式
sCommand.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY;
sCommand.Instruction = __Instruction; //指令
sCommand.DummyCycles = __DummyCycles; //设置空指令周期数
sCommand.Address = __Address; //发送到的目的地址
// sCommand.NbData = __NbData; //这个地方不使用
sCommand.InstructionMode = __InstructionMode; //指令模式
sCommand.AddressMode = __AddressMode; //地址模式
sCommand.AddressSize = __AddressSize; //地址长度
sCommand.DataMode = __DataMode; //数据模式
if (HAL_QSPI_Command(&hqspi, &sCommand, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return QSPI_ERROR;
}
if( _SendCmdDat == QSPI_SEND_DAT)
{
if(QSPI_Transmit( ( uint8_t * )_pBuf, __NbData) != QSPI_OK)
{
return QSPI_ERROR;
}
}
return QSPI_OK;
}
/**
* @brief This function configure the dummy cycles on memory side.
* @param hqspi: QSPI handle
* @retval None
*/
QSPI_StaticTypeDef QSPI_DummyCyclesCfg(QSPI_HandleTypeDef *hqspi)
{
QSPI_CommandTypeDef sCommand;
uint8_t reg;
if(W25QxxQpiMode) // qpi
{
sCommand.InstructionMode = QSPI_INSTRUCTION_4_LINES;
sCommand.DataMode = QSPI_DATA_4_LINES;
}
else
{
sCommand.InstructionMode = QSPI_INSTRUCTION_1_LINE;
sCommand.DataMode = QSPI_DATA_1_LINE;
}
/* Read Volatile Configuration register --------------------------- */
// sCommand.InstructionMode = QSPI_INSTRUCTION_1_LINE;
sCommand.Instruction = QSPI_READ_VOL_CFG_REG_CMD;
sCommand.AddressMode = QSPI_ADDRESS_NONE;
sCommand.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE;
// sCommand.DataMode = QSPI_DATA_1_LINE;
sCommand.DummyCycles = 0;
sCommand.DdrMode = QSPI_DDR_MODE_DISABLE;
sCommand.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY;
sCommand.SIOOMode = QSPI_SIOO_INST_EVERY_CMD;
sCommand.NbData = 1;
if (HAL_QSPI_Command( hqspi , &sCommand, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return QSPI_ERROR;
}
if (HAL_QSPI_Receive( hqspi , ®, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return QSPI_ERROR;
}
/* Enable write operations ---------------------------------------- */
QSPI_WriteEnable( hqspi );
/* Write Volatile Configuration register (with new dummy cycles) -- */
sCommand.Instruction = QSPI_WRITE_VOL_CFG_REG_CMD;
MODIFY_REG(reg, 0xF0, (10<< POSITION_VAL(0xF0)));
if (HAL_QSPI_Command(hqspi, &sCommand, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return QSPI_ERROR;
}
if (HAL_QSPI_Transmit(hqspi, ®, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return QSPI_ERROR;
}
return QSPI_OK;
}
QSPI_StaticTypeDef QSPI_ReadBuff(uint8_t* data, uint32_t address, uint32_t size)
{
uint8_t _RegVal = 0;
QSPI_DummyCyclesCfg(&hqspi);
//QPI,快速读数据,地址为ReadAddr,4线传输数据_32位地址_4线传输地址_4线传输指令,8空周期,NumByteToRead个数据
if(QSPI_SendCmdData( QSPI_QUAD_INOUT_FAST_READ_CMD /*QSPI_QUAD_INOUT_FAST_READ_CMD*/ /*QSPI_QUAD_INOUT_FAST_READ_CMD*/ , // _Instruction, 发送指令
QSPI_INSTRUCTION_4_LINES, // _InstructionMode, 指令模式
QSPI_ADDRESS_4_LINES, // _AddressMode, 地址模式
QSPI_ADDRESS_32_BITS, // _AddressSize, 地址长度
QSPI_DATA_4_LINES, // _DataMode, 数据模式
size, // _NbData, 数据读写字节数
10 , // _DummyCycles, 设置空指令周期数 与 QSPI_SET_READ_PARAM 这个指令设置的值一致
address, // _Address, 发送到的目的地址
&_RegVal, // *_pBuf, 待发送的数据
QSPI_SEND_CMD // __SEND_CMD_DATA_T _SendCmdDat
) != QSPI_OK )
{
return QSPI_ERROR;
}
if(QSPI_Receive( data, size) != QSPI_OK)
return QSPI_ERROR;
return QSPI_OK;
}
本帖最后由 hpdell 于 2016-12-15 14:32 编辑
使用的硬件的 QSPI ,芯片是N25Q512A的,估计就是时钟频率与 Dummy
Clock Cycles 的周期没有搞对造成的,
再加上 芯片 N25Q512的资料也没有完全明白
static QSPI_StaticTypeDef QSPI_SendCmdData( uint8_t __Instruction, // 发送指令
uint32_t __InstructionMode, // 指令模式
uint32_t __AddressMode, // 地址模式
uint32_t __AddressSize, // 地址长度
uint32_t __DataMode, // 数据模式
uint32_t __NbData, // 数据读写字节数
uint32_t __DummyCycles, // 设置空指令周期数
uint32_t __Address, // 发送到的目的地址
uint8_t *_pBuf, // 待发送的数据
__SEND_CMD_DATA_T _SendCmdDat
)
{
QSPI_CommandTypeDef sCommand;
sCommand.SIOOMode = QSPI_SIOO_INST_EVERY_CMD; //每次都发送指令
sCommand.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE; //无交替字节
sCommand.DdrMode = QSPI_DDR_MODE_DISABLE; //关闭DDR模式
sCommand.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY;
sCommand.Instruction = __Instruction; //指令
sCommand.DummyCycles = __DummyCycles; //设置空指令周期数
sCommand.Address = __Address; //发送到的目的地址
// sCommand.NbData = __NbData; //这个地方不使用
sCommand.InstructionMode = __InstructionMode; //指令模式
sCommand.AddressMode = __AddressMode; //地址模式
sCommand.AddressSize = __AddressSize; //地址长度
sCommand.DataMode = __DataMode; //数据模式
if (HAL_QSPI_Command(&hqspi, &sCommand, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return QSPI_ERROR;
}
if( _SendCmdDat == QSPI_SEND_DAT)
{
if(QSPI_Transmit( ( uint8_t * )_pBuf, __NbData) != QSPI_OK)
{
return QSPI_ERROR;
}
}
return QSPI_OK;
}
/**
* @brief This function configure the dummy cycles on memory side.
* @param hqspi: QSPI handle
* @retval None
*/
QSPI_StaticTypeDef QSPI_DummyCyclesCfg(QSPI_HandleTypeDef *hqspi)
{
QSPI_CommandTypeDef sCommand;
uint8_t reg;
if(W25QxxQpiMode) // qpi
{
sCommand.InstructionMode = QSPI_INSTRUCTION_4_LINES;
sCommand.DataMode = QSPI_DATA_4_LINES;
}
else
{
sCommand.InstructionMode = QSPI_INSTRUCTION_1_LINE;
sCommand.DataMode = QSPI_DATA_1_LINE;
}
/* Read Volatile Configuration register --------------------------- */
// sCommand.InstructionMode = QSPI_INSTRUCTION_1_LINE;
sCommand.Instruction = QSPI_READ_VOL_CFG_REG_CMD;
sCommand.AddressMode = QSPI_ADDRESS_NONE;
sCommand.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE;
// sCommand.DataMode = QSPI_DATA_1_LINE;
sCommand.DummyCycles = 0;
sCommand.DdrMode = QSPI_DDR_MODE_DISABLE;
sCommand.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY;
sCommand.SIOOMode = QSPI_SIOO_INST_EVERY_CMD;
sCommand.NbData = 1;
if (HAL_QSPI_Command( hqspi , &sCommand, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return QSPI_ERROR;
}
if (HAL_QSPI_Receive( hqspi , ®, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return QSPI_ERROR;
}
/* Enable write operations ---------------------------------------- */
QSPI_WriteEnable( hqspi );
/* Write Volatile Configuration register (with new dummy cycles) -- */
sCommand.Instruction = QSPI_WRITE_VOL_CFG_REG_CMD;
MODIFY_REG(reg, 0xF0, (10<< POSITION_VAL(0xF0)));
if (HAL_QSPI_Command(hqspi, &sCommand, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return QSPI_ERROR;
}
if (HAL_QSPI_Transmit(hqspi, ®, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return QSPI_ERROR;
}
return QSPI_OK;
}
QSPI_StaticTypeDef QSPI_ReadBuff(uint8_t* data, uint32_t address, uint32_t size)
{
uint8_t _RegVal = 0;
QSPI_DummyCyclesCfg(&hqspi);
//QPI,快速读数据,地址为ReadAddr,4线传输数据_32位地址_4线传输地址_4线传输指令,8空周期,NumByteToRead个数据
if(QSPI_SendCmdData( QSPI_QUAD_INOUT_FAST_READ_CMD /*QSPI_QUAD_INOUT_FAST_READ_CMD*/ /*QSPI_QUAD_INOUT_FAST_READ_CMD*/ , // _Instruction, 发送指令
QSPI_INSTRUCTION_4_LINES, // _InstructionMode, 指令模式
QSPI_ADDRESS_4_LINES, // _AddressMode, 地址模式
QSPI_ADDRESS_32_BITS, // _AddressSize, 地址长度
QSPI_DATA_4_LINES, // _DataMode, 数据模式
size, // _NbData, 数据读写字节数
10 , // _DummyCycles, 设置空指令周期数 与 QSPI_SET_READ_PARAM 这个指令设置的值一致
address, // _Address, 发送到的目的地址
&_RegVal, // *_pBuf, 待发送的数据
QSPI_SEND_CMD // __SEND_CMD_DATA_T _SendCmdDat
) != QSPI_OK )
{
return QSPI_ERROR;
}
if(QSPI_Receive( data, size) != QSPI_OK)
return QSPI_ERROR;
return QSPI_OK;
}
举报