zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.33k stars 6.33k forks source link

stm32 flash ospi fails on stm32l5 and stm32u5 disco #46740

Closed FRASTM closed 2 years ago

FRASTM commented 2 years ago

Describe the bug When testing the samples/drivers/spi_flash on b_u585i_iot02a or stm32l562e_dk the error occurs : "SPI flash driver MX25LM51245 was not found!"

To Reproduce Steps to reproduce the behavior:

  1. west build -p auto -b stm32l562e_dk samples/drivers/spi_flash
  2. west flash
  3. See error

Expected behavior

JEDEC OSPI-NOR SPI flash testing
==========================

Test 1: Flash erase
Flash erase succeeded!

Test 2: Flash write
Attempting to write 4 bytes
Data read matches data written. Good!!

Impact regression after the merge of the https://github.com/zephyrproject-rtos/zephyr/pull/45917

Logs and console output

*** Booting Zephyr OS build zephyr-v3.1.0-582-gcefd74f0444f  ***

JEDEC OSPI-NOR SPI flash testing                                            
==========================                                                  
SPI flash driver MX25LM51245 was not found!                                 
[00:00:05.141,000] <err> flash_stm32_ospi: OSPI AutoPoll failed             
[00:00:05.141,000] <err> flash_stm32_ospi: OSPI flash busy failed           
[00:00:05.141,000] <err> flash_stm32_ospi: OSPI mode not config'd (8 rate 2)
[00:00:05.141,000] <dbg> flash_stm32: stm32_flash_init: Flash initialized. BS: 8
[00:00:05.141,000] <dbg> flash_stm32: stm32_flash_init: Block 0: bs: 2048 count: 256
[00:00:05.141,000] <dbg> flash_stm32: stm32_flash_init: Block 1: bs: 0 count: 0
[00:00:05.141,000] <dbg> flash_stm32: stm32_flash_init: Block 2: bs: 0 count: 0
[00:00:05.141,000] <dbg> flash_stm32: flash_stm32_write_protection: Disable write protection

Environment (please complete the following information):

Additional context

FRASTM commented 2 years ago

In the stm32_ospi_write_enable() function, two commands are issued to the octoflash

  1. with SPINOR(O)CMD_WREN instruction
  2. with SPINOR(O)CMD_RDSR instruction In between some s_command parameters should be updated : .AddressMode, .DataMode

Also, I suspect a pb with the command.AddressSize and the stm32_ospi_hal_address_size badly init'd --> in the flash_stm32_ospi_write() cmd_pp.AddressSize = HAL_OSPI_ADDRESS_32_BITS;

Refering to the AN5050, the command.AddressSize is HAL_OSPI_ADDRESS_32_BITS except in quad mode.

FRASTM commented 2 years ago

see branch https://github.com/FRASTM/zephyr/tree/fix_ospi