Skip to content

Commit 302b720

Browse files
committed
Update core to support WB
Signed-off-by: Frederic.Pillon <[email protected]>
1 parent 37082fd commit 302b720

File tree

10 files changed

+66
-21
lines changed

10 files changed

+66
-21
lines changed

cores/arduino/stm32/analog.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ uint16_t adc_read_value(PinName pin)
554554
}
555555

556556
AdcChannelConf.Channel = get_adc_channel(pin); /* Specifies the channel to configure into ADC */
557-
#ifdef STM32L4xx
557+
#if defined(STM32L4xx) || defined(STM32WBxx)
558558
if (!IS_ADC_CHANNEL(&AdcHandle, AdcChannelConf.Channel)) {
559559
return 0;
560560
}
@@ -567,7 +567,7 @@ uint16_t adc_read_value(PinName pin)
567567
#ifndef STM32L0xx
568568
AdcChannelConf.SamplingTime = SAMPLINGTIME; /* Sampling time value to be set for the selected channel */
569569
#endif
570-
#if defined (STM32F3xx) || defined (STM32L4xx) || defined (STM32H7xx)
570+
#if defined (STM32F3xx) || defined (STM32L4xx) || defined (STM32H7xx) || defined(STM32WBxx)
571571
AdcChannelConf.SingleDiff = ADC_SINGLE_ENDED; /* Single-ended input channel */
572572
AdcChannelConf.OffsetNumber = ADC_OFFSET_NONE; /* No offset subtraction */
573573
AdcChannelConf.Offset = 0; /* Parameter discarded because offset correction is disabled */
@@ -579,7 +579,8 @@ uint16_t adc_read_value(PinName pin)
579579
}
580580

581581
#if defined (STM32F0xx) || defined (STM32F1xx) || defined (STM32F3xx) ||\
582-
defined (STM32H7xx) || defined (STM32L0xx) || defined (STM32L4xx)
582+
defined (STM32H7xx) || defined (STM32L0xx) || defined (STM32L4xx) ||\
583+
defined(STM32WBxx)
583584
/*##-2.1- Calibrate ADC then Start the conversion process ####################*/
584585
#if defined (STM32F0xx) || defined (STM32F1xx)
585586
if (HAL_ADCEx_Calibration_Start(&AdcHandle) != HAL_OK)

cores/arduino/stm32/clock.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,13 @@ void enableClock(sourceClock_t source)
100100

