Skip to content

Commit d061489

Browse files
committed
Update core to support G0
Signed-off-by: Frederic.Pillon <[email protected]>
1 parent 2648771 commit d061489

File tree

13 files changed

+108
-32
lines changed

13 files changed

+108
-32
lines changed

cores/arduino/stm32/analog.c

+21-7
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,8 @@ void HAL_ADC_MspDeInit(ADC_HandleTypeDef *hadc)
486486
}
487487
#endif
488488
#ifdef __HAL_RCC_ADC_CLK_DISABLE
489+
__HAL_RCC_ADC_FORCE_RESET();
490+
__HAL_RCC_ADC_RELEASE_RESET();
489491
__HAL_RCC_ADC_CLK_DISABLE();
490492
#endif
491493
}
@@ -526,13 +528,18 @@ uint16_t adc_read_value(PinName pin)
526528
AdcHandle.Init.DiscontinuousConvMode = DISABLE; /* Parameter discarded because sequencer is disabled */
527529
AdcHandle.Init.ExternalTrigConv = ADC_SOFTWARE_START; /* Software start to trig the 1st conversion manually, without external event */
528530
AdcHandle.State = HAL_ADC_STATE_RESET;
529-
#if defined (STM32F0xx) || defined (STM32L0xx)
531+
#if defined (STM32F0xx) || defined(STM32G0xx) || defined (STM32L0xx)
530532
AdcHandle.Init.LowPowerAutoWait = DISABLE; /* Auto-delayed conversion feature disabled */
531533
AdcHandle.Init.LowPowerAutoPowerOff = DISABLE; /* ADC automatically powers-off after a conversion and automatically wakes-up when a new conversion is triggered */
532534
AdcHandle.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN; /* DR register is overwritten with the last conversion result in case of overrun */
533535
#ifdef STM32F0xx
534536
AdcHandle.Init.SamplingTimeCommon = SAMPLINGTIME;
535-
#else /* STM32L0 */
537+
#elif STM32G0xx
538+
AdcHandle.Init.SamplingTimeCommon1 = SAMPLINGTIME; /* Set sampling time common to a group of channels. */
539+
AdcHandle.Init.SamplingTimeCommon2 = SAMPLINGTIME; /* Set sampling time common to a group of channels, second common setting possible.*/
540+
AdcHandle.Init.OversamplingMode = DISABLE;
541+
AdcHandle.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH;
542+
#else
536543
//LowPowerFrequencyMode to enable if clk freq < 2.8Mhz
537544
AdcHandle.Init.SamplingTime = SAMPLINGTIME;
538545
#endif /* STM32F0xx */
@@ -543,9 +550,12 @@ uint16_t adc_read_value(PinName pin)
543550
AdcHandle.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN; /* DR register is overwritten with the last conversion result in case of overrun */
544551
#endif /* !STM32H7xx */
545552
#endif /* STM32F3xx || STM32H7xx */
546-
AdcHandle.Init.NbrOfConversion = 1; /* Specifies the number of ranks that will be converted within the regular group sequencer. */
547553
AdcHandle.Init.NbrOfDiscConversion = 0; /* Parameter discarded because sequencer is disabled */
548-
#endif /* STM32F0xx || STM32L0xx */
554+
#endif /* STM32F0xx || STM32G0xx || STM32L0xx */
555+
556+
#if !defined (STM32F0xx) && !defined (STM32L0xx)
557+
AdcHandle.Init.NbrOfConversion = 1; /* Specifies the number of ranks that will be converted within the regular group sequencer. */
558+
#endif
549559

550560
g_current_pin = pin; /* Needed for HAL_ADC_MspInit*/
551561

@@ -565,8 +575,12 @@ uint16_t adc_read_value(PinName pin)
565575
#endif /* STM32L4xx */
566576
AdcChannelConf.Rank = ADC_REGULAR_RANK_1; /* Specifies the rank in the regular group sequencer */
567577
#ifndef STM32L0xx
578+
#if defined (STM32G0xx)
579+
AdcChannelConf.SamplingTime = ADC_SAMPLINGTIME_COMMON_1; /* Sampling time value to be set for the selected channel */
580+
#else
568581
AdcChannelConf.SamplingTime = SAMPLINGTIME; /* Sampling time value to be set for the selected channel */
569582
#endif
583+
#endif
570584
#if defined (STM32F3xx) || defined (STM32L4xx) || defined (STM32H7xx) || defined(STM32WBxx)
571585
AdcChannelConf.SingleDiff = ADC_SINGLE_ENDED; /* Single-ended input channel */
572586
AdcChannelConf.OffsetNumber = ADC_OFFSET_NONE; /* No offset subtraction */
@@ -579,10 +593,10 @@ uint16_t adc_read_value(PinName pin)
579593
}
580594

