Skip to content

Commit e2ca71d

Browse files
committed
STM32U5: generic STM32 driver files update
1 parent 69c7cb4 commit e2ca71d

File tree

7 files changed

+88
-15
lines changed

7 files changed

+88
-15
lines changed

targets/TARGET_STM/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ add_subdirectory(TARGET_STM32L0 EXCLUDE_FROM_ALL)
1414
add_subdirectory(TARGET_STM32L1 EXCLUDE_FROM_ALL)
1515
add_subdirectory(TARGET_STM32L4 EXCLUDE_FROM_ALL)
1616
add_subdirectory(TARGET_STM32L5 EXCLUDE_FROM_ALL)
17+
add_subdirectory(TARGET_STM32U5 EXCLUDE_FROM_ALL)
1718
add_subdirectory(TARGET_STM32WB EXCLUDE_FROM_ALL)
1819
add_subdirectory(TARGET_STM32WL EXCLUDE_FROM_ALL)
1920

targets/TARGET_STM/gpio_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ GPIO_TypeDef *Set_GPIO_Clock(uint32_t port_idx)
7575
#endif
7676
#if defined GPIOG_BASE
7777
case PortG:
78-
#if defined PWR_CR2_IOSV /* TARGET_STM32L4 / TARGET_STM32L5 */
78+
#if defined PWR_CR2_IOSV /* TARGET_STM32L4 - TARGET_STM32L5 - TARGET_STM32G0 */ || defined PWR_SVMCR_IO2VMEN /* TARGET_STM32U5 */
7979
__HAL_RCC_PWR_CLK_ENABLE();
8080
HAL_PWREx_EnableVddIO2();
8181
#endif

targets/TARGET_STM/gpio_irq_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ void gpio_irq_enable(gpio_irq_t *obj)
502502

503503
/* Select Source */
504504

505-
#if defined(STM32G0) || defined(STM32L5)
505+
#if defined(STM32G0) || defined(STM32L5) || defined(STM32U5)
506506
temp = EXTI->EXTICR[pin_index >> 2];
507507
CLEAR_BIT(temp, (0x0FU) << (8U * (pin_index & 0x03U)));
508508
SET_BIT(temp, port_index << (8U * (pin_index & 0x03U)));

targets/TARGET_STM/lp_ticker.c

Lines changed: 74 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -262,35 +262,43 @@ void lp_ticker_init(void)
262262
#else
263263
LptimHandle.Init.Clock.Prescaler = LPTIM_PRESCALER_DIV1;
264264
#endif /* MBED_CONF_TARGET_LPTICKER_LPTIM_CLOCK */
265-
266265
LptimHandle.Init.Trigger.Source = LPTIM_TRIGSOURCE_SOFTWARE;
267266
#if defined (LPTIM_ACTIVEEDGE_FALLING)
268267
LptimHandle.Init.Trigger.ActiveEdge = LPTIM_ACTIVEEDGE_FALLING;
269268
#endif
269+
#if defined(TARGET_STM32U5)
270+
LptimHandle.Init.Period = 0xFFFF;
271+
#endif
270272
#if defined (LPTIM_TRIGSAMPLETIME_DIRECTTRANSITION)
271273
LptimHandle.Init.Trigger.SampleTime = LPTIM_TRIGSAMPLETIME_DIRECTTRANSITION;
272274
#endif
273-
274-
LptimHandle.Init.UltraLowPowerClock.SampleTime = LPTIM_TRIGSAMPLETIME_DIRECTTRANSITION; // L5 ?
275-
275+
#if defined(LPTIM_CLOCKPOLARITY_RISING)
276+
LptimHandle.Init.UltraLowPowerClock.Polarity = LPTIM_CLOCKPOLARITY_RISING;
277+
LptimHandle.Init.UltraLowPowerClock.SampleTime = LPTIM_CLOCKSAMPLETIME_DIRECTTRANSITION;
278+
#endif
279+
#if defined(LPTIM_OUTPUTPOLARITY_HIGH)
276280
LptimHandle.Init.OutputPolarity = LPTIM_OUTPUTPOLARITY_HIGH;
281+
#endif
277282
LptimHandle.Init.UpdateMode = LPTIM_UPDATE_IMMEDIATE;
278283
LptimHandle.Init.CounterSource = LPTIM_COUNTERSOURCE_INTERNAL;
279-
#if defined (LPTIM_INPUT1SOURCE_GPIO) /* STM32L4 / STM32L5 */
284+
#if defined (LPTIM_INPUT1SOURCE_GPIO)
280285
LptimHandle.Init.Input1Source = LPTIM_INPUT1SOURCE_GPIO;
281286
LptimHandle.Init.Input2Source = LPTIM_INPUT2SOURCE_GPIO;
282287
#endif /* LPTIM_INPUT1SOURCE_GPIO */
283-
284-
#if defined(LPTIM_RCR_REP) /* STM32L4 / STM32L5 */
288+
#if defined(LPTIM_RCR_REP)
285289
LptimHandle.Init.RepetitionCounter = 0;
286290
#endif /* LPTIM_RCR_REP */
287291

