@@ -389,15 +389,18 @@ qspi_status_t qspi_init_direct(qspi_t *obj, const qspi_pinmap_t *pinmap, uint32_
389389static qspi_status_t _qspi_init_direct (qspi_t * obj , const qspi_pinmap_t * pinmap , uint32_t hz , uint8_t mode )
390390#endif
391391{
392- OSPIM_CfgTypeDef OSPIM_Cfg_Struct = {0 };
393392 debug_if (qspi_api_c_debug , "qspi_init mode %u\n" , mode );
394393
395394 // Reset handle internal state
396395 obj -> handle .State = HAL_OSPI_STATE_RESET ;
397396
398397 // Set default OCTOSPI handle values
399398 obj -> handle .Init .DualQuad = HAL_OSPI_DUALQUAD_DISABLE ;
400- obj -> handle .Init .MemoryType = HAL_OSPI_MEMTYPE_MICRON ;
399+ #if defined(TARGET_MX25LM51245G )
400+ obj -> handle .Init .MemoryType = HAL_OSPI_MEMTYPE_MACRONIX ; // Read sequence in DTR mode: D1-D0-D3-D2
401+ #else
402+ obj -> handle .Init .MemoryType = HAL_OSPI_MEMTYPE_MICRON ; // Read sequence in DTR mode: D0-D1-D2-D3
403+ #endif
401404 obj -> handle .Init .ClockPrescaler = 4 ; // default value, will be overwritten in qspi_frequency
402405 obj -> handle .Init .FifoThreshold = 4 ;
403406 obj -> handle .Init .SampleShifting = HAL_OSPI_SAMPLE_SHIFTING_NONE ;
@@ -408,6 +411,9 @@ static qspi_status_t _qspi_init_direct(qspi_t *obj, const qspi_pinmap_t *pinmap,
408411 obj -> handle .Init .ClockMode = mode == 0 ? HAL_OSPI_CLOCK_MODE_0 : HAL_OSPI_CLOCK_MODE_3 ;
409412 obj -> handle .Init .DelayHoldQuarterCycle = HAL_OSPI_DHQC_ENABLE ;
410413 obj -> handle .Init .ChipSelectBoundary = 0 ;
414+ #if defined(HAL_OSPI_DELAY_BLOCK_USED ) // STM32L5
415+ obj -> handle .Init .DelayBlockBypass = HAL_OSPI_DELAY_BLOCK_USED ;
416+ #endif
411417
412418 // tested all combinations, take first
413419 obj -> qspi = pinmap -> peripheral ;
@@ -426,15 +432,13 @@ static qspi_status_t _qspi_init_direct(qspi_t *obj, const qspi_pinmap_t *pinmap,
426432#if defined(OCTOSPI1 )
427433 if (obj -> qspi == QSPI_1 ) {
428434 __HAL_RCC_OSPI1_CLK_ENABLE ();
429- __HAL_RCC_OSPIM_CLK_ENABLE ();
430435 __HAL_RCC_OSPI1_FORCE_RESET ();
431436 __HAL_RCC_OSPI1_RELEASE_RESET ();
432437 }
433438#endif
434439#if defined(OCTOSPI2 )
435440 if (obj -> qspi == QSPI_2 ) {
436441 __HAL_RCC_OSPI2_CLK_ENABLE ();
437- __HAL_RCC_OSPIM_CLK_ENABLE ();
438442 __HAL_RCC_OSPI2_FORCE_RESET ();
439443 __HAL_RCC_OSPI2_RELEASE_RESET ();
440444 }
@@ -461,6 +465,11 @@ static qspi_status_t _qspi_init_direct(qspi_t *obj, const qspi_pinmap_t *pinmap,
461465 pin_function (pinmap -> ssel_pin , pinmap -> ssel_function );
462466 pin_mode (pinmap -> ssel_pin , PullNone );
463467
468+ #if defined(OCTOSPI2 )
469+ __HAL_RCC_OSPIM_CLK_ENABLE ();
470+
471+ OSPIM_CfgTypeDef OSPIM_Cfg_Struct = {0 };
472+
464473 /* The OctoSPI IO Manager OCTOSPIM configuration is supported in a simplified mode in mbed-os
465474 * QSPI1 signals are mapped to port 1 and QSPI2 signals are mapped to port 2.
466475 * This is coded in this way in PeripheralPins.c */
@@ -482,6 +491,7 @@ static qspi_status_t _qspi_init_direct(qspi_t *obj, const qspi_pinmap_t *pinmap,
482491 debug_if (qspi_api_c_debug , "HAL_OSPIM_Config error\n" );
483492 return QSPI_STATUS_ERROR ;
484493 }
494+ #endif
485495
486496 return qspi_frequency (obj , hz );
487497}
0 commit comments