581595
#if defined (STM32F0xx) || defined (STM32F1xx) || defined (STM32F3xx) ||\
582-
defined (STM32H7xx) || defined (STM32L0xx) || defined (STM32L4xx) ||\
583-
defined(STM32WBxx)
596+
defined (STM32H7xx) || defined (STM32G0xx) || defined (STM32L0xx) ||\
597+
defined (STM32L4xx) || defined(STM32WBxx)
584598
/*##-2.1- Calibrate ADC then Start the conversion process ####################*/
585-
#if defined (STM32F0xx) || defined (STM32F1xx)
599+
#if defined (STM32F0xx) || defined (STM32G0xx) || defined (STM32F1xx)
586600
if (HAL_ADCEx_Calibration_Start(&AdcHandle) != HAL_OK)
587601
#elif defined (STM32H7xx)
588602
if (HAL_ADCEx_Calibration_Start(&AdcHandle, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED) != HAL_OK)

cores/arduino/stm32/backup.h

+4
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ static inline void setBackupRegister(uint32_t index, uint32_t value)
103103
{
104104
#if defined(STM32F1xx)
105105
LL_RTC_BKP_SetRegister(BKP, index, value);
106+
#elif defined(STM32G0xx)
107+
LL_RTC_BKP_SetRegister(TAMP, index, value);
106108
#else
107109
#ifdef ENABLE_BACKUP_SUPPORT
108110
LL_RTC_BAK_SetRegister(RTC, index, value);
@@ -117,6 +119,8 @@ static inline uint32_t getBackupRegister(uint32_t index)
117119
{
118120
#if defined(STM32F1xx)
119121
return LL_RTC_BKP_GetRegister(BKP, index);
122+
#elif defined(STM32G0xx)
123+
return LL_RTC_BKP_GetRegister(TAMP, index);
120124
#else
121125
#ifdef ENABLE_BACKUP_SUPPORT
122126
return LL_RTC_BAK_GetRegister(RTC, index);

cores/arduino/stm32/interrupt.cpp

+24-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ typedef struct {
5151

5252
/* Private Variables */
5353
static gpio_irq_conf_str gpio_irq_conf[NB_EXTI] = {
54-
#if defined (STM32F0xx) || defined (STM32L0xx)
54+
#if defined (STM32F0xx) || defined (STM32G0xx) || defined (STM32L0xx)
5555
{.irqnb = EXTI0_1_IRQn, .callback = NULL}, //GPIO_PIN_0
5656
{.irqnb = EXTI0_1_IRQn, .callback = NULL}, //GPIO_PIN_1
5757
{.irqnb = EXTI2_3_IRQn, .callback = NULL}, //GPIO_PIN_2
@@ -218,7 +218,29 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
218218
}
219219
}
220220

221-
#if defined (STM32F0xx) || defined (STM32L0xx)
221+
#if defined (STM32G0xx)
222+
/**
223+
* @brief EXTI line detection callback.
224+
* @param GPIO_Pin Specifies the port pin connected to corresponding EXTI line.
225+
* @retval None
226+
*/
227+
void HAL_GPIO_EXTI_Rising_Callback(uint16_t GPIO_Pin)
228+
{
229+
HAL_GPIO_EXTI_Callback(GPIO_Pin);
230+
}
231+
232+
/**
233+
* @brief EXTI line detection callback.
234+
* @param GPIO_Pin Specifies the port pin connected to corresponding EXTI line.
235+
* @retval None
236+
*/
237+
void HAL_GPIO_EXTI_Falling_Callback(uint16_t GPIO_Pin)
238+
{
239+
HAL_GPIO_EXTI_Callback(GPIO_Pin);
240+
}
241+
#endif
242+
243+
#if defined (STM32F0xx) || defined (STM32G0xx) || defined (STM32L0xx)
222244
#ifdef __cplusplus
223245
extern "C" {
224246
#endif

cores/arduino/stm32/low_power.c

+4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ static UART_HandleTypeDef *WakeUpUart = NULL;
5252
/* Save callback pointer */
5353
static void (*WakeUpUartCb)(void) = NULL;
5454

55+
#ifdef STM32G0xx
56+
#define PWR_FLAG_WU PWR_FLAG_WUF
57+
#endif
58+
5559
/**
5660
* @brief Initialize low power mode
5761
* @param None

cores/arduino/stm32/rtc.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ 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) || defined(STM32WBxx)
127+
#elif defined(STM32F0xx) || defined(STM32F3xx) || defined(STM32G0xx) ||\
128+
defined(STM32L4xx) || defined(STM32WBxx)
128129
PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_HSE_DIV32;
129130
HSEDiv = 32;
130131
#elif defined(STM32L0xx) || defined(STM32L1xx)
@@ -183,7 +184,9 @@ static void RTC_initClock(sourceClock_t source)
183184
} else {
184185
Error_Handler();
185186
}
186-
187+
#ifdef __HAL_RCC_RTCAPB_CLK_ENABLE
188+
__HAL_RCC_RTCAPB_CLK_ENABLE();
189+
#endif
187190
__HAL_RCC_RTC_ENABLE();
188191
}
189192

@@ -318,7 +321,7 @@ void RTC_init(hourFormat_t format, sourceClock_t source, bool reset)
318321
}
319322
RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
320323
RTC_getPrediv((int8_t *) & (RtcHandle.Init.AsynchPrediv), (int16_t *) & (RtcHandle.Init.SynchPrediv));
321-
#if defined(STM32H7xx) || defined(STM32L0xx) || defined(STM32L4xx)
324+
#if defined(STM32G0xx) || defined(STM32H7xx) || defined(STM32L0xx) || defined(STM32L4xx)
322325
RtcHandle.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
323326
#endif /* STM32H7xx || STM32L0xx || STM32L4xx */
324327
RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;

cores/arduino/stm32/rtc.h

+4
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ typedef void(*voidCallbackPtr)(void *);
103103
#define RTC_Alarm_IRQn RTC_IRQn
104104
#define RTC_Alarm_IRQHandler RTC_IRQHandler
105105
#endif
106+
#if defined(STM32G0xx)
107+
#define RTC_Alarm_IRQn RTC_TAMP_IRQn
108+
#define RTC_Alarm_IRQHandler RTC_TAMP_IRQHandler
109+
#endif
106110

107111
#if defined(STM32F1xx) && !defined(IS_RTC_WEEKDAY)
108112
/* Compensate missing HAL definition */

cores/arduino/stm32/spi_com.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ uint32_t spi_getClkFreqInst(SPI_TypeDef *spi_inst)
5555
{
5656
uint32_t spi_freq = SystemCoreClock;
5757

58-
#ifdef STM32F0xx
58+
#if defined(STM32F0xx) || defined(STM32G0xx)
5959
UNUSED(spi_inst);
6060
/* SPIx source CLK is PCKL1 */
6161
spi_freq = HAL_RCC_GetPCLK1Freq();

cores/arduino/stm32/stm32_eeprom.c

+7-6
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ 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) || defined(STM32WBxx))
73+
#if !defined(FLASH_PAGE_NUMBER) &&\
74+
(defined (STM32G0xx) || defined (STM32L4xx) || defined(STM32WBxx))
7475
#define FLASH_PAGE_NUMBER ((uint32_t)((FLASH_SIZE / FLASH_PAGE_SIZE) - 1))
7576
#endif /* !FLASH_PAGE_NUMBER */
7677

@@ -109,7 +110,7 @@ static inline uint32_t get_flash_end(void)
109110
return size;
110111
}
111112
#define FLASH_END get_flash_end()
112-
#elif defined (STM32L4xx) || defined(STM32WBxx)
113+
#elif defined(STM32G0xx) || defined (STM32L4xx) || defined(STM32WBxx)
113114
/* If FLASH_PAGE_NUMBER is defined by user, this is not really end of the flash */
114115
#define FLASH_END ((uint32_t)(FLASH_BASE + (((FLASH_PAGE_NUMBER +1) * FLASH_PAGE_SIZE))-1))
115116
#endif
@@ -203,8 +204,8 @@ void eeprom_buffer_flush(void)
203204
uint32_t address = FLASH_BASE_ADDRESS;
204205
uint32_t address_end = FLASH_BASE_ADDRESS + E2END;
205206
#if defined (STM32F0xx) || defined (STM32F1xx) || defined (STM32F3xx) || \
206-
defined (STM32L0xx) || defined (STM32L1xx) || defined(STM32L4xx) || \
207-
defined (STM32WBxx)
207+
defined (STM32G0xx) || defined (STM32L0xx) || defined (STM32L1xx) ||\
208+
defined(STM32L4xx) || defined (STM32WBxx)
208209
uint32_t pageError = 0;
209210
uint64_t data = 0;
210211

@@ -213,7 +214,7 @@ void eeprom_buffer_flush(void)
213214
#if defined(STM32L4xx) || defined(STM32F1xx)
214215
EraseInitStruct.Banks = FLASH_BANK_NUMBER;
215216
#endif
216-
#if defined(STM32L4xx) || defined(STM32WBxx)
217+
#if defined (STM32G0xx) || defined(STM32L4xx) || defined(STM32WBxx)
217218
EraseInitStruct.Page = FLASH_PAGE_NUMBER;
218219
#else
219220
EraseInitStruct.PageAddress = FLASH_BASE_ADDRESS;
@@ -233,7 +234,7 @@ void eeprom_buffer_flush(void)
233234
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | \
234235
FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR);
235236
#endif
236-
#elif defined (STM32L4xx) || defined (STM32WBxx)
237+
#elif defined (STM32G0xx) || defined (STM32L4xx) || defined (STM32WBxx)
237238
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
238239
#else
239240
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR);

cores/arduino/stm32/timer.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ uint32_t getTimerClkFreq(TIM_TypeDef *tim)
695695
uwAPBxPrescaler = clkconfig.APB1CLKDivider;
696696
uwTimclock = HAL_RCC_GetPCLK1Freq();
697697
break;
698-
#ifndef STM32F0xx
698+
#if !defined(STM32F0xx) && !defined(STM32G0xx)
699699
case 2:
700700
uwAPBxPrescaler = clkconfig.APB2CLKDivider;
701701
uwTimclock = HAL_RCC_GetPCLK2Freq();

cores/arduino/stm32/timer.h

+12-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ struct timer_s {
7676
#define MAX_FREQ 65535
7777

7878
#if defined(TIM1_BASE) && !defined(TIM1_IRQn)
79-
#if defined(STM32F0xx)
79+
#if defined(STM32F0xx) || defined(STM32G0xx)
8080
#define TIM1_IRQn TIM1_BRK_UP_TRG_COM_IRQn
8181
#define TIM1_IRQHandler TIM1_BRK_UP_TRG_COM_IRQHandler
8282
#elif defined(STM32F1xx)
@@ -98,11 +98,21 @@ struct timer_s {
9898
#endif
9999
#endif
100100
#if defined(TIM6_BASE) && !defined(TIM6_IRQn)
101-
#if !defined(STM32F1xx) && !defined(STM32L1xx)
101+
#if defined(STM32G0xx)
102+
#define TIM6_IRQn TIM6_DAC_LPTIM1_IRQn
103+
#define TIM6_IRQHandler TIM6_DAC_LPTIM1_IRQHandler
104+
#elif !defined(STM32F1xx) && !defined(STM32L1xx)
102105
#define TIM6_IRQn TIM6_DAC_IRQn
103106
#define TIM6_IRQHandler TIM6_DAC_IRQHandler
104107
#endif
105108
#endif
109+
#if defined(TIM7_BASE) && !defined(TIM7_IRQn)
110+
#if defined(STM32G0xx)
111+
#define TIM7_IRQn TIM7_LPTIM2_IRQn
112+
#define TIM7_IRQHandler TIM7_LPTIM2_IRQHandler
113+
#endif
114+
#endif
115+
106116
#if defined(TIM8_BASE) && !defined(TIM8_IRQn)
107117
#if defined(STM32F1xx) || defined(STM32F2xx) ||defined(STM32F4xx) || defined(STM32F7xx)\
108118
|| defined(STM32H7xx)

cores/arduino/stm32/twi.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ void i2c_custom_init(i2c_t *obj, i2c_timing_e timing, uint32_t addressingMode, u
124124
__HAL_RCC_I2C1_RELEASE_RESET();
125125

126126
obj->irq = I2C1_EV_IRQn;
127-
#if !defined(STM32F0xx) && !defined(STM32L0xx)
127+
#if !defined(STM32F0xx) && !defined(STM32G0xx) && !defined(STM32L0xx)
128128
obj->irqER = I2C1_ER_IRQn;
129-
#endif // !defined(STM32F0xx) && !defined(STM32L0xx)
129+
#endif // !defined(STM32F0xx) && !defined(STM32G0xx) && !defined(STM32L0xx)
130130
i2c_handles[I2C1_INDEX] = handle;
131131
}
132132
#endif // I2C1_BASE
@@ -137,9 +137,9 @@ void i2c_custom_init(i2c_t *obj, i2c_timing_e timing, uint32_t addressingMode, u
137137
__HAL_RCC_I2C2_FORCE_RESET();
138138
__HAL_RCC_I2C2_RELEASE_RESET();
139139
obj->irq = I2C2_EV_IRQn;
140-
#if !defined(STM32F0xx) && !defined(STM32L0xx)
140+
#if !defined(STM32F0xx) && !defined(STM32G0xx) && !defined(STM32L0xx)
141141
obj->irqER = I2C2_ER_IRQn;
142-
#endif // !defined(STM32F0xx) && !defined(STM32L0xx)
142+
#endif // !defined(STM32F0xx) && !defined(STM32G0xx) && !defined(STM32L0xx)
143143
i2c_handles[I2C2_INDEX] = handle;
144144
}
145145
#endif // I2C2_BASE
@@ -176,8 +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) ||\
180-
defined (STM32WBxx)
179+
defined (STM32G0xx) || defined (STM32H7xx) || defined (STM32L0xx) ||\
180+
defined (STM32L4xx) || defined (STM32WBxx)
181181
handle->Init.Timing = timing;
182182
#else
183183
handle->Init.ClockSpeed = timing;
@@ -255,8 +255,8 @@ void i2c_setTiming(i2c_t *obj, uint32_t frequency)
255255
}
256256

257257
#if defined (STM32F0xx) || defined (STM32F3xx) || defined (STM32F7xx) ||\
258-
defined (STM32H7xx) || defined (STM32L0xx) || defined (STM32L4xx) ||\
259-
defined (STM32WBxx)
258+
defined (STM32G0xx) || defined (STM32H7xx) || defined (STM32L0xx) ||\
259+
defined (STM32L4xx) || defined (STM32WBxx)
260260
obj->handle.Init.Timing = f;
261261
#else
262262
obj->handle.Init.ClockSpeed = f;

cores/arduino/stm32/twi.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ extern "C" {
5656
#define I2C_TXRX_BUFFER_SIZE 32
5757

5858
/* Redefinition of IRQ for F0 & L0 family */
59-
#if defined(STM32F0xx) || defined(STM32L0xx)
59+
#if defined(STM32F0xx) || defined(STM32G0xx) || defined(STM32L0xx)
6060
#if defined(I2C1_BASE)
6161
#define I2C1_EV_IRQn I2C1_IRQn
6262
#define I2C1_EV_IRQHandler I2C1_IRQHandler

cores/arduino/stm32/uart.h

+15-1
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,13 @@ struct serial_s {
8686
#else
8787
#define USART3_IRQn USART3_4_IRQn
8888
#define USART3_IRQHandler USART3_4_IRQHandler
89-
9089
#endif /* STM32F091xC || STM32F098xx */
9190
#endif /* STM32F0xx */
91+
92+
#if defined(STM32G0xx)
93+
#define USART3_IRQn USART3_4_LPUART1_IRQn
94+
#define USART3_IRQHandler USART3_4_LPUART1_IRQHandler
95+
#endif /* STM32G0xx */
9296
#endif
9397

9498
#if defined(USART4_BASE) && !defined(USART4_IRQn)
@@ -104,6 +108,10 @@ struct serial_s {
104108
#elif defined(STM32L0xx)
105109
#define USART4_IRQn USART4_5_IRQn
106110
#endif /* STM32F0xx */
111+
#if defined(STM32G0xx)
112+
#define USART4_IRQn USART3_4_LPUART1_IRQn
113+
#endif /* STM32G0xx */
114+
107115
#endif
108116

109117
#if defined(USART5_BASE) && !defined(USART5_IRQn)
@@ -142,6 +150,12 @@ struct serial_s {
142150
#endif
143151
#endif /* STM32F0xx */
144152

153+
#if defined(STM32G0xx)
154+
#if defined(LPUART1_BASE) && !defined(LPUART1_IRQn)
155+
#define LPUART1_IRQn USART3_4_LPUART1_IRQn
156+
#endif
157+
#endif /* STM32G0xx */
158+
145159
/* Exported macro ------------------------------------------------------------*/
146160
/* Exported functions ------------------------------------------------------- */
147161
void uart_init(serial_t *obj);

0 commit comments

Comments
 (0)