2020-07-28 01:54 AM
Hi!
I'm trying to send this information: ADDRESS (3 bytes), Dummy Byte (1 byte), DATA (2 bytes), and the result of HAL_OSPI_Transmit is always--> HAL ERROR.
What do you think could be the issue? Below you have my code:
Thank you!
void FT813_memWrite16_QUAD(u32 ftAddress, u16 ftData16) {
s32 i;
u8 cTempAddr[3], cTempData[2];
cTempAddr[2] = (u8)(ftAddress >> 16) | MEM_WRITE; // Compose the command and address to send
cTempAddr[1] = (u8)(ftAddress >> 8); // middle byte
cTempAddr[0] = (u8)(ftAddress); // low byte
cTempData[1] = (u8) (ftData16 >> 8); // Compose data to be sent - high byte
cTempData[0] = (u8) (ftData16); // low byte
ftAddress=Array_u32(cTempAddr);
FT813_CS_ON
sCommand.OperationType = HAL_OSPI_OPTYPE_COMMON_CFG;
sCommand.InstructionMode=HAL_OSPI_INSTRUCTION_NONE;
sCommand.Instruction=0x00;
sCommand.AddressMode=HAL_OSPI_ADDRESS_1_LINE;
sCommand.AddressSize=HAL_OSPI_ADDRESS_24_BITS;
sCommand.Address=ftAddress;
sCommand.AlternateBytesMode=HAL_OSPI_ALTERNATE_BYTES_NONE;
sCommand.AlternateBytes=0;
sCommand.AlternateBytesSize=0;
sCommand.DataMode=HAL_OSPI_DATA_1_LINE;
sCommand.DataDtrMode=HAL_OSPI_DATA_DTR_DISABLE;
sCommand.NbData=2; //2 bytes to send
sCommand.DummyCycles= 8; //1 Byte dummy
if (HAL_OSPI_Command(&hospi1, &sCommand, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
Error_Handler();
}
if(HAL_OSPI_Transmit(&hospi1,&cTempData[0],HAL_OSPI_TIMEOUT_DEFAULT_VALUE)!=HAL_OK)
{
Error_Handler();
}
FT813_CS_OFF
}
2020-07-28 06:03 AM
Set breakpoints within HAL_OSPI_Transmit to determine where exactly it's failing and debug from there.
Next time include your chip part number in the post.
2020-07-28 07:42 AM
Thank you for the answer. The chip part number is: STM32H7A3ZIT6
Into the function, it fails at this point:
/* Check the state */
if (hospi->State == HAL_OSPI_STATE_CMD_CFG)
{
//it is false, State= 0x00000200 (HAL_OSPI_STATE_ERROR)
2020-07-28 08:42 AM
Show the configuration code, ideally a free standing and compilable example that demonstrates the issue.
Point of failure isn't necessarily where the real problem is.
Some up stream code, or hacky chip select implementation.
Dump OSPI register content.
Determine the point(s) at which HAL_OPSI_STATE_ERROR can occur, or occur here, grep the library source.
2020-07-29 02:43 AM
Thank you for the answers.
I've found the problem, it was due to the "Device Size" at the initial configuration. If the “device size�? is smaller than the memory size then it doesn’t transmit/receive. Now it is working fine.
However, I have another problem. If I receive 1 byte or 2 bytes (Nbdata =1 or Nbdata = 2), it works perfectly. But if I try to receive 4 bytes (Nbdata = 4), then it receive 8 bytes (checked by a logic analyzer) so it is not correct. Do you know what could be the reason?
u32 FT813_memRead32_QUAD(u32 ftAddress) {
s32 i;
u32 ftData32;
u8 cTempAddr[4], cTempData[8], cZeroFill=0;
cTempAddr[3] = 0;
cTempAddr[2] = (u8)(ftAddress >> 16) | MEM_READ; // Compose the command and address to send
cTempAddr[1] = (u8)(ftAddress >> 8); // middle byte
cTempAddr[0] = (u8)(ftAddress); // low byte
ftAddress=Array_u32(cTempAddr);
FT813_CS_ON
sCommand.OperationType = HAL_OSPI_OPTYPE_COMMON_CFG;
sCommand.InstructionMode=HAL_OSPI_INSTRUCTION_NONE;
sCommand.Instruction=0x00;
sCommand.AddressMode=HAL_OSPI_ADDRESS_1_LINE;
sCommand.AddressSize=HAL_OSPI_ADDRESS_24_BITS;
sCommand.Address=ftAddress;
sCommand.AlternateBytesMode=HAL_OSPI_ALTERNATE_BYTES_NONE;
sCommand.AlternateBytes=0;
sCommand.AlternateBytesSize=0;
sCommand.DataMode=HAL_OSPI_DATA_1_LINE;
sCommand.DataDtrMode=HAL_OSPI_DATA_DTR_DISABLE;
sCommand.NbData=4; //Want to receive 4 bytes
sCommand.DummyCycles= 8; //1 Byte
if (HAL_OSPI_Command(&hospi1, &sCommand, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
Error_Handler();
}
if (HAL_OSPI_Receive(&hospi1,cTempData,HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
Error_Handler();
} //<--- //Here, receive 8 bytes
FT813_CS_OFF
ftData32 = (cTempData[3]<< 24) | // Compose value to return - high byte
(cTempData[2]<< 16) |
(cTempData[1]<< 8) |
(cTempData[0]); // Low byte
return ftData32;
}
Here you can see the _Init:
static void MX_OCTOSPI1_Init(void)
{
/* USER CODE BEGIN OCTOSPI1_Init 0 */
/* USER CODE END OCTOSPI1_Init 0 */
OSPIM_CfgTypeDef sOspiManagerCfg = {0};
/* USER CODE BEGIN OCTOSPI1_Init 1 */
/* USER CODE END OCTOSPI1_Init 1 */
/* OCTOSPI1 parameter configuration*/
hospi1.Instance = OCTOSPI1;
hospi1.Init.FifoThreshold = 1;
hospi1.Init.DualQuad = HAL_OSPI_DUALQUAD_DISABLE;
hospi1.Init.MemoryType = HAL_OSPI_MEMTYPE_MICRON;
hospi1.Init.DeviceSize = 24;
hospi1.Init.ChipSelectHighTime = 1;
hospi1.Init.FreeRunningClock = HAL_OSPI_FREERUNCLK_DISABLE;
hospi1.Init.ClockMode = HAL_OSPI_CLOCK_MODE_0;
hospi1.Init.WrapSize = HAL_OSPI_WRAP_NOT_SUPPORTED;
hospi1.Init.ClockPrescaler = 12;
hospi1.Init.SampleShifting = HAL_OSPI_SAMPLE_SHIFTING_NONE;
hospi1.Init.DelayHoldQuarterCycle = HAL_OSPI_DHQC_DISABLE;
hospi1.Init.ChipSelectBoundary = 1;
hospi1.Init.ClkChipSelectHighTime = 0;
hospi1.Init.DelayBlockBypass = HAL_OSPI_DELAY_BLOCK_BYPASSED;
hospi1.Init.MaxTran = 0;
hospi1.Init.Refresh = 0;
if (HAL_OSPI_Init(&hospi1) != HAL_OK)
{
Error_Handler();
}
sOspiManagerCfg.ClkPort = 1;
sOspiManagerCfg.IOLowPort = HAL_OSPIM_IOPORT_1_LOW;
if (HAL_OSPIM_Config(&hospi1, &sOspiManagerCfg, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN OCTOSPI1_Init 2 */
/* USER CODE END OCTOSPI1_Init 2 */
}
And here the output at logic analyzer: