@@ -50,24 +50,29 @@ void qspi_prepare_command(const qspi_command_t *command, OSPI_RegularCmdTypeDef
5050
5151 st_command -> FlashId = HAL_OSPI_FLASH_ID_1 ;
5252
53- switch (command -> instruction .bus_width ) {
54- case QSPI_CFG_BUS_SINGLE :
55- st_command -> InstructionMode = HAL_OSPI_INSTRUCTION_1_LINE ;
56- break ;
57- case QSPI_CFG_BUS_DUAL :
58- st_command -> InstructionMode = HAL_OSPI_INSTRUCTION_2_LINES ;
59- break ;
60- case QSPI_CFG_BUS_QUAD :
61- st_command -> InstructionMode = HAL_OSPI_INSTRUCTION_4_LINES ;
62- break ;
63- default :
64- st_command -> InstructionMode = HAL_OSPI_INSTRUCTION_NONE ;
65- break ;
53+ if (command -> instruction .disabled == true) {
54+ st_command -> InstructionMode = HAL_OSPI_INSTRUCTION_NONE ;
55+ st_command -> Instruction = 0 ;
56+ } else {
57+ st_command -> Instruction = command -> instruction .value ;
58+ switch (command -> instruction .bus_width ) {
59+ case QSPI_CFG_BUS_SINGLE :
60+ st_command -> InstructionMode = HAL_OSPI_INSTRUCTION_1_LINE ;
61+ break ;
62+ case QSPI_CFG_BUS_DUAL :
63+ st_command -> InstructionMode = HAL_OSPI_INSTRUCTION_2_LINES ;
64+ break ;
65+ case QSPI_CFG_BUS_QUAD :
66+ st_command -> InstructionMode = HAL_OSPI_INSTRUCTION_4_LINES ;
67+ break ;
68+ default :
69+ error ("Command param error: wrong istruction format\n" );
70+ break ;
71+ }
6672 }
6773
6874 st_command -> InstructionSize = HAL_OSPI_INSTRUCTION_8_BITS ;
6975 st_command -> InstructionDtrMode = HAL_OSPI_INSTRUCTION_DTR_DISABLE ;
70- st_command -> Instruction = command -> instruction .value ;
7176 st_command -> DummyCycles = command -> dummy_count ;
7277 // these are target specific settings, use default values
7378 st_command -> SIOOMode = HAL_OSPI_SIOO_INST_EVERY_CMD ;
@@ -93,7 +98,7 @@ void qspi_prepare_command(const qspi_command_t *command, OSPI_RegularCmdTypeDef
9398 st_command -> AddressMode = HAL_OSPI_ADDRESS_4_LINES ;
9499 break ;
95100 default :
96- st_command -> AddressMode = HAL_OSPI_ADDRESS_NONE ;
101+ error ( "Command param error: wrong address size\n" ) ;
97102 break ;
98103 }
99104 switch (command -> address .size ) {
@@ -110,7 +115,7 @@ void qspi_prepare_command(const qspi_command_t *command, OSPI_RegularCmdTypeDef
110115 st_command -> AddressSize = HAL_OSPI_ADDRESS_32_BITS ;
111116 break ;
112117 default :
113- printf ("Command param error: wrong address size\n" );
118+ error ("Command param error: wrong address size\n" );
114119 break ;
115120 }
116121 }
@@ -284,7 +289,7 @@ qspi_status_t qspi_init(qspi_t *obj, PinName io0, PinName io1, PinName io2, PinN
284289 // Set default OCTOSPI handle values
285290 obj -> handle .Init .DualQuad = HAL_OSPI_DUALQUAD_DISABLE ;
286291 obj -> handle .Init .MemoryType = HAL_OSPI_MEMTYPE_MICRON ;
287- obj -> handle .Init .ClockPrescaler = 4 ;
292+ obj -> handle .Init .ClockPrescaler = 4 ; // default value, will be overwritten in qspi_frequency
288293 obj -> handle .Init .FifoThreshold = 4 ;
289294 obj -> handle .Init .SampleShifting = HAL_OSPI_SAMPLE_SHIFTING_NONE ;
290295 obj -> handle .Init .DeviceSize = POSITION_VAL (QSPI_FLASH_SIZE_DEFAULT ) - 1 ;
@@ -358,11 +363,23 @@ qspi_status_t qspi_init(qspi_t *obj, PinName io0, PinName io1, PinName io2, PinN
358363 obj -> ssel = ssel ;
359364 pinmap_pinout (ssel , PinMap_QSPI_SSEL );
360365
361- OSPIM_Cfg_Struct .ClkPort = 2 ;
362- OSPIM_Cfg_Struct .DQSPort = 2 ;
363- OSPIM_Cfg_Struct .NCSPort = 2 ;
364- OSPIM_Cfg_Struct .IOLowPort = HAL_OSPIM_IOPORT_2_LOW ;
365- OSPIM_Cfg_Struct .IOHighPort = HAL_OSPIM_IOPORT_2_HIGH ;
366+ /* The OctoSPI IO Manager OCTOSPIM configuration is supported in a simplified mode in mbed-os
367+ * QSPI1 signals are mapped to port 1 and QSPI2 signals are mapped to port 2.
368+ * This is coded in this way in PeripheralPins.c */
369+ if (obj -> qspi == QSPI_1 ) {
370+ OSPIM_Cfg_Struct .ClkPort = 1 ;
371+ OSPIM_Cfg_Struct .DQSPort = 1 ;
372+ OSPIM_Cfg_Struct .NCSPort = 1 ;
373+ OSPIM_Cfg_Struct .IOLowPort = HAL_OSPIM_IOPORT_1_LOW ;
374+ OSPIM_Cfg_Struct .IOHighPort = HAL_OSPIM_IOPORT_1_HIGH ;
375+ } else {
376+ OSPIM_Cfg_Struct .ClkPort = 2 ;
377+ OSPIM_Cfg_Struct .DQSPort = 2 ;
378+ OSPIM_Cfg_Struct .NCSPort = 2 ;
379+ OSPIM_Cfg_Struct .IOLowPort = HAL_OSPIM_IOPORT_2_LOW ;
380+ OSPIM_Cfg_Struct .IOHighPort = HAL_OSPIM_IOPORT_2_HIGH ;
381+ }
382+
366383 if (HAL_OSPIM_Config (& obj -> handle , & OSPIM_Cfg_Struct , HAL_OSPI_TIMEOUT_DEFAULT_VALUE ) != HAL_OK )
367384 {
368385 debug_if (qspi_api_c_debug , "HAL_OSPIM_Config error\n" );
0 commit comments