cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L4R5ZI - Octospi bug in code generation

Seegras
Associate II

I am using the interfaces octospi1 and octospi2 to interface two qspi-nor flashes.

The interfaces are configured the following way:

  • Quad spi (octospi 1 uses low port 1 and octospi 2 uses low port 2)
  • CLK (octospi 1 uses port 1 and octospi 2 uses port 2)
  • NCS is disabled on both instances since I am using an external GPIO for this.

After the second instance got initialized with the call to MX_OCTOSPI2_Init(); it appears that the first instance gets disabled in the octospi manager.

I tracked the issue down to the check where the HAL_OSPIM_Config function verifies that there is no conflicting configuration between the two instances. Unfortunately this check does not respect the fact that some ports can be disabled and deactivates the other instance if both instances have the same ports disabled. As for example, in my example above, where the NCSPort, IOHighPort and DQSPort are disabled for both instances.

This should not be the case since this is clearly not a conflicting situation in my opinion.

HAL version from the ioc file:

MxCube.Version=6.3.0

MxDb.Version=DB.6.0.30

from the file stm32l4xx_hal.c:

#define STM32L4XX_HAL_VERSION_MAIN  (0x01U) /*!< [31:24] main version */

#define STM32L4XX_HAL_VERSION_SUB1  (0x0DU) /*!< [23:16] sub1 version */

#define STM32L4XX_HAL_VERSION_SUB2  (0x00U) /*!< [15:8] sub2 version */

#define STM32L4XX_HAL_VERSION_RC    (0x00U) /*!< [7:0] release candidate */

#define STM32L4XX_HAL_VERSION       ((STM32L4XX_HAL_VERSION_MAIN << 24U)\

                                     |(STM32L4XX_HAL_VERSION_SUB1 << 16U)\

                                     |(STM32L4XX_HAL_VERSION_SUB2 << 8U)\

                                     |(STM32L4XX_HAL_VERSION_RC))

The following fix helped me to bypass the problem but I am not 100% sure about side effects etc. Can you please confirm that this is indeed a bug or did I something wrong with the configuration?

Thank you a lot in advance for any help or pointers!

Updated patch:

Date: Thu, 19 Aug 2021 12:17:45 +0200
Subject: [PATCH] Fixed bug in octospi manager hal init
 
Without this fix the second instance gets disabled if one of the
IO-Ports is not used. Even thought there will be no conflict between the
instances since the specified port is not used.
 
Example: Bot octospi interfaces are configured to use quad mode.
This means the DQSPort and IOHighPort will be initialized to 0 for both
instances. In this case the second octospi initialization call will
disable the first instance since it assumes it has the same
configuration which will lead to conflicts.
 
Same would apply if one decides to use external GPIO chip selects and
leave the NSCPort uninitialized.
 
To fix this problem an additional check has been added to first if the
specific Port is not initialized. In this case it is assumed there is no
conflict for this port and the check proceeds with the next one.
 
Additionally the assertion which verifies the NCSPort input has been
changed to accept 0 for the case of an unused NCSPort. This needed an
additional step to verify the passed NCSPort is not 0 before configuring
the PCR register.
---
 .../STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_ospi.h  |  2 ++
 .../STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_ospi.c  | 14 +++++++++-----
 2 files changed, 11 insertions(+), 5 deletions(-)
 