101101
switch (source) {
102102
case LSI_CLOCK:
103+
#ifdef STM32WBxx
104+
if (__HAL_RCC_GET_FLAG(RCC_FLAG_LSI1RDY) == RESET) {
105+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI1;
106+
#else
103107
if (__HAL_RCC_GET_FLAG(RCC_FLAG_LSIRDY) == RESET) {
104108
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI;
109+
#endif
105110
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
106111
}
107112
break;
@@ -114,7 +119,7 @@ void enableClock(sourceClock_t source)
114119
break;
115120
case LSE_CLOCK:
116121
/* Enable Power Clock */
117-
#ifndef STM32H7xx
122+
#if !defined(STM32H7xx) && !defined(STM32WBxx)
118123
if (__HAL_RCC_PWR_IS_CLK_DISABLED()) {
119124
__HAL_RCC_PWR_CLK_ENABLE();
120125
}

cores/arduino/stm32/low_power.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static void (*WakeUpUartCb)(void) = NULL;
5959
*/
6060
void LowPower_init()
6161
{
62-
#ifndef STM32H7xx
62+
#if !defined(STM32H7xx) && ! defined(STM32WBxx)
6363
/* Enable Power Clock */
6464
__HAL_RCC_PWR_CLK_ENABLE();
6565
#endif

cores/arduino/stm32/rtc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static void RTC_initClock(sourceClock_t source)
124124
/* HSE max is 16 MHZ divided by 128 --> 125 KHz */
125125
PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_HSE_DIV128;
126126
HSEDiv = 128;
127-
#elif defined(STM32F0xx) || defined(STM32F3xx) || defined(STM32L4xx)
127+
#elif defined(STM32F0xx) || defined(STM32F3xx) || defined(STM32L4xx) || defined(STM32WBxx)
128128
PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_HSE_DIV32;
129129
HSEDiv = 32;
130130
#elif defined(STM32L0xx) || defined(STM32L1xx)

cores/arduino/stm32/stm32_eeprom.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ extern "C" {
7070
#endif /* STM32F2xx || STM32F4xx || STM32F7xx */
7171

7272
/* Be able to change FLASH_PAGE_NUMBER to use if relevant */
73-
#if !defined(FLASH_PAGE_NUMBER) && defined (STM32L4xx)
73+
#if !defined(FLASH_PAGE_NUMBER) && (defined (STM32L4xx) || defined(STM32WBxx))
7474
#define FLASH_PAGE_NUMBER ((uint32_t)((FLASH_SIZE / FLASH_PAGE_SIZE) - 1))
7575
#endif /* !FLASH_PAGE_NUMBER */
7676

@@ -109,7 +109,7 @@ static inline uint32_t get_flash_end(void)
109109
return size;
110110
}
111111
#define FLASH_END get_flash_end()
112-
#elif defined (STM32L4xx)
112+
#elif defined (STM32L4xx) || defined(STM32WBxx)
113113
/* If FLASH_PAGE_NUMBER is defined by user, this is not really end of the flash */
114114
#define FLASH_END ((uint32_t)(FLASH_BASE + (((FLASH_PAGE_NUMBER +1) * FLASH_PAGE_SIZE))-1))
115115
#endif
@@ -203,7 +203,8 @@ void eeprom_buffer_flush(void)
203203
uint32_t address = FLASH_BASE_ADDRESS;
204204
uint32_t address_end = FLASH_BASE_ADDRESS + E2END;
205205
#if defined (STM32F0xx) || defined (STM32F1xx) || defined (STM32F3xx) || \
206-
defined (STM32L0xx) || defined (STM32L1xx) || defined(STM32L4xx)
206+
defined (STM32L0xx) || defined (STM32L1xx) || defined(STM32L4xx) || \
207+
defined (STM32WBxx)
207208
uint32_t pageError = 0;
208209
uint64_t data = 0;
209210

@@ -212,7 +213,7 @@ void eeprom_buffer_flush(void)
212213
#if defined(STM32L4xx) || defined(STM32F1xx)
213214
EraseInitStruct.Banks = FLASH_BANK_NUMBER;
214215
#endif
215-
#ifdef STM32L4xx
216+
#if defined(STM32L4xx) || defined(STM32WBxx)
216217
EraseInitStruct.Page = FLASH_PAGE_NUMBER;
217218
#else
218219
EraseInitStruct.PageAddress = FLASH_BASE_ADDRESS;
@@ -232,7 +233,7 @@ void eeprom_buffer_flush(void)
232233
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | \
233234
FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR);
234235
#endif
235-
#elif defined (STM32L4xx)
236+
#elif defined (STM32L4xx) || defined (STM32WBxx)
236237
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
237238
#else
238239
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR);

cores/arduino/stm32/timer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ void TIM1_IRQHandler(void)
11201120
#endif
11211121
#endif
11221122

1123-
#if defined(STM32F1xx) || defined(STM32F3xx) || defined(STM32L4xx)
1123+
#if defined(STM32F1xx) || defined(STM32F3xx) || defined(STM32L4xx) || defined(STM32WBxx)
11241124
#if defined (TIM16_BASE)
11251125
if (timer_handles[TIMER16_INDEX] != NULL) {
11261126
HAL_TIM_IRQHandler(timer_handles[TIMER16_INDEX]);

cores/arduino/stm32/timer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ struct timer_s {
8686
#elif defined (TIM10_BASE)
8787
#define TIM1_IRQHandler TIM1_UP_TIM10_IRQHandler
8888
#endif
89-
#elif defined(STM32F3xx) || defined(STM32L4xx)
89+
#elif defined(STM32F3xx) || defined(STM32L4xx) || defined(STM32WBxx)
9090
#define TIM1_IRQn TIM1_UP_TIM16_IRQn
9191
#define TIM1_IRQHandler TIM1_UP_TIM16_IRQHandler
9292
#elif defined(STM32F2xx) || defined(STM32F4xx) || defined(STM32F7xx)
@@ -158,13 +158,13 @@ struct timer_s {
158158
#endif
159159
#endif
160160
#if defined(TIM16_BASE) && !defined(TIM16_IRQn)
161-
#if defined(STM32F1xx) || defined(STM32F3xx) || defined(STM32L4xx)
161+
#if defined(STM32F1xx) || defined(STM32F3xx) || defined(STM32L4xx) || defined(STM32WBxx)
162162
#define TIM16_IRQn TIM1_UP_TIM16_IRQn
163163
//TIM16_IRQHandler is mapped on TIM1_IRQHandler when TIM16_IRQn is not defined
164164
#endif
165165
#endif
166166
#if defined(TIM17_BASE) && !defined(TIM17_IRQn)
167-
#if defined(STM32F1xx) || defined(STM32F3xx) || defined(STM32L4xx)
167+
#if defined(STM32F1xx) || defined(STM32F3xx) || defined(STM32L4xx) || defined(STM32WBxx)
168168
#define TIM17_IRQn TIM1_TRG_COM_TIM17_IRQn
169169
#define TIM17_IRQHandler TIM1_TRG_COM_TIM17_IRQHandler
170170
#endif

cores/arduino/stm32/twi.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ void i2c_custom_init(i2c_t *obj, i2c_timing_e timing, uint32_t addressingMode, u
176176

177177
handle->Instance = obj->i2c;
178178
#if defined (STM32F0xx) || defined (STM32F3xx) || defined (STM32F7xx) ||\
179-
defined (STM32H7xx) || defined (STM32L0xx) || defined (STM32L4xx)
179+
defined (STM32H7xx) || defined (STM32L0xx) || defined (STM32L4xx) ||\
180+
defined (STM32WBxx)
180181
handle->Init.Timing = timing;
181182
#else
182183
handle->Init.ClockSpeed = timing;
@@ -251,7 +252,8 @@ void i2c_setTiming(i2c_t *obj, uint32_t frequency)
251252
}
252253

253254
#if defined (STM32F0xx) || defined (STM32F3xx) || defined (STM32F7xx) ||\
254-
defined (STM32H7xx) || defined (STM32L0xx) || defined (STM32L4xx)
255+
defined (STM32H7xx) || defined (STM32L0xx) || defined (STM32L4xx) ||\
256+
defined (STM32WBxx)
255257
obj->handle.Init.Timing = f;
256258
#else
257259
obj->handle.Init.ClockSpeed = f;

cores/arduino/stm32/usb/usbd_conf.c

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,14 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
5252
const PinMap *map = NULL;
5353
#if defined(PWR_CR2_USV)
5454
/* Enable VDDUSB on Pwrctrl CR2 register*/
55+
#if !defined(STM32WBxx)
5556
if (__HAL_RCC_PWR_IS_CLK_DISABLED()) {
5657
__HAL_RCC_PWR_CLK_ENABLE();
5758
HAL_PWREx_EnableVddUSB();
5859
__HAL_RCC_PWR_CLK_DISABLE();
59-
} else {
60+
} else
61+
#endif
62+
{
6063
HAL_PWREx_EnableVddUSB();
6164
}
6265
#endif
@@ -83,11 +86,18 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
8386
__HAL_REMAPINTERRUPT_USB_ENABLE();
8487
#endif
8588

89+
#if defined(STM32WBxx)
90+
HAL_NVIC_SetPriority(USB_HP_IRQn, 5, 0);
91+
HAL_NVIC_EnableIRQ(USB_HP_IRQn);
92+
HAL_NVIC_SetPriority(USB_LP_IRQn, 5, 0);
93+
HAL_NVIC_EnableIRQ(USB_LP_IRQn);
94+
#else
8695
/* Set USB FS Interrupt priority */
8796
HAL_NVIC_SetPriority(USB_IRQn, 5, 0);
8897

8998
/* Enable USB FS Interrupt */
9099
HAL_NVIC_EnableIRQ(USB_IRQn);
100+
#endif /* STM32WBxx */
91101

92102
if (hpcd->Init.low_power_enable == 1) {
93103
/* Enable EXTI for USB wakeup */
@@ -204,8 +214,10 @@ void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd)
204214
__HAL_RCC_USB_OTG_HS_CLK_DISABLE();
205215
}
206216
#endif /* USB_OTG_HS */
217+
#if !defined(STM32WBxx)
207218
/* Disable SYSCFG Clock */
208219
__HAL_RCC_SYSCFG_CLK_DISABLE();
220+
#endif
209221
}
210222

211223
/*******************************************************************************
@@ -379,14 +391,32 @@ void USB_IRQHandler(void)
379391
HAL_PCD_IRQHandler(&g_hpcd);
380392
}
381393

382-
394+
#if defined(STM32WBxx)
395+
/**
396+
* @brief This function handles USB high priority interrupt.
397+
* @param None
398+
* @retval None
399+
*/
400+
void USB_HP_IRQHandler(void)
401+
{
402+
HAL_PCD_IRQHandler(&g_hpcd);
403+
}
383404

405+
/**
406+
* @brief This function handles USB low priority interrupt, USB wake-up interrupt through EXTI line 28.
407+
* @param None
408+
* @retval None
409+
*/
410+
void USB_LP_IRQHandler(void)
411+
{
412+
HAL_PCD_IRQHandler(&g_hpcd);
413+
}
414+
#else
384415
/**
385416
* @brief This function handles USB OTG FS Wakeup IRQ Handler.
386417
* @param None
387418
* @retval None
388419
*/
389-
390420
#ifdef USE_USB_HS
391421
void OTG_HS_WKUP_IRQHandler(void)
392422
#elif defined(USB_OTG_FS)
@@ -416,6 +446,7 @@ void USBWakeUp_IRQHandler(void)
416446
__HAL_USB_WAKEUP_EXTI_CLEAR_FLAG();
417447
#endif
418448
}
449+
#endif
419450
/*******************************************************************************
420451
LL Driver Interface (USB Device Library --> PCD)
421452
*******************************************************************************/

libraries/IWatchdog/src/IWatchdog.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@ void IWatchdogClass::begin(uint32_t timeout, uint32_t window)
1919
}
2020

2121
// Enable the peripheral clock IWDG
22+
#ifdef STM32WBxx
23+
LL_RCC_LSI1_Enable();
24+
while (LL_RCC_LSI1_IsReady() != 1) {
25+
}
26+
#else
2227
LL_RCC_LSI_Enable();
2328
while (LL_RCC_LSI_IsReady() != 1) {
2429
}
25-
30+
#endif
2631
// Enable the IWDG by writing 0x0000 CCCC in the IWDG_KR register
2732
LL_IWDG_Enable(IWDG);
2833
_enabled = true;

0 commit comments

Comments
 (0)