stm32: Update HAL macro and constant names to use newer versions.

Newer versions of the HAL use names which are cleaner and more
self-consistent amongst the HAL itself.  This patch switches to use those
names in most places so it is easier to update the HAL in the future.
This commit is contained in:
Damien George 2018-02-13 15:37:35 +11:00
parent 8e1cb58a23
commit 3eb0694b97
18 changed files with 140 additions and 140 deletions

View File

@ -51,7 +51,7 @@
/* ADC defintions */
#define ADCx (ADC1)
#define ADCx_CLK_ENABLE __ADC1_CLK_ENABLE
#define ADCx_CLK_ENABLE __HAL_RCC_ADC1_CLK_ENABLE
#define ADC_NUM_CHANNELS (19)
#if defined(MCU_SERIES_F4)
@ -261,7 +261,7 @@ STATIC uint32_t adc_read_channel(ADC_HandleTypeDef *adcHandle) {
HAL_ADC_Start(adcHandle);
if (HAL_ADC_PollForConversion(adcHandle, 10) == HAL_OK
&& (HAL_ADC_GetState(adcHandle) & HAL_ADC_STATE_EOC_REG) == HAL_ADC_STATE_EOC_REG) {
&& (HAL_ADC_GetState(adcHandle) & HAL_ADC_STATE_REG_EOC) == HAL_ADC_STATE_REG_EOC) {
rawValue = HAL_ADC_GetValue(adcHandle);
}
HAL_ADC_Stop(adcHandle);
@ -535,7 +535,7 @@ uint32_t adc_config_and_read_channel(ADC_HandleTypeDef *adcHandle, uint32_t chan
}
int adc_get_resolution(ADC_HandleTypeDef *adcHandle) {
uint32_t res_reg = __HAL_ADC_GET_RESOLUTION(adcHandle);
uint32_t res_reg = ADC_GET_RESOLUTION(adcHandle);
switch (res_reg) {
case ADC_RESOLUTION_6B: return 6;

View File

@ -104,10 +104,10 @@ static void LBF_DFU_If_Needed(void)
// Initialize and assert pin BTLE_RST
// (hw reset to BLE module, so it won't drive UART3)
__GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Pin = BT_RST_PIN;
HAL_GPIO_Init(BT_RST_PORT, &GPIO_InitStruct);
@ -124,7 +124,7 @@ static void LBF_DFU_If_Needed(void)
// Initialize Extension Port Position 10 = PB8 (bears I2C1_SCL)
// Use weak pull-up to detect if pin is externally pulled low
__GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Pin = CONN_POS10_PIN;

View File

@ -2,11 +2,11 @@
void NETDUINO_PLUS_2_board_early_init(void) {
__GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
// Turn off the backlight. LCD_BL_CTRL = PK3
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.Pull = GPIO_PULLUP;

View File

@ -3,13 +3,13 @@
void STM32F7DISC_board_early_init(void) {
GPIO_InitTypeDef GPIO_InitStructure;
__GPIOK_CLK_ENABLE();
__HAL_RCC_GPIOK_CLK_ENABLE();
// Turn off the backlight. LCD_BL_CTRL = PK3
GPIO_InitStructure.Pin = GPIO_PIN_3;
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.Pull = GPIO_PULLUP;
GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
HAL_GPIO_Init(GPIOK, &GPIO_InitStructure);
HAL_GPIO_WritePin(GPIOK, GPIO_PIN_3, GPIO_PIN_RESET);
}

View File

@ -125,7 +125,7 @@ STATIC bool can_init(pyb_can_obj_t *can_obj) {
// init GPIO
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.Pin = GPIO_Pin;
GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
GPIO_InitStructure.Pull = GPIO_PULLUP;
GPIO_InitStructure.Alternate = GPIO_AF_CANx;

View File

@ -373,7 +373,7 @@ static void dma_enable_clock(dma_id_t dma_id) {
if (dma_id < NSTREAMS_PER_CONTROLLER) {
if (((old_enable_mask & DMA1_ENABLE_MASK) == 0) && !DMA1_IS_CLK_ENABLED()) {
__DMA1_CLK_ENABLE();
__HAL_RCC_DMA1_CLK_ENABLE();
// We just turned on the clock. This means that anything stored
// in dma_last_channel (for DMA1) needs to be invalidated.
@ -384,7 +384,7 @@ static void dma_enable_clock(dma_id_t dma_id) {
}
} else {
if (((old_enable_mask & DMA2_ENABLE_MASK) == 0) && !DMA2_IS_CLK_ENABLED()) {
__DMA2_CLK_ENABLE();
__HAL_RCC_DMA2_CLK_ENABLE();
// We just turned on the clock. This means that anything stored
// in dma_last_channel (for DMA1) needs to be invalidated.
@ -494,9 +494,9 @@ void dma_idle_handler(int tick) {
// Now we'll really disable the clock.
dma_idle.counter[controller] = 0;
if (controller == 0) {
__DMA1_CLK_DISABLE();
__HAL_RCC_DMA1_CLK_DISABLE();
} else {
__DMA2_CLK_DISABLE();
__HAL_RCC_DMA2_CLK_DISABLE();
}
} else {
// Something is still active, but the counter never got

View File

@ -203,7 +203,7 @@ uint extint_register(mp_obj_t pin_obj, uint32_t mode, uint32_t pull, mp_obj_t ca
exti.Pin = pin->pin_mask;
exti.Mode = mode;
exti.Pull = pull;
exti.Speed = GPIO_SPEED_FAST;
exti.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(pin->gpio, &exti);
// Calling HAL_GPIO_Init does an implicit extint_enable

View File

@ -32,7 +32,7 @@ DWORD get_fattime(void) {
rtc_init_finalise();
RTC_TimeTypeDef time;
RTC_DateTypeDef date;
HAL_RTC_GetTime(&RTCHandle, &time, FORMAT_BIN);
HAL_RTC_GetDate(&RTCHandle, &date, FORMAT_BIN);
HAL_RTC_GetTime(&RTCHandle, &time, RTC_FORMAT_BIN);
HAL_RTC_GetDate(&RTCHandle, &date, RTC_FORMAT_BIN);
return ((2000 + date.Year - 1980) << 25) | ((date.Month) << 21) | ((date.Date) << 16) | ((time.Hours) << 11) | ((time.Minutes) << 5) | (time.Seconds / 2);
}

View File

@ -428,10 +428,10 @@ int main(void) {
SystemClock_Config();
// enable GPIO clocks
__GPIOA_CLK_ENABLE();
__GPIOB_CLK_ENABLE();
__GPIOC_CLK_ENABLE();
__GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
#if defined(MCU_SERIES_F4) || defined(MCU_SERIES_F7)
#if defined(__HAL_RCC_DTCMRAMEN_CLK_ENABLE)

View File

@ -223,7 +223,7 @@ STATIC NORETURN mp_obj_t machine_bootloader(void) {
((void (*)(void)) *((uint32_t*) 0x1FF00004))();
#else
__HAL_REMAPMEMORY_SYSTEMFLASH();
__HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();
// arm-none-eabi-gcc 4.9.0 does not correctly inline this
// MSP function, so we write it out explicitly here.

View File

@ -60,8 +60,8 @@ STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) {
rtc_init_finalise();
RTC_DateTypeDef date;
RTC_TimeTypeDef time;
HAL_RTC_GetTime(&RTCHandle, &time, FORMAT_BIN);
HAL_RTC_GetDate(&RTCHandle, &date, FORMAT_BIN);
HAL_RTC_GetTime(&RTCHandle, &time, RTC_FORMAT_BIN);
HAL_RTC_GetDate(&RTCHandle, &date, RTC_FORMAT_BIN);
mp_obj_t tuple[8] = {
mp_obj_new_int(2000 + date.Year),
mp_obj_new_int(date.Month),
@ -123,8 +123,8 @@ STATIC mp_obj_t time_time(void) {
rtc_init_finalise();
RTC_DateTypeDef date;
RTC_TimeTypeDef time;
HAL_RTC_GetTime(&RTCHandle, &time, FORMAT_BIN);
HAL_RTC_GetDate(&RTCHandle, &date, FORMAT_BIN);
HAL_RTC_GetTime(&RTCHandle, &time, RTC_FORMAT_BIN);
HAL_RTC_GetDate(&RTCHandle, &date, RTC_FORMAT_BIN);
return mp_obj_new_int(timeutils_seconds_since_2000(2000 + date.Year, date.Month, date.Date, time.Hours, time.Minutes, time.Seconds));
}
MP_DEFINE_CONST_FUN_OBJ_0(time_time_obj, time_time);

View File

@ -99,53 +99,53 @@ void mp_hal_ticks_cpu_enable(void) {
void mp_hal_gpio_clock_enable(GPIO_TypeDef *gpio) {
if (0) {
#ifdef __GPIOA_CLK_ENABLE
#ifdef __HAL_RCC_GPIOA_CLK_ENABLE
} else if (gpio == GPIOA) {
__GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
#endif
#ifdef __GPIOB_CLK_ENABLE
#ifdef __HAL_RCC_GPIOB_CLK_ENABLE
} else if (gpio == GPIOB) {
__GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
#endif
#ifdef __GPIOC_CLK_ENABLE
#ifdef __HAL_RCC_GPIOC_CLK_ENABLE
} else if (gpio == GPIOC) {
__GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
#endif
#ifdef __GPIOD_CLK_ENABLE
#ifdef __HAL_RCC_GPIOD_CLK_ENABLE
} else if (gpio == GPIOD) {
__GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
#endif
#ifdef __GPIOE_CLK_ENABLE
#ifdef __HAL_RCC_GPIOE_CLK_ENABLE
} else if (gpio == GPIOE) {
__GPIOE_CLK_ENABLE();
__HAL_RCC_GPIOE_CLK_ENABLE();
#endif
#if defined(GPIOF) && defined(__GPIOF_CLK_ENABLE)
#ifdef __HAL_RCC_GPIOF_CLK_ENABLE
} else if (gpio == GPIOF) {
__GPIOF_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE();
#endif
#if defined(GPIOG) && defined(__GPIOG_CLK_ENABLE)
#ifdef __HAL_RCC_GPIOG_CLK_ENABLE
} else if (gpio == GPIOG) {
#if defined(STM32L476xx) || defined(STM32L486xx)
// Port G pins 2 thru 15 are powered using VddIO2 on these MCUs.
HAL_PWREx_EnableVddIO2();
#endif
__GPIOG_CLK_ENABLE();
__HAL_RCC_GPIOG_CLK_ENABLE();
#endif
#ifdef __GPIOH_CLK_ENABLE
#ifdef __HAL_RCC_GPIOH_CLK_ENABLE
} else if (gpio == GPIOH) {
__GPIOH_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
#endif
#if defined(GPIOI) && defined(__GPIOI_CLK_ENABLE)
#ifdef __HAL_RCC_GPIOI_CLK_ENABLE
} else if (gpio == GPIOI) {
__GPIOI_CLK_ENABLE();
__HAL_RCC_GPIOI_CLK_ENABLE();
#endif
#if defined(GPIOJ) && defined(__GPIOJ_CLK_ENABLE)
#ifdef __HAL_RCC_GPIOJ_CLK_ENABLE
} else if (gpio == GPIOJ) {
__GPIOJ_CLK_ENABLE();
__HAL_RCC_GPIOJ_CLK_ENABLE();
#endif
#if defined(GPIOK) && defined(__GPIOK_CLK_ENABLE)
#ifdef __HAL_RCC_GPIOK_CLK_ENABLE
} else if (gpio == GPIOK) {
__GPIOK_CLK_ENABLE();
__HAL_RCC_GPIOK_CLK_ENABLE();
#endif
}
}

View File

@ -376,7 +376,7 @@ STATIC mp_obj_t pin_obj_init_helper(const pin_obj_t *self, size_t n_args, const
GPIO_InitStructure.Pin = self->pin_mask;
GPIO_InitStructure.Mode = mode;
GPIO_InitStructure.Pull = pull;
GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStructure.Alternate = af;
HAL_GPIO_Init(self->gpio, &GPIO_InitStructure);

View File

@ -224,7 +224,7 @@ STATIC HAL_StatusTypeDef PYB_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruc
/*------------------------------ LSE Configuration -------------------------*/
if ((RCC_OscInitStruct->OscillatorType & RCC_OSCILLATORTYPE_LSE) == RCC_OSCILLATORTYPE_LSE) {
// Enable Power Clock
__PWR_CLK_ENABLE();
__HAL_RCC_PWR_CLK_ENABLE();
HAL_PWR_EnableBkUpAccess();
uint32_t tickstart = HAL_GetTick();
@ -243,7 +243,7 @@ STATIC HAL_StatusTypeDef PYB_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruc
//PWR->CR |= PWR_CR_DBP;
// Wait for Backup domain Write protection disable
while ((PWR->CR & PWR_CR_DBP) == RESET) {
if (HAL_GetTick() - tickstart > DBP_TIMEOUT_VALUE) {
if (HAL_GetTick() - tickstart > RCC_DBP_TIMEOUT_VALUE) {
return HAL_TIMEOUT;
}
}
@ -399,7 +399,7 @@ STATIC void RTC_CalendarConfig(void) {
date.Date = 1;
date.WeekDay = RTC_WEEKDAY_THURSDAY;
if(HAL_RTC_SetDate(&RTCHandle, &date, FORMAT_BIN) != HAL_OK) {
if(HAL_RTC_SetDate(&RTCHandle, &date, RTC_FORMAT_BIN) != HAL_OK) {
// init error
return;
}
@ -413,7 +413,7 @@ STATIC void RTC_CalendarConfig(void) {
time.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
time.StoreOperation = RTC_STOREOPERATION_RESET;
if (HAL_RTC_SetTime(&RTCHandle, &time, FORMAT_BIN) != HAL_OK) {
if (HAL_RTC_SetTime(&RTCHandle, &time, RTC_FORMAT_BIN) != HAL_OK) {
// init error
return;
}
@ -496,8 +496,8 @@ mp_obj_t pyb_rtc_datetime(size_t n_args, const mp_obj_t *args) {
// note: need to call get time then get date to correctly access the registers
RTC_DateTypeDef date;
RTC_TimeTypeDef time;
HAL_RTC_GetTime(&RTCHandle, &time, FORMAT_BIN);
HAL_RTC_GetDate(&RTCHandle, &date, FORMAT_BIN);
HAL_RTC_GetTime(&RTCHandle, &time, RTC_FORMAT_BIN);
HAL_RTC_GetDate(&RTCHandle, &date, RTC_FORMAT_BIN);
mp_obj_t tuple[8] = {
mp_obj_new_int(2000 + date.Year),
mp_obj_new_int(date.Month),
@ -519,7 +519,7 @@ mp_obj_t pyb_rtc_datetime(size_t n_args, const mp_obj_t *args) {
date.Month = mp_obj_get_int(items[1]);
date.Date = mp_obj_get_int(items[2]);
date.WeekDay = mp_obj_get_int(items[3]);
HAL_RTC_SetDate(&RTCHandle, &date, FORMAT_BIN);
HAL_RTC_SetDate(&RTCHandle, &date, RTC_FORMAT_BIN);
RTC_TimeTypeDef time;
time.Hours = mp_obj_get_int(items[4]);
@ -529,7 +529,7 @@ mp_obj_t pyb_rtc_datetime(size_t n_args, const mp_obj_t *args) {
time.TimeFormat = RTC_HOURFORMAT12_AM;
time.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
time.StoreOperation = RTC_STOREOPERATION_SET;
HAL_RTC_SetTime(&RTCHandle, &time, FORMAT_BIN);
HAL_RTC_SetTime(&RTCHandle, &time, RTC_FORMAT_BIN);
return mp_const_none;
}

View File

@ -537,7 +537,7 @@ STATIC void spi_print(const mp_print_t *print, const spi_t *spi_obj, bool legacy
mp_printf(print, ", SPI.SLAVE");
}
mp_printf(print, ", polarity=%u, phase=%u, bits=%u", spi->Init.CLKPolarity == SPI_POLARITY_LOW ? 0 : 1, spi->Init.CLKPhase == SPI_PHASE_1EDGE ? 0 : 1, spi->Init.DataSize == SPI_DATASIZE_8BIT ? 8 : 16);
if (spi->Init.CRCCalculation == SPI_CRCCALCULATION_ENABLED) {
if (spi->Init.CRCCalculation == SPI_CRCCALCULATION_ENABLE) {
mp_printf(print, ", crc=0x%x", spi->Init.CRCPolynomial);
}
}
@ -600,12 +600,12 @@ STATIC mp_obj_t pyb_spi_init_helper(const pyb_spi_obj_t *self, size_t n_args, co
init->Direction = args[5].u_int;
init->NSS = args[7].u_int;
init->TIMode = args[9].u_bool ? SPI_TIMODE_ENABLED : SPI_TIMODE_DISABLED;
init->TIMode = args[9].u_bool ? SPI_TIMODE_ENABLE : SPI_TIMODE_DISABLE;
if (args[10].u_obj == mp_const_none) {
init->CRCCalculation = SPI_CRCCALCULATION_DISABLED;
init->CRCCalculation = SPI_CRCCALCULATION_DISABLE;
init->CRCPolynomial = 0;
} else {
init->CRCCalculation = SPI_CRCCALCULATION_ENABLED;
init->CRCCalculation = SPI_CRCCALCULATION_ENABLE;
init->CRCPolynomial = mp_obj_get_int(args[10].u_obj);
}
@ -916,7 +916,7 @@ mp_obj_t machine_hard_spi_make_new(const mp_obj_type_t *type, size_t n_args, siz
init->Direction = SPI_DIRECTION_2LINES;
init->NSS = SPI_NSS_SOFT;
init->TIMode = SPI_TIMODE_DISABLED;
init->CRCCalculation = SPI_CRCCALCULATION_DISABLED;
init->CRCCalculation = SPI_CRCCALCULATION_DISABLE;
init->CRCPolynomial = 0;
// set configurable paramaters

View File

@ -166,7 +166,7 @@ void timer_deinit(void) {
// This function inits but does not start the timer
void timer_tim5_init(void) {
// TIM5 clock enable
__TIM5_CLK_ENABLE();
__HAL_RCC_TIM5_CLK_ENABLE();
// set up and enable interrupt
HAL_NVIC_SetPriority(TIM5_IRQn, IRQ_PRI_TIM5, IRQ_SUBPRI_TIM5);
@ -188,7 +188,7 @@ void timer_tim5_init(void) {
// This function inits but does not start the timer
TIM_HandleTypeDef *timer_tim6_init(uint freq) {
// TIM6 clock enable
__TIM6_CLK_ENABLE();
__HAL_RCC_TIM6_CLK_ENABLE();
// Timer runs at SystemCoreClock / 2
// Compute the prescaler value so TIM6 triggers at freq-Hz
@ -302,7 +302,7 @@ STATIC uint32_t compute_prescaler_period_from_freq(pyb_timer_obj_t *self, mp_obj
STATIC uint32_t compute_period(pyb_timer_obj_t *self) {
// In center mode, compare == period corresponds to 100%
// In edge mode, compare == (period + 1) corresponds to 100%
uint32_t period = (__HAL_TIM_GetAutoreload(&self->tim) & TIMER_CNT_MASK(self));
uint32_t period = (__HAL_TIM_GET_AUTORELOAD(&self->tim) & TIMER_CNT_MASK(self));
if (period != 0xffffffff) {
if (self->tim.Init.CounterMode == TIM_COUNTERMODE_UP ||
self->tim.Init.CounterMode == TIM_COUNTERMODE_DOWN) {
@ -439,7 +439,7 @@ STATIC void pyb_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_
mp_printf(print, "Timer(%u)", self->tim_id);
} else {
uint32_t prescaler = self->tim.Instance->PSC & 0xffff;
uint32_t period = __HAL_TIM_GetAutoreload(&self->tim) & TIMER_CNT_MASK(self);
uint32_t period = __HAL_TIM_GET_AUTORELOAD(&self->tim) & TIMER_CNT_MASK(self);
// for efficiency, we compute and print freq as an int (not a float)
uint32_t freq = timer_get_source_freq(self->tim_id) / ((prescaler + 1) * (period + 1));
mp_printf(print, "Timer(%u, freq=%u, prescaler=%u, period=%u, mode=%s, div=%u",
@ -554,46 +554,46 @@ STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, size_t n_args, cons
// enable TIM clock
switch (self->tim_id) {
case 1: __TIM1_CLK_ENABLE(); break;
case 2: __TIM2_CLK_ENABLE(); break;
case 3: __TIM3_CLK_ENABLE(); break;
case 4: __TIM4_CLK_ENABLE(); break;
case 5: __TIM5_CLK_ENABLE(); break;
case 1: __HAL_RCC_TIM1_CLK_ENABLE(); break;
case 2: __HAL_RCC_TIM2_CLK_ENABLE(); break;
case 3: __HAL_RCC_TIM3_CLK_ENABLE(); break;
case 4: __HAL_RCC_TIM4_CLK_ENABLE(); break;
case 5: __HAL_RCC_TIM5_CLK_ENABLE(); break;
#if defined(TIM6)
case 6: __TIM6_CLK_ENABLE(); break;
case 6: __HAL_RCC_TIM6_CLK_ENABLE(); break;
#endif
#if defined(TIM7)
case 7: __TIM7_CLK_ENABLE(); break;
case 7: __HAL_RCC_TIM7_CLK_ENABLE(); break;
#endif
#if defined(TIM8)
case 8: __TIM8_CLK_ENABLE(); break;
case 8: __HAL_RCC_TIM8_CLK_ENABLE(); break;
#endif
#if defined(TIM9)
case 9: __TIM9_CLK_ENABLE(); break;
case 9: __HAL_RCC_TIM9_CLK_ENABLE(); break;
#endif
#if defined(TIM10)
case 10: __TIM10_CLK_ENABLE(); break;
case 10: __HAL_RCC_TIM10_CLK_ENABLE(); break;
#endif
#if defined(TIM11)
case 11: __TIM11_CLK_ENABLE(); break;
case 11: __HAL_RCC_TIM11_CLK_ENABLE(); break;
#endif
#if defined(TIM12)
case 12: __TIM12_CLK_ENABLE(); break;
case 12: __HAL_RCC_TIM12_CLK_ENABLE(); break;
#endif
#if defined(TIM13)
case 13: __TIM13_CLK_ENABLE(); break;
case 13: __HAL_RCC_TIM13_CLK_ENABLE(); break;
#endif
#if defined(TIM14)
case 14: __TIM14_CLK_ENABLE(); break;
case 14: __HAL_RCC_TIM14_CLK_ENABLE(); break;
#endif
#if defined(TIM15)
case 15: __TIM15_CLK_ENABLE(); break;
case 15: __HAL_RCC_TIM15_CLK_ENABLE(); break;
#endif
#if defined(TIM16)
case 16: __TIM16_CLK_ENABLE(); break;
case 16: __HAL_RCC_TIM16_CLK_ENABLE(); break;
#endif
#if defined(TIM17)
case 17: __TIM17_CLK_ENABLE(); break;
case 17: __HAL_RCC_TIM17_CLK_ENABLE(); break;
#endif
}
@ -1062,7 +1062,7 @@ STATIC mp_obj_t pyb_timer_channel(size_t n_args, const mp_obj_t *pos_args, mp_ma
// an interrupt by initializing the timer.
__HAL_TIM_DISABLE_IT(&self->tim, TIM_IT_UPDATE);
HAL_TIM_Encoder_Init(&self->tim, &enc_config);
__HAL_TIM_SetCounter(&self->tim, 0);
__HAL_TIM_SET_COUNTER(&self->tim, 0);
if (self->callback != mp_const_none) {
__HAL_TIM_CLEAR_FLAG(&self->tim, TIM_IT_UPDATE);
__HAL_TIM_ENABLE_IT(&self->tim, TIM_IT_UPDATE);
@ -1088,7 +1088,7 @@ STATIC mp_obj_t pyb_timer_counter(size_t n_args, const mp_obj_t *args) {
return mp_obj_new_int(self->tim.Instance->CNT);
} else {
// set
__HAL_TIM_SetCounter(&self->tim, mp_obj_get_int(args[1]));
__HAL_TIM_SET_COUNTER(&self->tim, mp_obj_get_int(args[1]));
return mp_const_none;
}
}
@ -1110,7 +1110,7 @@ STATIC mp_obj_t pyb_timer_freq(size_t n_args, const mp_obj_t *args) {
if (n_args == 1) {
// get
uint32_t prescaler = self->tim.Instance->PSC & 0xffff;
uint32_t period = __HAL_TIM_GetAutoreload(&self->tim) & TIMER_CNT_MASK(self);
uint32_t period = __HAL_TIM_GET_AUTORELOAD(&self->tim) & TIMER_CNT_MASK(self);
uint32_t source_freq = timer_get_source_freq(self->tim_id);
uint32_t divide = ((prescaler + 1) * (period + 1));
#if MICROPY_PY_BUILTINS_FLOAT
@ -1126,7 +1126,7 @@ STATIC mp_obj_t pyb_timer_freq(size_t n_args, const mp_obj_t *args) {
uint32_t period;
uint32_t prescaler = compute_prescaler_period_from_freq(self, args[1], &period);
self->tim.Instance->PSC = prescaler;
__HAL_TIM_SetAutoreload(&self->tim, period);
__HAL_TIM_SET_AUTORELOAD(&self->tim, period);
return mp_const_none;
}
}
@ -1153,10 +1153,10 @@ STATIC mp_obj_t pyb_timer_period(size_t n_args, const mp_obj_t *args) {
pyb_timer_obj_t *self = args[0];
if (n_args == 1) {
// get
return mp_obj_new_int(__HAL_TIM_GetAutoreload(&self->tim) & TIMER_CNT_MASK(self));
return mp_obj_new_int(__HAL_TIM_GET_AUTORELOAD(&self->tim) & TIMER_CNT_MASK(self));
} else {
// set
__HAL_TIM_SetAutoreload(&self->tim, mp_obj_get_int(args[1]) & TIMER_CNT_MASK(self));
__HAL_TIM_SET_AUTORELOAD(&self->tim, mp_obj_get_int(args[1]) & TIMER_CNT_MASK(self));
return mp_const_none;
}
}
@ -1265,10 +1265,10 @@ STATIC mp_obj_t pyb_timer_channel_capture_compare(size_t n_args, const mp_obj_t
pyb_timer_channel_obj_t *self = args[0];
if (n_args == 1) {
// get
return mp_obj_new_int(__HAL_TIM_GetCompare(&self->timer->tim, TIMER_CHANNEL(self)) & TIMER_CNT_MASK(self->timer));
return mp_obj_new_int(__HAL_TIM_GET_COMPARE(&self->timer->tim, TIMER_CHANNEL(self)) & TIMER_CNT_MASK(self->timer));
} else {
// set
__HAL_TIM_SetCompare(&self->timer->tim, TIMER_CHANNEL(self), mp_obj_get_int(args[1]) & TIMER_CNT_MASK(self->timer));
__HAL_TIM_SET_COMPARE(&self->timer->tim, TIMER_CHANNEL(self), mp_obj_get_int(args[1]) & TIMER_CNT_MASK(self->timer));
return mp_const_none;
}
}
@ -1285,12 +1285,12 @@ STATIC mp_obj_t pyb_timer_channel_pulse_width_percent(size_t n_args, const mp_ob
uint32_t period = compute_period(self->timer);
if (n_args == 1) {
// get
uint32_t cmp = __HAL_TIM_GetCompare(&self->timer->tim, TIMER_CHANNEL(self)) & TIMER_CNT_MASK(self->timer);
uint32_t cmp = __HAL_TIM_GET_COMPARE(&self->timer->tim, TIMER_CHANNEL(self)) & TIMER_CNT_MASK(self->timer);
return compute_percent_from_pwm_value(period, cmp);
} else {
// set
uint32_t cmp = compute_pwm_value_from_percent(period, args[1]);
__HAL_TIM_SetCompare(&self->timer->tim, TIMER_CHANNEL(self), cmp & TIMER_CNT_MASK(self->timer));
__HAL_TIM_SET_COMPARE(&self->timer->tim, TIMER_CHANNEL(self), cmp & TIMER_CNT_MASK(self->timer));
return mp_const_none;
}
}
@ -1365,7 +1365,7 @@ STATIC void timer_handle_irq_channel(pyb_timer_obj_t *tim, uint8_t channel, mp_o
uint32_t irq_mask = TIMER_IRQ_MASK(channel);
if (__HAL_TIM_GET_FLAG(&tim->tim, irq_mask) != RESET) {
if (__HAL_TIM_GET_ITSTATUS(&tim->tim, irq_mask) != RESET) {
if (__HAL_TIM_GET_IT_SOURCE(&tim->tim, irq_mask) != RESET) {
// clear the interrupt
__HAL_TIM_CLEAR_IT(&tim->tim, irq_mask);

View File

@ -166,7 +166,7 @@ STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
irqn = USART1_IRQn;
pins[0] = &MICROPY_HW_UART1_TX;
pins[1] = &MICROPY_HW_UART1_RX;
__USART1_CLK_ENABLE();
__HAL_RCC_USART1_CLK_ENABLE();
break;
#endif
@ -187,7 +187,7 @@ STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
pins[3] = &MICROPY_HW_UART2_CTS;
}
#endif
__USART2_CLK_ENABLE();
__HAL_RCC_USART2_CLK_ENABLE();
break;
#endif
@ -208,7 +208,7 @@ STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
pins[3] = &MICROPY_HW_UART3_CTS;
}
#endif
__USART3_CLK_ENABLE();
__HAL_RCC_USART3_CLK_ENABLE();
break;
#endif
@ -219,7 +219,7 @@ STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
irqn = UART4_IRQn;
pins[0] = &MICROPY_HW_UART4_TX;
pins[1] = &MICROPY_HW_UART4_RX;
__UART4_CLK_ENABLE();
__HAL_RCC_UART4_CLK_ENABLE();
break;
#endif
@ -230,7 +230,7 @@ STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
irqn = UART5_IRQn;
pins[0] = &MICROPY_HW_UART5_TX;
pins[1] = &MICROPY_HW_UART5_RX;
__UART5_CLK_ENABLE();
__HAL_RCC_UART5_CLK_ENABLE();
break;
#endif
@ -251,7 +251,7 @@ STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
pins[3] = &MICROPY_HW_UART6_CTS;
}
#endif
__USART6_CLK_ENABLE();
__HAL_RCC_USART6_CLK_ENABLE();
break;
#endif
@ -262,7 +262,7 @@ STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
irqn = UART7_IRQn;
pins[0] = &MICROPY_HW_UART7_TX;
pins[1] = &MICROPY_HW_UART7_RX;
__UART7_CLK_ENABLE();
__HAL_RCC_UART7_CLK_ENABLE();
break;
#endif
@ -273,7 +273,7 @@ STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
irqn = UART8_IRQn;
pins[0] = &MICROPY_HW_UART8_TX;
pins[1] = &MICROPY_HW_UART8_RX;
__UART8_CLK_ENABLE();
__HAL_RCC_UART8_CLK_ENABLE();
break;
#endif
@ -801,55 +801,55 @@ STATIC mp_obj_t pyb_uart_deinit(mp_obj_t self_in) {
HAL_UART_DeInit(uart);
if (uart->Instance == USART1) {
HAL_NVIC_DisableIRQ(USART1_IRQn);
__USART1_FORCE_RESET();
__USART1_RELEASE_RESET();
__USART1_CLK_DISABLE();
__HAL_RCC_USART1_FORCE_RESET();
__HAL_RCC_USART1_RELEASE_RESET();
__HAL_RCC_USART1_CLK_DISABLE();
} else if (uart->Instance == USART2) {
HAL_NVIC_DisableIRQ(USART2_IRQn);
__USART2_FORCE_RESET();
__USART2_RELEASE_RESET();
__USART2_CLK_DISABLE();
__HAL_RCC_USART2_FORCE_RESET();
__HAL_RCC_USART2_RELEASE_RESET();
__HAL_RCC_USART2_CLK_DISABLE();
#if defined(USART3)
} else if (uart->Instance == USART3) {
HAL_NVIC_DisableIRQ(USART3_IRQn);
__USART3_FORCE_RESET();
__USART3_RELEASE_RESET();
__USART3_CLK_DISABLE();
__HAL_RCC_USART3_FORCE_RESET();
__HAL_RCC_USART3_RELEASE_RESET();
__HAL_RCC_USART3_CLK_DISABLE();
#endif
#if defined(UART4)
} else if (uart->Instance == UART4) {
HAL_NVIC_DisableIRQ(UART4_IRQn);
__UART4_FORCE_RESET();
__UART4_RELEASE_RESET();
__UART4_CLK_DISABLE();
__HAL_RCC_UART4_FORCE_RESET();
__HAL_RCC_UART4_RELEASE_RESET();
__HAL_RCC_UART4_CLK_DISABLE();
#endif
#if defined(UART5)
} else if (uart->Instance == UART5) {
HAL_NVIC_DisableIRQ(UART5_IRQn);
__UART5_FORCE_RESET();
__UART5_RELEASE_RESET();
__UART5_CLK_DISABLE();
__HAL_RCC_UART5_FORCE_RESET();
__HAL_RCC_UART5_RELEASE_RESET();
__HAL_RCC_UART5_CLK_DISABLE();
#endif
#if defined(UART6)
} else if (uart->Instance == USART6) {
HAL_NVIC_DisableIRQ(USART6_IRQn);
__USART6_FORCE_RESET();
__USART6_RELEASE_RESET();
__USART6_CLK_DISABLE();
__HAL_RCC_USART6_FORCE_RESET();
__HAL_RCC_USART6_RELEASE_RESET();
__HAL_RCC_USART6_CLK_DISABLE();
#endif
#if defined(UART7)
} else if (uart->Instance == UART7) {
HAL_NVIC_DisableIRQ(UART7_IRQn);
__UART7_FORCE_RESET();
__UART7_RELEASE_RESET();
__UART7_CLK_DISABLE();
__HAL_RCC_UART7_FORCE_RESET();
__HAL_RCC_UART7_RELEASE_RESET();
__HAL_RCC_UART7_CLK_DISABLE();
#endif
#if defined(UART8)
} else if (uart->Instance == UART8) {
HAL_NVIC_DisableIRQ(UART8_IRQn);
__UART8_FORCE_RESET();
__UART8_RELEASE_RESET();
__UART8_CLK_DISABLE();
__HAL_RCC_UART8_FORCE_RESET();
__HAL_RCC_UART8_RELEASE_RESET();
__HAL_RCC_UART8_CLK_DISABLE();
#endif
}
return mp_const_none;

View File

@ -63,12 +63,12 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
if(hpcd->Instance == USB_OTG_FS)
{
/* Configure USB FS GPIOs */
__GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12);
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
@ -119,13 +119,13 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
#if defined(USE_USB_HS_IN_FS)
/* Configure USB FS GPIOs */
__GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/* Configure DM DP Pins */
GPIO_InitStruct.Pin = (GPIO_PIN_14 | GPIO_PIN_15);
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF12_OTG_HS_FS;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
@ -134,7 +134,7 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
GPIO_InitStruct.Pin = GPIO_PIN_13;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF12_OTG_HS_FS;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
#endif
@ -144,7 +144,7 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
GPIO_InitStruct.Pin = GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF12_OTG_HS_FS;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
#endif
@ -169,17 +169,17 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
#else // !USE_USB_HS_IN_FS
/* Configure USB HS GPIOs */
__GPIOA_CLK_ENABLE();
__GPIOB_CLK_ENABLE();
__GPIOC_CLK_ENABLE();
__GPIOH_CLK_ENABLE();
__GPIOI_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
__HAL_RCC_GPIOI_CLK_ENABLE();
/* CLK */
GPIO_InitStruct.Pin = GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
@ -187,7 +187,7 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
GPIO_InitStruct.Pin = GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);