288-
289292
if (HAL_LPTIM_Init(&LptimHandle) != HAL_OK) {
290293
error("HAL_LPTIM_Init ERROR\n");
291294
return;
292295
}
293296

297+
#if defined(__HAL_RCC_LPTIM1_CLKAM_ENABLE)
298+
/* Enable autonomous mode for LPTIM1 */
299+
__HAL_RCC_LPTIM1_CLKAM_ENABLE();
300+
#endif
301+
294302
NVIC_SetVector(LPTIM_MST_IRQ, (uint32_t)LPTIM_IRQHandler);
295303

296304
#if (LPTIM_MST_BASE == LPTIM1_BASE)
@@ -306,8 +314,25 @@ void lp_ticker_init(void)
306314
__HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE();
307315
#endif
308316

317+
#if defined(LPTIM_FLAG_DIEROK)
318+
HAL_LPTIM_Counter_Start(&LptimHandle);
319+
320+
__HAL_LPTIM_CLEAR_FLAG(&LptimHandle, LPTIM_FLAG_DIEROK);
321+
__HAL_LPTIM_ENABLE_IT(&LptimHandle, LPTIM_IT_CC1 | LPTIM_IT_CMP1OK);
322+
while (__HAL_LPTIM_GET_FLAG(&LptimHandle, LPTIM_FLAG_DIEROK) == RESET) {
323+
}
324+
325+
/* Need to write a compare value in order to get LPTIM_FLAG_CMPOK in set_interrupt */
326+
__HAL_LPTIM_CLEAR_FLAG(&LptimHandle, LPTIM_FLAG_CMP1OK);
327+
__HAL_LPTIM_COMPARE_SET(&LptimHandle, LPTIM_CHANNEL_1, 0);
328+
while (__HAL_LPTIM_GET_FLAG(&LptimHandle, LPTIM_FLAG_CMP1OK) == RESET) {
329+
}
330+
__HAL_LPTIM_CLEAR_FLAG(&LptimHandle, LPTIM_FLAG_CMP1OK);
331+
332+
#else
309333
__HAL_LPTIM_ENABLE_IT(&LptimHandle, LPTIM_IT_CMPM);
310334
__HAL_LPTIM_ENABLE_IT(&LptimHandle, LPTIM_IT_CMPOK);
335+
311336
HAL_LPTIM_Counter_Start(&LptimHandle, 0xFFFF);
312337

313338
/* Need to write a compare value in order to get LPTIM_FLAG_CMPOK in set_interrupt */
@@ -316,6 +341,7 @@ void lp_ticker_init(void)
316341
while (__HAL_LPTIM_GET_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK) == RESET) {
317342
}
318343
__HAL_LPTIM_CLEAR_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK);
344+
#endif
319345

