2024-08-13 07:14 AM
Hi All
I have created a PCB where I want to use the OCTOSPI to communicate with a FPGA.
I have difficulty finding accurate information on how the different memory types work. I already have a Hyperram running so I started there, that did also seem straight forward.
I do currently only have FPGA code listening and is focusing on getting write to work.
I slowed down the clk quite a bit to only fucus on functionality. Pre scale of 30 ~9.6Mhz
I would much like to have the FPGA memory mapped, so that's what I'm testing.
When I write to address 0x91234568 (0x90000000) is octospi1 base
with the data of 0x87654321 then i get following sequence in hex:
20 12 34 56 00 04 43 21 87 65
The Data is easy, that's just different order 43 21 87 65 instead of 87 65 43 21
The 20 seems to be CMD
The Address (in correct order) 12 34 56 (but then always 00 00 or 00 04) as the last, I seem to lack the last nibble of the Address. The RWDS Seems a bit early.
if I Change to 0x91234560 then the same 20 12 34 56 00 00 43 21 87 65, just with out the 04
If I write at 0x91234564 I get 4 extra bytes before RWDS.
20 12 34 56 00 00 00 00 00 00 43 21 87 65, But now the RWDS is accurate
If I write at 0x9123456C I also get the 4 extra bytes before RWDS, now with 04.
20 12 34 56 00 04 00 00 00 00 43 21 87 65, and the RWDS is accurate
If I write at 0x91234566 I also get the 6 extra bytes before RWDS, now with 00.
if I write on uneven addresses then bytes a masked with RWDS.
There seems to be a quite clear pattern, that I first discovered while writing this message, but again, it is a bit difficult.
My config currently looks like this:
static void MX_OCTOSPI1_Init(void)
{
/* USER CODE BEGIN OCTOSPI1_Init 0 */
/* USER CODE END OCTOSPI1_Init 0 */
OSPIM_CfgTypeDef sOspiManagerCfg = {0};
OSPI_HyperbusCfgTypeDef sHyperBusCfg = {0};
/* USER CODE BEGIN OCTOSPI1_Init 1 */
/* USER CODE END OCTOSPI1_Init 1 */
/* OCTOSPI1 parameter configuration*/
hospi1.Instance = OCTOSPI1;
hospi1.Init.FifoThreshold = 4;
hospi1.Init.DualQuad = HAL_OSPI_DUALQUAD_DISABLE;
hospi1.Init.MemoryType = HAL_OSPI_MEMTYPE_HYPERBUS;
hospi1.Init.DeviceSize = 28;
hospi1.Init.ChipSelectHighTime = 8;
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 = 30;
hospi1.Init.SampleShifting = HAL_OSPI_SAMPLE_SHIFTING_NONE;
hospi1.Init.DelayHoldQuarterCycle = HAL_OSPI_DHQC_ENABLE;
hospi1.Init.ChipSelectBoundary = 23;
hospi1.Init.DelayBlockBypass = HAL_OSPI_DELAY_BLOCK_USED;
hospi1.Init.MaxTran = 0;
hospi1.Init.Refresh = 0;
if (HAL_OSPI_Init(&hospi1) != HAL_OK)
{
Error_Handler();
}
sOspiManagerCfg.ClkPort = 1;
sOspiManagerCfg.DQSPort = 1;
sOspiManagerCfg.NCSPort = 1;
sOspiManagerCfg.IOLowPort = HAL_OSPIM_IOPORT_1_LOW;
sOspiManagerCfg.IOHighPort = HAL_OSPIM_IOPORT_1_HIGH;
if (HAL_OSPIM_Config(&hospi1, &sOspiManagerCfg, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
Error_Handler();
}
sHyperBusCfg.RWRecoveryTime = 0;
sHyperBusCfg.AccessTime = 0;
sHyperBusCfg.WriteZeroLatency = HAL_OSPI_NO_LATENCY_ON_WRITE;
sHyperBusCfg.LatencyMode = HAL_OSPI_FIXED_LATENCY;
if (HAL_OSPI_HyperbusCfg(&hospi1, &sHyperBusCfg, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN OCTOSPI1_Init 2 */
OSPI_HyperbusCmdTypeDef sCommand;
OSPI_MemoryMappedTypeDef sMemMappedCfg;
/* Memory-mapped mode configuration --------------------------------------- */
sCommand.AddressSpace = HAL_OSPI_MEMORY_ADDRESS_SPACE;
sCommand.AddressSize = HAL_OSPI_ADDRESS_24_BITS;
sCommand.DQSMode = HAL_OSPI_DQS_ENABLE; //Test
sCommand.Address = 0;
sCommand.NbData = 1;
if (HAL_OSPI_HyperbusCmd(&hospi1, &sCommand, 0) != HAL_OK)
{
Error_Handler();
}
sMemMappedCfg.TimeOutActivation = HAL_OSPI_TIMEOUT_COUNTER_DISABLE;
if (HAL_OSPI_MemoryMapped(&hospi1, &sMemMappedCfg) != HAL_OK)
{
Error_Handler();
}
//Enable FREERUNCLK
//SET_BIT(hospi1.Instance->DCR1, OCTOSPI_DCR1_FRCK);
/* USER CODE END OCTOSPI1_Init 2 */
}
Thanks in advance
Kristian Vang
Solved! Go to Solution.
2024-09-10 06:06 AM
Hi
I found that the reason for the last problem was that I was holding the bus from the FPGA, so problem solved, I now have a Stable OctoSpi <> FPGA interface.
2024-08-13 07:42 AM - edited 2024-08-13 07:48 AM
Hello @Kvang ,
Could you provide more details? Which STM32H7 MCU and HyperRAM memory are you using?
Could you please share the memory datasheet?
I advise you to take a look at the STM32H7 errata sheet and check the OCTOSPI errata and the workaround.
If you use the STM32H735 please note that at least six cycles memory latency must be set when DQS is used for HyperBus™ memories (sHyperBusCfg.AccessTime = 0; should be sHyperBusCfg.AccessTime = 6;)
May this example "OSPI_HyperRAM_MemoryMapped" can help you.
Thank you.
Kaouthar
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2024-08-13 10:13 PM
Hi Kaouthar
2024-08-14 12:54 AM
Hello @Kvang ,
For communication with an FPGA using the OctoSPI interface, you can choose any of the following memory types, depending on your specific requirements:
Note that the memory type has no impact in Quad-SPI mode as mentioned in AN5050.
Thank you.
Kaouthar
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2024-08-14 05:37 AM
Hi Kaouthar
Thanks a lot.
I got further, I now have it running in these mode:
HAL_OSPI_MEMTYPE_MICRON
/* OCTOSPI1 parameter configuration*/
hospi1.Instance = OCTOSPI1;
hospi1.Init.FifoThreshold = 4;
hospi1.Init.DualQuad = HAL_OSPI_DUALQUAD_DISABLE;
hospi1.Init.MemoryType = HAL_OSPI_MEMTYPE_APMEMORY;
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 = 15;
hospi1.Init.SampleShifting = HAL_OSPI_SAMPLE_SHIFTING_NONE;
hospi1.Init.DelayHoldQuarterCycle = HAL_OSPI_DHQC_ENABLE;
hospi1.Init.ChipSelectBoundary = 24;
hospi1.Init.DelayBlockBypass = HAL_OSPI_DELAY_BLOCK_USED;
hospi1.Init.MaxTran = 0;
hospi1.Init.Refresh = 0;
if (HAL_OSPI_Init(&hospi1) != HAL_OK)
{
Error_Handler();
}
sOspiManagerCfg.ClkPort = 1;
sOspiManagerCfg.DQSPort = 1;
sOspiManagerCfg.NCSPort = 1;
sOspiManagerCfg.IOLowPort = HAL_OSPIM_IOPORT_1_LOW;
sOspiManagerCfg.IOHighPort = HAL_OSPIM_IOPORT_1_HIGH;
if (HAL_OSPIM_Config(&hospi1, &sOspiManagerCfg, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
Error_Handler();
}
/*APS6408L-3OB PSRAM APmemory*/
#define LINEAR_BURST_READ 0x20
#define LINEAR_BURST_WRITE 0xA0
#define DUMMY_CLOCK_CYCLES_SRAM_READ 1
#define DUMMY_CLOCK_CYCLES_SRAM_WRITE 1
void EnableMemMapped(void)
{
OSPI_RegularCmdTypeDef sCommand;
OSPI_MemoryMappedTypeDef sMemMappedCfg;
sCommand.FlashId = HAL_OSPI_FLASH_ID_1;
sCommand.InstructionMode = HAL_OSPI_INSTRUCTION_8_LINES;
sCommand.InstructionSize = HAL_OSPI_INSTRUCTION_8_BITS;
sCommand.InstructionDtrMode = HAL_OSPI_INSTRUCTION_DTR_ENABLE;
sCommand.AddressMode = HAL_OSPI_ADDRESS_8_LINES;
sCommand.AddressSize = HAL_OSPI_ADDRESS_24_BITS;
sCommand.AddressDtrMode = HAL_OSPI_ADDRESS_DTR_ENABLE;
sCommand.AlternateBytesMode = HAL_OSPI_ALTERNATE_BYTES_NONE;
sCommand.DataMode = HAL_OSPI_DATA_8_LINES;
sCommand.DataDtrMode = HAL_OSPI_DATA_DTR_ENABLE;
sCommand.DQSMode = HAL_OSPI_DQS_ENABLE;
sCommand.SIOOMode = HAL_OSPI_SIOO_INST_EVERY_CMD;
sCommand.Address = 0;
sCommand.NbData = 1;
/* Memory-mapped mode configuration for Linear burst write operations */
sCommand.OperationType = HAL_OSPI_OPTYPE_WRITE_CFG;
sCommand.Instruction = LINEAR_BURST_WRITE;
sCommand.DummyCycles = DUMMY_CLOCK_CYCLES_SRAM_WRITE;
if (HAL_OSPI_Command(&hospi1, &sCommand, HAL_OSPI_TIMEOUT_DEFAULT_VALUE)!= HAL_OK) {
Error_Handler();
}
/* Memory-mapped mode configuration for Linear burst read operations */
sCommand.OperationType = HAL_OSPI_OPTYPE_READ_CFG;
sCommand.Instruction = LINEAR_BURST_READ;
sCommand.DummyCycles = DUMMY_CLOCK_CYCLES_SRAM_READ;
if (HAL_OSPI_Command(&hospi1, &sCommand, HAL_OSPI_TIMEOUT_DEFAULT_VALUE)!= HAL_OK) {
Error_Handler();
}
/*Disable timeout counter for memory mapped mode*/
sMemMappedCfg.TimeOutActivation = HAL_OSPI_TIMEOUT_COUNTER_DISABLE;
/*Enable memory mapped mode*/
if (HAL_OSPI_MemoryMapped(&hospi1, &sMemMappedCfg) != HAL_OK) {
Error_Handler();
}
}
2024-08-23 04:15 AM
Hi Kaouthar
Thanks for the help
I got it working ok now.
I do have a igniring problem, when I debug the debugger read and potentially write to the memory(fpga)
but when doing so it's not setting a cmd, just leave it 0x00
I use the CMD from the exsample:
#define LINEAR_BURST_READ 0x20
#define LINEAR_BURST_WRITE 0xA0
at first that would lock up my system all the time if the mouse hit a variable from the octospi1 memmory area.
i then added 0x00 as read in the fpga.
but if I change a variable i can see that it tries to write, but cmd is also 0x00 there.
thanks in advance
Kristian Vang
2024-08-27 07:33 AM
Hi @Kvang ,
Thank you for coming back to the community and glad to know that the initial issue is solved.
I didn't quite understand your new questions and your requests.
For HyperBus protocol, during this initial phase, the OCTOSPI sends 48 bits over IO[7:0] to specify the operations
to be performed with the external device. And Bit 47 identifies the transaction as a read or a write.
Please take a look at RM0468 section 25 Octo-SPI interface (OCTOSPI) may help you.
Thank you.
Kaouthar
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2024-09-10 06:06 AM
Hi
I found that the reason for the last problem was that I was holding the bus from the FPGA, so problem solved, I now have a Stable OctoSpi <> FPGA interface.
2024-11-01 08:45 AM
Glad to see you successfully implemented OSPI communication between STM32 and FPGA.
I also want to implement such a communication protocol on the PCB I made myself,
but I am stuck at the output stage of the microcontroller.
I think it is incorrect configuration that causes my microcontroller to not be able to send data.
Could you please let me refer to your configuration or project?
I really need your help. Thanks in advance.