@@ -55,7 +55,7 @@ static uint32_t get_alt_bytes_size(const uint32_t num_bytes)
55
55
56
56
ospi_status_t ospi_prepare_command (const ospi_command_t * command , OSPI_RegularCmdTypeDef * st_command )
57
57
{
58
- debug_if (ospi_api_c_debug , "ospi_prepare_command In: instruction.value %x dummy_count %x address.bus_width %x address.disabled %x address.value %x address.size %x\n" ,
58
+ debug_if (ospi_api_c_debug , "ospi_prepare_command In: instruction.value %x dummy_count %u address.bus_width %x address.disabled %x address.value %x address.size %x\n" ,
59
59
command -> instruction .value , command -> dummy_count , command -> address .bus_width , command -> address .disabled , command -> address .value , command -> address .size );
60
60
61
61
st_command -> FlashId = HAL_OSPI_FLASH_ID_1 ;
@@ -255,18 +255,21 @@ static ospi_status_t _ospi_init_direct(ospi_t *obj, const ospi_pinmap_t *pinmap,
255
255
obj -> handle .Init .DeviceSize = 32 ;
256
256
obj -> handle .Init .ChipSelectHighTime = 3 ;
257
257
obj -> handle .Init .FreeRunningClock = HAL_OSPI_FREERUNCLK_DISABLE ;
258
- #if defined(HAL_OSPI_WRAP_NOT_SUPPORTED ) // removed in STM32L4
258
+ #if defined(HAL_OSPI_WRAP_NOT_SUPPORTED )
259
259
obj -> handle .Init .WrapSize = HAL_OSPI_WRAP_NOT_SUPPORTED ;
260
260
#endif
261
261
obj -> handle .Init .ClockMode = mode == 0 ? HAL_OSPI_CLOCK_MODE_0 : HAL_OSPI_CLOCK_MODE_3 ;
262
262
obj -> handle .Init .DelayHoldQuarterCycle = HAL_OSPI_DHQC_ENABLE ;
263
263
obj -> handle .Init .ChipSelectBoundary = 0 ;
264
- #if defined(HAL_OSPI_DELAY_BLOCK_USED ) // STM32L5
264
+ #if defined(HAL_OSPI_DELAY_BLOCK_USED )
265
265
obj -> handle .Init .DelayBlockBypass = HAL_OSPI_DELAY_BLOCK_USED ;
266
266
#endif
267
- #if defined(TARGET_STM32L5 )
267
+ #if defined(TARGET_STM32L5 ) || defined( TARGET_STM32U5 )
268
268
obj -> handle .Init .Refresh = 0 ;
269
269
#endif
270
+ #if defined(OCTOSPI_DCR3_MAXTRAN )
271
+ obj -> handle .Init .MaxTran = 0 ;
272
+ #endif
270
273
271
274
// tested all combinations, take first
272
275
obj -> ospi = pinmap -> peripheral ;
@@ -371,13 +374,13 @@ ospi_status_t ospi_init(ospi_t *obj, PinName io0, PinName io1, PinName io2, PinN
371
374
OSPIName ospiio1name = (OSPIName )pinmap_peripheral (io1 , PinMap_OSPI_DATA1 );
372
375
OSPIName ospiio2name = (OSPIName )pinmap_peripheral (io2 , PinMap_OSPI_DATA2 );
373
376
OSPIName ospiio3name = (OSPIName )pinmap_peripheral (io3 , PinMap_OSPI_DATA3 );
374
- OSPIName ospiio4name = (OSPIName )pinmap_peripheral (io4 , PinMap_OSPI_DATA4 );
375
- OSPIName ospiio5name = (OSPIName )pinmap_peripheral (io5 , PinMap_OSPI_DATA5 );
376
- OSPIName ospiio6name = (OSPIName )pinmap_peripheral (io6 , PinMap_OSPI_DATA6 );
377
- OSPIName ospiio7name = (OSPIName )pinmap_peripheral (io7 , PinMap_OSPI_DATA7 );
377
+ // OSPIName ospiio4name = (OSPIName)pinmap_peripheral(io4, PinMap_OSPI_DATA4); // IO4 pin not checked
378
+ // OSPIName ospiio5name = (OSPIName)pinmap_peripheral(io5, PinMap_OSPI_DATA5); // IO5 pin not checked
379
+ // OSPIName ospiio6name = (OSPIName)pinmap_peripheral(io6, PinMap_OSPI_DATA6); // IO6 pin not checked
380
+ // OSPIName ospiio7name = (OSPIName)pinmap_peripheral(io7, PinMap_OSPI_DATA7); // IO7 pin not checked
378
381
OSPIName ospiclkname = (OSPIName )pinmap_peripheral (sclk , PinMap_OSPI_SCLK );
379
382
OSPIName ospisselname = (OSPIName )pinmap_peripheral (ssel , PinMap_OSPI_SSEL );
380
- OSPIName ospidqsname = (OSPIName )pinmap_peripheral (dqs , PinMap_OSPI_DQS );
383
+ // OSPIName ospidqsname = (OSPIName)pinmap_peripheral(dqs, PinMap_OSPI_DQS); // DQS pin not checked
381
384
382
385
OSPIName ospi_data_first = (OSPIName )pinmap_merge (ospiio0name , ospiio1name );
383
386
OSPIName ospi_data_second = (OSPIName )pinmap_merge (ospiio2name , ospiio3name );
@@ -451,24 +454,29 @@ ospi_status_t ospi_free(ospi_t *obj)
451
454
452
455
ospi_status_t ospi_frequency (ospi_t * obj , int hz )
453
456
{
454
- tr_debug ("ospi_frequency hz %d" , hz );
455
457
ospi_status_t status = OSPI_STATUS_OK ;
456
458
457
- /* HCLK drives OSPI. OSPI clock depends on prescaler value:
459
+ /* OSPI clock depends on prescaler value:
458
460
* 0: Freq = HCLK
459
461
* 1: Freq = HCLK/2
460
462
* ...
461
463
* 255: Freq = HCLK/256 (minimum value)
462
464
*/
463
465
464
- int div = HAL_RCC_GetHCLKFreq () / hz ;
466
+ #if defined(TARGET_STM32L5 )
467
+ uint32_t OSPI_clock_source = HAL_RCC_GetSysClockFreq ();
468
+ #else
469
+ uint32_t OSPI_clock_source = HAL_RCCEx_GetPeriphCLKFreq (RCC_PERIPHCLK_OSPI );
470
+ #endif
471
+ int div = OSPI_clock_source / hz ;
465
472
if (div > 255 ) {
466
473
div = 255 ;
467
474
} else {
468
- if (div == 1 ) {
475
+ if (OSPI_clock_source % hz != 0 ) {
469
476
div = div + 1 ;
470
477
}
471
478
}
479
+ tr_debug ("ospi_frequency hz %d source %d Prescaler %d" , hz , OSPI_clock_source , div );
472
480
473
481
obj -> handle .Init .ClockPrescaler = div ;
474
482
0 commit comments