cancel
Showing results for 
Search instead for 
Did you mean: 

what is HAL_OSPI_AutoPolling() ? how to fix it ?

MNapi
Senior III

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.

28 REPLIES 28

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;

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

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.

 

Pavel A.
Evangelist III

> 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.

 

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 ?

 

 

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

P1.pngP2.png

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.

 

 

.

Tentative patch of the loader

https://github.com/cturvey/stm32extldr/blob/main/h7_mx25lm51245g/CLIVEONE-MX25LM51245G_STM32H7X3-PB2-PB6-PA1-PF8-PF9-PF7-PF6-PD4-PC2-PC3-PD7.stldr

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

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