@@ -50,24 +50,29 @@ void qspi_prepare_command(const qspi_command_t *command, OSPI_RegularCmdTypeDef
50
50
51
51
st_command -> FlashId = HAL_OSPI_FLASH_ID_1 ;
52
52
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
+ }
66
72
}
67
73
68
74
st_command -> InstructionSize = HAL_OSPI_INSTRUCTION_8_BITS ;
69
75
st_command -> InstructionDtrMode = HAL_OSPI_INSTRUCTION_DTR_DISABLE ;
70
- st_command -> Instruction = command -> instruction .value ;
71
76
st_command -> DummyCycles = command -> dummy_count ;
72
77
// these are target specific settings, use default values
73
78
st_command -> SIOOMode = HAL_OSPI_SIOO_INST_EVERY_CMD ;
@@ -93,7 +98,7 @@ void qspi_prepare_command(const qspi_command_t *command, OSPI_RegularCmdTypeDef
93
98
st_command -> AddressMode = HAL_OSPI_ADDRESS_4_LINES ;
94
99
break ;
95
100
default :
96
- st_command -> AddressMode = HAL_OSPI_ADDRESS_NONE ;
101
+ error ( "Command param error: wrong address size\n" ) ;
97
102
break ;
98
103
}
99
104
switch (command -> address .size ) {
@@ -110,7 +115,7 @@ void qspi_prepare_command(const qspi_command_t *command, OSPI_RegularCmdTypeDef
110
115
st_command -> AddressSize = HAL_OSPI_ADDRESS_32_BITS ;
111
116
break ;
112
117
default :
113
- printf ("Command param error: wrong address size\n" );
118
+ error ("Command param error: wrong address size\n" );
114
119
break ;
115
120
}
116
121
}
@@ -284,7 +289,7 @@ qspi_status_t qspi_init(qspi_t *obj, PinName io0, PinName io1, PinName io2, PinN
284
289
// Set default OCTOSPI handle values
285
290
obj -> handle .Init .DualQuad = HAL_OSPI_DUALQUAD_DISABLE ;
286
291
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
288
293
obj -> handle .Init .FifoThreshold = 4 ;
289
294
obj -> handle .Init .SampleShifting = HAL_OSPI_SAMPLE_SHIFTING_NONE ;
290
295
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
358
363
obj -> ssel = ssel ;
359
364
pinmap_pinout (ssel , PinMap_QSPI_SSEL );
360
365
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
+
366
383
if (HAL_OSPIM_Config (& obj -> handle , & OSPIM_Cfg_Struct , HAL_OSPI_TIMEOUT_DEFAULT_VALUE ) != HAL_OK )
367
384
{
368
385
debug_if (qspi_api_c_debug , "HAL_OSPIM_Config error\n" );
0 commit comments