@@ -391,26 +391,18 @@ static int ospi_read_jedec_id(const struct device *dev, uint8_t *id)
391
391
}
392
392
#endif /* CONFIG_FLASH_JESD216_API */
393
393
394
+ #if !DT_NODE_HAS_PROP (DT_INST (0 , st_stm32_ospi_nor ), sfdp_bfp )
394
395
/*
395
- * Read Serial Flash Discovery Parameter :
396
+ * Read Serial Flash Discovery Parameter from the octoFlash at init :
396
397
* perform a read access over SPI bus for SDFP (DataMode is already set)
397
- * or get it from the sdfp table (in the DTS)
398
398
*/
399
- static int ospi_read_sfdp (const struct device * dev , off_t addr , uint8_t * data ,
400
- size_t size )
399
+ static int stm32_ospi_read_sfdp (const struct device * dev , off_t addr ,
400
+ void * data ,
401
+ size_t size )
401
402
{
402
403
const struct flash_stm32_ospi_config * dev_cfg = dev -> config ;
403
404
struct flash_stm32_ospi_data * dev_data = dev -> data ;
404
405
405
- #if DT_NODE_HAS_PROP (DT_INST (0 , st_stm32_ospi_nor ), sfdp_bfp )
406
- /* simulate the SDFP */
407
- ARG_UNUSED (addr ); /* addr is 0 */
408
-
409
- for (uint8_t i_ind = 0 ; i_ind < MIN (size , ARRAY_SIZE (dev_cfg -> sfdp_bfp )); i_ind ++ ) {
410
- * (data + i_ind ) = dev_cfg -> sfdp_bfp [i_ind ];
411
- }
412
- #else /* sfdp_bfp */
413
-
414
406
OSPI_RegularCmdTypeDef cmd = ospi_prepare_cmd (dev_cfg -> data_mode ,
415
407
dev_cfg -> data_rate );
416
408
if (dev_cfg -> data_mode == OSPI_OPI_MODE ) {
@@ -436,17 +428,52 @@ static int ospi_read_sfdp(const struct device *dev, off_t addr, uint8_t *data,
436
428
return - EIO ;
437
429
}
438
430
439
- hal_ret = HAL_OSPI_Receive (& dev_data -> hospi , data , HAL_OSPI_TIMEOUT_DEFAULT_VALUE );
431
+ hal_ret = HAL_OSPI_Receive (& dev_data -> hospi , (uint8_t * )data ,
432
+ HAL_OSPI_TIMEOUT_DEFAULT_VALUE );
440
433
if (hal_ret != HAL_OK ) {
441
434
LOG_ERR ("%d: Failed to read data" , hal_ret );
442
435
return - EIO ;
443
436
}
444
437
445
- #endif /* sfdp_bfp */
446
438
dev_data -> cmd_status = 0 ;
447
439
448
440
return 0 ;
449
441
}
442
+ #endif /* ! sfdp_bfp */
443
+
444
+ /*
445
+ * Read Serial Flash Discovery Parameter :
446
+ * perform a read access over SPI bus for SDFP (DataMode is already set)
447
+ * or get it from the sdfp table (in the DTS)
448
+ */
449
+ static int ospi_read_sfdp (const struct device * dev , off_t addr , void * data ,
450
+ size_t size )
451
+ {
452
+ #if DT_NODE_HAS_PROP (DT_INST (0 , st_stm32_ospi_nor ), sfdp_bfp )
453
+ /* There is a sfdp-bfp property in the deviceTree : do not read the flash */
454
+ const struct flash_stm32_ospi_config * dev_cfg = dev -> config ;
455
+
456
+ LOG_INF ("Read SFDP from DTS property" );
457
+ /* If DTS has the sdfp table property, check its length */
458
+ if (size > DT_INST_PROP_LEN (0 , sfdp_bfp )) {
459
+ LOG_ERR ("SDFP bdfp length is wrong (%d)" , DT_INST_PROP_LEN (0 , sfdp_bfp ));
460
+ return - EIO ;
461
+ }
462
+ /* The dev_cfg->sfdp_bfp if filled from the DTS property */
463
+ memcpy (data , dev_cfg -> sfdp_bfp + addr , size );
464
+
465
+ return 0 ;
466
+ #else
467
+ LOG_INF ("Read SFDP from octoFlash" );
468
+ /* Get the SFDP from the octoFlash (no sfdp-bfp table in the DeviceTree) */
469
+ if (stm32_ospi_read_sfdp (dev , addr , data , size ) == 0 ) {
470
+ /* If valid, then ignore any table from the DTS */
471
+ return 0 ;
472
+ }
473
+ LOG_INF ("Error reading SFDP from octoFlash and none in the DTS" );
474
+ return - EINVAL ;
475
+ #endif /* sfdp_bfp */
476
+ }
450
477
451
478
static bool ospi_address_is_valid (const struct device * dev , off_t addr ,
452
479
size_t size )
@@ -1354,6 +1381,7 @@ static const struct flash_driver_api flash_stm32_ospi_driver_api = {
1354
1381
.page_layout = flash_stm32_ospi_pages_layout ,
1355
1382
#endif
1356
1383
#if defined(CONFIG_FLASH_JESD216_API )
1384
+ .sfdp_read = ospi_read_sfdp ,
1357
1385
.read_jedec_id = ospi_read_jedec_id ,
1358
1386
#endif /* CONFIG_FLASH_JESD216_API */
1359
1387
};
@@ -2155,6 +2183,7 @@ static struct flash_stm32_ospi_data flash_stm32_ospi_dev_data = {
2155
2183
},
2156
2184
.qer_type = DT_QER_PROP_OR (0 , JESD216_DW15_QER_VAL_S1B6 ),
2157
2185
.write_opcode = DT_WRITEOC_PROP_OR (0 , SPI_NOR_WRITEOC_NONE ),
2186
+ .page_size = SPI_NOR_PAGE_SIZE , /* by default, to be updated by sfdp */
2158
2187
#if DT_NODE_HAS_PROP (DT_INST (0 , st_stm32_ospi_nor ), jedec_id )
2159
2188
.jedec_id = DT_INST_PROP (0 , jedec_id ),
2160
2189
#endif /* jedec_id */
0 commit comments