Last active
March 16, 2018 21:26
-
-
Save glegrain/205b61dea7093c9e562eaa35d8efa796 to your computer and use it in GitHub Desktop.
STM32-Nucleo LED2 Init
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GPIO_InitTypeDef GPIO_InitStruct; | |
__HAL_RCC_GPIOA_CLK_ENABLE(); | |
GPIO_InitStruct.Pin = GPIO_PIN_5; | |
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | |
GPIO_InitStruct.Pull = GPIO_PULLUP; | |
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; | |
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | |
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5); | |
/* GPIOA Clock Enable */ | |
RCC->AHB2ENR |= RCC_AHB2ENR_GPIOAEN; | |
__DSB(); /*!< Wait 2 Clock cycles before peripheral clock is active */ | |
__NOP(); | |
__NOP(); | |
/* Reset PA5 */ | |
GPIOA->MODER &= ~GPIO_MODER_MODE5_Msk; | |
GPIOA->OTYPER &= ~GPIO_OTYPER_OT5_Msk; | |
GPIOA->OSPEEDR &= ~GPIO_OSPEEDR_OSPEED5_Msk; | |
GPIOA->PUPDR &= ~GPIO_PUPDR_PUPD5_Msk; | |
GPIOA->AFR[0] &= ~GPIO_AFRL_AFSEL5_Msk; | |
/* Config PA5 */ | |
GPIOA->MODER |= (GPIO_MODE_OUTPUT_PP & 0x03) << GPIO_MODER_MODE5_Pos; | |
GPIOA->OTYPER |= (GPIO_MODE_OUTPUT_PP & 0x10) << GPIO_OTYPER_OT5_Pos; | |
GPIOA->OSPEEDR |= GPIO_SPEED_FREQ_VERY_HIGH << GPIO_OSPEEDR_OSPEED5_Pos; | |
GPIOA->PUPDR |= GPIO_PULLUP << GPIO_PUPDR_PUPD5_Pos; | |
/* Set PA5 */ | |
GPIOA->BSRR = GPIO_PIN_5; | |
/* Reset PA5 */ | |
GPIOA->BSRR = GPIO_PIN_5 << 16; | |
/* Toggle PA5 */ | |
GPIOA->ODR ^= GPIO_PIN_5; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment