Skip to content

Commit be1e30d

Browse files
committed
Update core to support WB
Signed-off-by: Frederic.Pillon <[email protected]>
1 parent 8586ee3 commit be1e30d

File tree

11 files changed

+90
-25
lines changed

11 files changed

+90
-25
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
@@ -1051,7 +1051,7 @@ void TIM1_IRQHandler(void)
10511051
#endif
10521052
#endif
10531053

1054-
#if defined(STM32F1xx) || defined(STM32F3xx) || defined(STM32L4xx)
1054+
#if defined(STM32F1xx) || defined(STM32F3xx) || defined(STM32L4xx) || defined(STM32WBxx)
10551055
#if defined (TIM16_BASE)
10561056
if (timer_handles[15] != NULL) {
10571057
HAL_TIM_IRQHandler(timer_handles[15]);

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: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ extern "C" {
5757
#define I2C_NUM (4)
5858
#elif defined(STM32F2xx) || defined(STM32F3xx) || defined(STM32F4xx) || defined(STM32L0xx)
5959
#define I2C_NUM (3)
60-
#elif defined(STM32F0xx) || defined(STM32F1xx) || defined(STM32L1xx)
60+
#elif defined(STM32F0xx) || defined(STM32F1xx) || defined(STM32L1xx) || defined(STM32WBxx)
6161
#define I2C_NUM (2)
6262
#else
6363
#error "Unknown Family - unknown I2C_NUM"
@@ -147,7 +147,11 @@ void i2c_custom_init(i2c_t *obj, i2c_timing_e timing, uint32_t addressingMode, u
147147
#if !defined(STM32F0xx) && !defined(STM32L0xx)
148148
obj->irqER = I2C3_ER_IRQn;
149149
#endif // !defined(STM32F0xx) && !defined(STM32L0xx)
150+
#if defined I2C2_BASE
150151
i2c_handles[2] = handle;
152+
#else
153+
i2c_handles[1] = handle;
154+
#endif
151155
}
152156
#endif // I2C3_BASE
153157
#if defined I2C4_BASE
@@ -170,7 +174,8 @@ void i2c_custom_init(i2c_t *obj, i2c_timing_e timing, uint32_t addressingMode, u
170174

171175
handle->Instance = obj->i2c;
172176
#if defined (STM32F0xx) || defined (STM32F3xx) || defined (STM32F7xx) ||\
173-
defined (STM32H7xx) || defined (STM32L0xx) || defined (STM32L4xx)
177+
defined (STM32H7xx) || defined (STM32L0xx) || defined (STM32L4xx) ||\
178+
defined (STM32WBxx)
174179
handle->Init.Timing = timing;
175180
#else
176181
handle->Init.ClockSpeed = timing;
@@ -245,7 +250,8 @@ void i2c_setTiming(i2c_t *obj, uint32_t frequency)
245250
}
246251

247252
#if defined (STM32F0xx) || defined (STM32F3xx) || defined (STM32F7xx) ||\
248-
defined (STM32H7xx) || defined (STM32L0xx) || defined (STM32L4xx)
253+
defined (STM32H7xx) || defined (STM32L0xx) || defined (STM32L4xx) ||\
254+
defined (STM32WBxx)
249255
obj->handle.Init.Timing = f;
250256
#else
251257
obj->handle.Init.ClockSpeed = f;
@@ -635,7 +641,11 @@ void I2C2_ER_IRQHandler(void)
635641
*/
636642
void I2C3_EV_IRQHandler(void)
637643
{
644+
#if defined(I2C2_BASE)
638645
I2C_HandleTypeDef *handle = i2c_handles[2];
646+
#else
647+
I2C_HandleTypeDef *handle = i2c_handles[1];
648+
#endif
639649
HAL_I2C_EV_IRQHandler(handle);
640650
#if defined(STM32F0xx) || defined(STM32L0xx)
641651
HAL_I2C_ER_IRQHandler(handle);
@@ -650,7 +660,11 @@ void I2C3_EV_IRQHandler(void)
650660
*/
651661
void I2C3_ER_IRQHandler(void)
652662
{
663+
#if defined(I2C2_BASE)
653664
I2C_HandleTypeDef *handle = i2c_handles[2];
665+
#else
666+
I2C_HandleTypeDef *handle = i2c_handles[1];
667+
#endif
654668
HAL_I2C_ER_IRQHandler(handle);
655669
}
656670
#endif // !defined(STM32F0xx) && !defined(STM32L0xx)

cores/arduino/stm32/uart.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ extern "C" {
6868
#elif defined(STM32F1xx) || defined(STM32F3xx) ||\
6969
defined(STM32L0xx) || defined(STM32L1xx)
7070
#define UART_NUM (5)
71+
#elif defined(STM32WBxx)
72+
#define UART_NUM (2)
7173
#else
7274
#error "Unknown Family - unknown UART_NUM"
7375
#endif
@@ -190,7 +192,9 @@ void uart_init(serial_t *obj)
190192
__HAL_RCC_LPUART1_FORCE_RESET();
191193
__HAL_RCC_LPUART1_RELEASE_RESET();
192194
__HAL_RCC_LPUART1_CLK_ENABLE();
193-
#if !defined(USART3_BASE)
195+
#if !defined(USART2_BASE)
196+
obj->index = 1;
197+
#elif !defined(USART3_BASE)
194198
obj->index = 2;
195199
#else
196200
obj->index = 5;
@@ -507,7 +511,9 @@ void uart_config_lowpower(serial_t *obj)
507511
break;
508512
#endif
509513
#if defined(LPUART1_BASE) && defined(__HAL_RCC_LPUART1_CONFIG)
510-
#if !defined(USART3_BASE)
514+
#if !defined(USART2_BASE)
515+
case 1:
516+
#elif !defined(USART3_BASE)
511517
case 2:
512518
#else
513519
case 5:
@@ -936,7 +942,9 @@ void USART6_IRQHandler(void)
936942
void LPUART1_IRQHandler(void)
937943
{
938944
HAL_NVIC_ClearPendingIRQ(LPUART1_IRQn);
939-
#if !defined(USART3_BASE)
945+
#if !defined(USART2_BASE)
946+
HAL_UART_IRQHandler(uart_handlers[1]);
947+
#elif !defined(USART3_BASE)
940948
HAL_UART_IRQHandler(uart_handlers[2]);
941949
#else
942950
HAL_UART_IRQHandler(uart_handlers[5]);

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
*******************************************************************************/

0 commit comments

Comments
 (0)