Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.c
- Revision:
- 2:5acdd8565d02
- Parent:
- 0:a9bbfbd216e8
--- a/main.c Fri Feb 24 21:13:56 2017 +0000 +++ b/main.c Sat Feb 25 00:23:53 2017 +0000 @@ -2,28 +2,54 @@ #include "stm32l476g_discovery.h" #include "stm32l4xx_hal.h" +TIM_HandleTypeDef hTim; +TIM_OC_InitTypeDef timOutChannel; +RCC_ClkInitTypeDef RCC_ClkInitStruct; -// main() runs in its own thread in the OS -// (note the calls to wait below for delays) -int main() { +int main() +{ + // Configure Timer base + __HAL_RCC_TIM1_CLK_ENABLE(); + + hTim.Instance = TIM1; + hTim.Init.Prescaler = 8000; + hTim.Init.Period = 10000; + hTim.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + hTim.Init.CounterMode = TIM_COUNTERMODE_UP; + hTim.Init.RepetitionCounter = 0; + HAL_TIM_PWM_Init(&hTim); - LED4_GPIO_CLK_ENABLE(); + // Configure Timer channel + timOutChannel.OCMode = TIM_OCMODE_PWM1; + timOutChannel.OCPolarity = TIM_OCPOLARITY_HIGH; + timOutChannel.OCFastMode = TIM_OCFAST_DISABLE; + timOutChannel.OCNPolarity = TIM_OCNPOLARITY_HIGH; + timOutChannel.OCNIdleState = TIM_OCNIDLESTATE_RESET; + timOutChannel.OCIdleState = TIM_OCIDLESTATE_RESET; + timOutChannel.Pulse = 5000; + HAL_TIM_PWM_ConfigChannel(&hTim, &timOutChannel, TIM_CHANNEL_1); + HAL_TIMEx_OCN_Start(&hTim, TIM_CHANNEL_1); + + // Configure GPIO LED5_GPIO_CLK_ENABLE(); - GPIO_InitTypeDef gpio; - gpio.Mode = GPIO_MODE_OUTPUT_PP; + + gpio.Mode = GPIO_MODE_AF_PP; gpio.Pull = GPIO_NOPULL; - gpio.Speed = GPIO_SPEED_FREQ_LOW; - gpio.Pin = LED4_PIN; - HAL_GPIO_Init(LED4_GPIO_PORT, &gpio); - + gpio.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + gpio.Alternate = GPIO_AF1_TIM1; gpio.Pin = LED5_PIN; HAL_GPIO_Init(LED5_GPIO_PORT, &gpio); - while (1) { - HAL_GPIO_TogglePin(LED5_GPIO_PORT, LED5_PIN); - HAL_Delay(300); - HAL_GPIO_TogglePin(LED4_GPIO_PORT, LED4_PIN); - } + //Start timer + HAL_TIM_Base_Start(&hTim); + HAL_TIM_PWM_Start(&hTim, TIM_CHANNEL_1); + + while(1) {} } +/************** TODO ********************** + - Increase frequency + - Control pwm brightness with joystick + +*/