diff --git a/Source/Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_ospi.h b/Source/Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_ospi.h
index 35210ee..767ebfa 100644
--- a/Source/Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_ospi.h
+++ b/Source/Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_ospi.h
@@ -1014,6 +1014,8 @@ HAL_StatusTypeDef     HAL_OSPIM_Config              (OSPI_HandleTypeDef *hospi,
 
 #define IS_OSPIM_DQS_PORT(NUMBER)          ((NUMBER) <= 2U)
 
+#define IS_OSPIM_CS_PORT(NUMBER)           ((NUMBER) <= 2U)
+
 #define IS_OSPIM_IO_PORT(PORT)             (((PORT) == HAL_OSPIM_IOPORT_NONE)  || \
                                             ((PORT) == HAL_OSPIM_IOPORT_1_LOW)  || \
                                             ((PORT) == HAL_OSPIM_IOPORT_1_HIGH) || \
diff --git a/Source/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_ospi.c b/Source/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_ospi.c
index 9979053..f0a9690 100644
--- a/Source/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_ospi.c
+++ b/Source/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_ospi.c
@@ -2496,7 +2496,7 @@ HAL_StatusTypeDef HAL_OSPIM_Config(OSPI_HandleTypeDef *hospi, OSPIM_CfgTypeDef *
   /* Check the parameters of the OctoSPI IO Manager configuration structure */
   assert_param(IS_OSPIM_PORT(cfg->ClkPort));
   assert_param(IS_OSPIM_DQS_PORT(cfg->DQSPort));
-  assert_param(IS_OSPIM_PORT(cfg->NCSPort));
+  assert_param(IS_OSPIM_CS_PORT(cfg->NCSPort));
   assert_param(IS_OSPIM_IO_PORT(cfg->IOLowPort));
   assert_param(IS_OSPIM_IO_PORT(cfg->IOHighPort));
 #if   defined (OCTOSPIM_CR_MUXEN)
@@ -2587,9 +2587,11 @@ HAL_StatusTypeDef HAL_OSPIM_Config(OSPI_HandleTypeDef *hospi, OSPIM_CfgTypeDef *
 #endif
 
     /********************* Deactivation of other instance *********************/
-    if ((cfg->ClkPort == IOM_cfg[other_instance].ClkPort) || (cfg->DQSPort == IOM_cfg[other_instance].DQSPort)     ||
-        (cfg->NCSPort == IOM_cfg[other_instance].NCSPort) || (cfg->IOLowPort == IOM_cfg[other_instance].IOLowPort) ||
-        (cfg->IOHighPort == IOM_cfg[other_instance].IOHighPort))
+    if (((cfg->ClkPort != 0) && (cfg->ClkPort == IOM_cfg[other_instance].ClkPort)) ||
+        ((cfg->DQSPort != 0) && (cfg->DQSPort == IOM_cfg[other_instance].DQSPort)) ||
+        ((cfg->NCSPort != 0) && (cfg->NCSPort == IOM_cfg[other_instance].NCSPort)) ||
+        ((cfg->IOLowPort != HAL_OSPIM_IOPORT_NONE) && (cfg->IOLowPort == IOM_cfg[other_instance].IOLowPort)) ||
+        ((cfg->IOHighPort != HAL_OSPIM_IOPORT_NONE) && (cfg->IOHighPort == IOM_cfg[other_instance].IOHighPort)))
     {
 #if   defined (OCTOSPIM_CR_MUXEN)
       if ((cfg->ClkPort   == IOM_cfg[other_instance].ClkPort)   && (cfg->DQSPort    == IOM_cfg[other_instance].DQSPort) &&
@@ -2621,7 +2623,9 @@ HAL_StatusTypeDef HAL_OSPIM_Config(OSPI_HandleTypeDef *hospi, OSPIM_CfgTypeDef *
     }
 
     /******************** Activation of new configuration *********************/
-    MODIFY_REG(OCTOSPIM->PCR[(cfg->NCSPort-1U)], (OCTOSPIM_PCR_NCSEN | OCTOSPIM_PCR_NCSSRC), (OCTOSPIM_PCR_NCSEN | (instance << OCTOSPIM_PCR_NCSSRC_Pos)));
+    if (cfg->NCSPort != 0U) {
+      MODIFY_REG(OCTOSPIM->PCR[(cfg->NCSPort-1U)], (OCTOSPIM_PCR_NCSEN | OCTOSPIM_PCR_NCSSRC), (OCTOSPIM_PCR_NCSEN | (instance << OCTOSPIM_PCR_NCSSRC_Pos)));
+    }
 
 #if   defined (OCTOSPIM_CR_MUXEN)
     if ((cfg->Req2AckTime - 1U) > ((OCTOSPIM->CR & OCTOSPIM_CR_REQ2ACK_TIME) >> OCTOSPIM_CR_REQ2ACK_TIME_Pos))
-- 
2.30.2

0 REPLIES 0