320346
/* Init is called with Interrupts disabled, so the CMPOK interrupt
321347
* will not be handled. Let's mark it is now safe to write to LP counter */
@@ -330,22 +356,42 @@ static void LPTIM_IRQHandler(void)
330356
lp_Fired = 0;
331357
/* We're already in handler and interrupt might be pending,
332358
* so clear the flag, to avoid calling irq_handler twice */
359+
#if defined(LPTIM_FLAG_CC1)
360+
__HAL_LPTIM_CLEAR_FLAG(&LptimHandle, LPTIM_FLAG_CC1);
361+
#else
333362
__HAL_LPTIM_CLEAR_FLAG(&LptimHandle, LPTIM_FLAG_CMPM);
363+
#endif
334364
lp_ticker_irq_handler();
335365
}
336366

337367
/* Compare match interrupt */
368+
#if defined(LPTIM_FLAG_CC1)
369+
if (__HAL_LPTIM_GET_FLAG(&LptimHandle, LPTIM_FLAG_CC1) != RESET) {
370+
if (__HAL_LPTIM_GET_IT_SOURCE(&LptimHandle, LPTIM_IT_CC1) != RESET) {
371+
/* Clear Compare match flag */
372+
__HAL_LPTIM_CLEAR_FLAG(&LptimHandle, LPTIM_FLAG_CC1);
373+
lp_ticker_irq_handler();
374+
}
375+
}
376+
#else
338377
if (__HAL_LPTIM_GET_FLAG(&LptimHandle, LPTIM_FLAG_CMPM) != RESET) {
339378
if (__HAL_LPTIM_GET_IT_SOURCE(&LptimHandle, LPTIM_IT_CMPM) != RESET) {
340379
/* Clear Compare match flag */
341380
__HAL_LPTIM_CLEAR_FLAG(&LptimHandle, LPTIM_FLAG_CMPM);
342381
lp_ticker_irq_handler();
343382
}
344383
}
384+
#endif
345385

386+
#if defined(LPTIM_FLAG_CMP1OK)
387+
if (__HAL_LPTIM_GET_FLAG(&LptimHandle, LPTIM_FLAG_CMP1OK) != RESET) {
388+
if (__HAL_LPTIM_GET_IT_SOURCE(&LptimHandle, LPTIM_IT_CMP1OK) != RESET) {
389+
__HAL_LPTIM_CLEAR_FLAG(&LptimHandle, LPTIM_FLAG_CMP1OK);
390+
#else
346391
if (__HAL_LPTIM_GET_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK) != RESET) {
347392
if (__HAL_LPTIM_GET_IT_SOURCE(&LptimHandle, LPTIM_IT_CMPOK) != RESET) {
348393
__HAL_LPTIM_CLEAR_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK);
394+
#endif
349395
lp_cmpok = true;
350396
if (sleep_manager_locked) {
351397
sleep_manager_unlock_deep_sleep();
@@ -379,11 +425,11 @@ static void LPTIM_IRQHandler(void)
379425
}
380426
}
381427

382-
383428
#if defined (__HAL_LPTIM_WAKEUPTIMER_EXTI_CLEAR_FLAG)
384429
/* EXTI lines are not configured by default */
385430
__HAL_LPTIM_WAKEUPTIMER_EXTI_CLEAR_FLAG();
386431
#endif
432+
387433
core_util_critical_section_exit();
388434
}
389435

@@ -466,10 +512,19 @@ void lp_ticker_set_interrupt(timestamp_t timestamp)
466512
*/
467513
if ((timestamp < last_read_counter) && (last_read_counter <= (0xFFFF - LP_TIMER_SAFE_GUARD))) {
468514
/* Workaround, because limitation */
515+
#if defined(LPTIM_CHANNEL_1)
516+
__HAL_LPTIM_COMPARE_SET(&LptimHandle, LPTIM_CHANNEL_1, ~0);
517+
#else
469518
__HAL_LPTIM_COMPARE_SET(&LptimHandle, ~0);
519+
#endif
470520
} else {
471521
/* It is safe to write */
522+
#if defined(LPTIM_CHANNEL_1)
523+
__HAL_LPTIM_COMPARE_SET(&LptimHandle, LPTIM_CHANNEL_1, timestamp);
524+
#else
472525
__HAL_LPTIM_COMPARE_SET(&LptimHandle, timestamp);
526+
#endif
527+
473528
}
474529

