2024-04-05
09:23 AM
- last edited on
2024-04-08
02:00 AM
by
Lina_DABASINSKA
After trying the sample code from STM32Cube_FW_L4_V1.18.0
for octo spi
I getting stuck on
HAL_OSPI_AutoPolling(hospi, &sConfig, HAL_OSPI_TIMEOUT_DEFAULT_VALUE);
it is not working, after reading posts and
STM32L4Rxxx and STM32L4Sxxx device errata
I found information that:
"Auto-polling mode not functional with new octal memories"
any idea how to work around it or fix ?
the sample code does not work, I cannot test OSPI.
2024-04-05 07:40 PM
In OCTO mode
OSPI_RegularCmdTypeDef sCommand = {0};// make sure the structure is clean/clear
sCommand.OperationType = HAL_OSPI_OPTYPE_COMMON_CFG;
sCommand.FlashId = HAL_OSPI_FLASH_ID_1;
s_command.Instruction = MX25LM51245G_OCTA_SECTOR_ERASE_64K_CMD;
s_command.InstructionMode = HAL_OSPI_INSTRUCTION_8_LINES;
s_command.InstructionDtrMode = HAL_OSPI_INSTRUCTION_DTR_DISABLE;
s_command.InstructionSize = HAL_OSPI_INSTRUCTION_16_BITS;
s_command.AddressMode = HAL_OSPI_ADDRESS_8_LINES;
s_command.AddressDtrMode = HAL_OSPI_ADDRESS_DTR_DISABLE;
s_command.AddressSize = HAL_OSPI_ADDRESS_32_BITS;
s_command.Address = Address;
s_command.AlternateBytesMode = HAL_OSPI_ALTERNATE_BYTES_NONE;
s_command.DataMode = HAL_OSPI_DATA_NONE;
s_command.DummyCycles = 0U;
s_command.DQSMode = HAL_OSPI_DQS_DISABLE;
s_command.SIOOMode = HAL_OSPI_SIOO_INST_EVERY_CMD;
2024-04-06 10:46 AM
I think a lot of those examples where just copy- pasted, without actually testing them.
I found library for this octo flash
https://github.com/STMicroelectronics/stm32-mx25lm51245g/tree/main
it looks like the whole thing
all those functions do something without giving error code.
but I cannot write and read it. It actually looks like it writes without error code but I am not reading the same data back.
when I try
MX25LM51245G_ReadID(&hospi1, MX25LM51245G_SPI_MODE, MX25LM51245G_STR_TRANSFER, &FlashID);
I get
FlashID = 0xC2
so something is working
but it does not have main.c to see how the code looks like, maybe I am missing some configuration.
There are a few cheap Discovery boards with this octo flash it might be the best way to see where the problem is assuming the example codes from CubeMX (github) will work on it.
2024-04-06 12:01 PM - edited 2024-04-06 12:02 PM
> I get FlashID = 0xC2
Likely you get also a memory corruption, because the FlashID arg to MX25LM51245G_ReadID is a pointer to array of 3 bytes at least. So two bytes after your FlashID variable were overwritten. This can cause undefined behavior.
2024-04-06 01:46 PM
I changed to 3 byte array (previously uint8_t FlashID; )
uint8_t FlashID[3];
MX25LM51245G_ReadID(&hospi1, MX25LM51245G_SPI_MODE, MX25LM51245G_STR_TRANSFER, FlashID)
now I get
FlashID[0] = 0xC3
FlashID[1]= 0x85
FlashID[2]=0x3A
so, do you think that the memory is working ?
2024-04-06 02:12 PM
What is your pin configuration? The same as the DISCO board?
What are you trying to build? The .STLDR? A loader that runs in application space?
The ReadID is consistent with the data-sheet
https://www.mxic.com.tw/Lists/Datasheet/Attachments/8729/MX25LM51245G,%203V,%20512Mb,%20v1.1.pdf
2024-04-06 02:46 PM
not exactly the same pins numbers but it is connected OCTOSPI1, on disco board to OCTOPSPI2, the same memory chip.
I want to try STLDR later I have seen some codes on guthub. for now I want to get to write and read data. all those examples use HAL driver. so all is the same. I guess I am missing something, some FLASH configuration setup.
2024-04-06 03:08 PM - edited 2024-04-06 03:12 PM
.
2024-04-06 05:18 PM
OCTOSPI1
2024-04-06 06:11 PM
Tentative patch of the loader
2024-04-07 06:31 AM
thanks for all the info I appreciate, it will take time to go through all of this to get it working.
there are lot of discrepancies in the examples
for example in: (for STM32H7B3I_DK board)
STM32Cube\Example\OSPI_NOR_ReadWrite_DMA\
in the main.c
OSPIHandle.Init.FifoThreshold = 4;
OSPIHandle.Init.DualQuad = HAL_OSPI_DUALQUAD_DISABLE;
OSPIHandle.Init.MemoryType = HAL_OSPI_MEMTYPE_MICRON;
OSPIHandle.Init.DeviceSize = OSPI_FLASH_SIZE;
OSPIHandle.Init.ChipSelectHighTime = 2;
while in the header (main.h)
/* MX25LM512ABA1G12 Macronix memory */
/* Size of the flash */
#define OSPI_FLASH_SIZE 26
#define OSPI_PAGE_SIZE 256
they mix Macronix with Micron, I doubt that the codes were ever tested, just copied and pasted