475530
/* We just programed the CMP so we'll need to wait for cmpok before
@@ -501,9 +556,15 @@ void lp_ticker_disable_interrupt(void)
501556
core_util_critical_section_enter();
502557

503558
if (!lp_cmpok) {
559+
#if defined(LPTIM_FLAG_CMP1OK)
560+
while (__HAL_LPTIM_GET_FLAG(&LptimHandle, LPTIM_FLAG_CMP1OK) == RESET) {
561+
}
562+
__HAL_LPTIM_CLEAR_FLAG(&LptimHandle, LPTIM_FLAG_CMP1OK);
563+
#else
504564
while (__HAL_LPTIM_GET_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK) == RESET) {
505565
}
506566
__HAL_LPTIM_CLEAR_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK);
567+
#endif
507568
lp_cmpok = true;
508569
}
509570
/* now that CMPOK is set, allow deep sleep again */
@@ -522,7 +583,11 @@ void lp_ticker_disable_interrupt(void)
522583
void lp_ticker_clear_interrupt(void)
523584
{
524585
core_util_critical_section_enter();
586+
#if defined(LPTIM_FLAG_CC1)
587+
__HAL_LPTIM_CLEAR_FLAG(&LptimHandle, LPTIM_FLAG_CC1);
588+
#else
525589
__HAL_LPTIM_CLEAR_FLAG(&LptimHandle, LPTIM_FLAG_CMPM);
590+
#endif
526591
NVIC_ClearPendingIRQ(LPTIM_MST_IRQ);
527592
core_util_critical_section_exit();
528593
}

targets/TARGET_STM/serial_api.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,13 @@ void serial_baud(serial_t *obj, int baudrate)
417417
return;
418418
}
419419
#endif
420+
#if ((MBED_CONF_TARGET_LPUART_CLOCK_SOURCE) & USE_LPUART_CLK_PCLK3)
421+
PeriphClkInitStruct.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_PCLK3;
422+
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
423+
if (init_uart(obj) == HAL_OK) {
424+
return;
425+
}
426+
#endif
420427
#if ((MBED_CONF_TARGET_LPUART_CLOCK_SOURCE) & USE_LPUART_CLK_HSI)
421428
// Enable HSI in case it is not already done
422429
if (!__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY)) {

targets/TARGET_STM/trng_api.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void trng_init(trng_t *obj)
3737
{
3838
uint32_t dummy;
3939

40-
#if defined(RCC_PERIPHCLK_RNG) /* STM32L4 */ /* STM32H7 */ /* STM32WB */ /* STM32G4 */ /* STM32WL */
40+
#if defined(RCC_PERIPHCLK_RNG)
4141

4242
#if defined(TARGET_STM32WB)
4343
/* No need to configure RngClockSelection as already done in SetSysClock */
@@ -98,8 +98,8 @@ void trng_init(trng_t *obj)
9898
error("RNG clock configuration error\n");
9999
}
100100

101-
#elif defined(TARGET_STM32L5)
102-
/* No need to reconfigure RngClockSelection as alreday done in SetSysClock */
101+
#elif defined(TARGET_STM32L5) || defined(TARGET_STM32U5)
102+
/* No need to reconfigure RngClockSelection as already done in SetSysClock */
103103

104104
#else
105105
#error("RNG clock not configured");

targets/TARGET_STM/watchdog_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ watchdog_features_t hal_watchdog_get_platform_features(void)
137137
features.clock_max_frequency = 47000;
138138
#elif defined(STM32F0) || defined(STM32F3)
139139
features.clock_max_frequency = 50000;
140-
#elif defined(STM32H7) || defined(STM32L4)
140+
#elif defined(STM32H7) || defined(STM32L4) || defined(STM32U5)
141141
features.clock_max_frequency = 33600;
142142
#elif defined(STM32G0) || defined(STM32L5) || defined(STM32G4) || defined(STM32WB) || defined(STM32WL)
143143
features.clock_max_frequency = 34000;

0 commit comments

Comments
 (0)