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.
main.c
00001 #define USE_STM32L476G_DISCO_REVC 00002 #include "stm32l476g_discovery.h" 00003 #include "stm32l4xx_hal.h" 00004 00005 TIM_HandleTypeDef hTim; 00006 TIM_OC_InitTypeDef timOutChannel; 00007 RCC_ClkInitTypeDef RCC_ClkInitStruct; 00008 00009 int main() 00010 { 00011 // Configure Timer base 00012 __HAL_RCC_TIM1_CLK_ENABLE(); 00013 00014 hTim.Instance = TIM1; 00015 hTim.Init.Prescaler = 8000; 00016 hTim.Init.Period = 10000; 00017 hTim.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; 00018 hTim.Init.CounterMode = TIM_COUNTERMODE_UP; 00019 hTim.Init.RepetitionCounter = 0; 00020 HAL_TIM_PWM_Init(&hTim); 00021 00022 // Configure Timer channel 00023 timOutChannel.OCMode = TIM_OCMODE_PWM1; 00024 timOutChannel.OCPolarity = TIM_OCPOLARITY_HIGH; 00025 timOutChannel.OCFastMode = TIM_OCFAST_DISABLE; 00026 timOutChannel.OCNPolarity = TIM_OCNPOLARITY_HIGH; 00027 timOutChannel.OCNIdleState = TIM_OCNIDLESTATE_RESET; 00028 timOutChannel.OCIdleState = TIM_OCIDLESTATE_RESET; 00029 timOutChannel.Pulse = 5000; 00030 HAL_TIM_PWM_ConfigChannel(&hTim, &timOutChannel, TIM_CHANNEL_1); 00031 HAL_TIMEx_OCN_Start(&hTim, TIM_CHANNEL_1); 00032 00033 // Configure GPIO 00034 LED5_GPIO_CLK_ENABLE(); 00035 GPIO_InitTypeDef gpio; 00036 00037 gpio.Mode = GPIO_MODE_AF_PP; 00038 gpio.Pull = GPIO_NOPULL; 00039 gpio.Speed = GPIO_SPEED_FREQ_VERY_HIGH; 00040 gpio.Alternate = GPIO_AF1_TIM1; 00041 gpio.Pin = LED5_PIN; 00042 HAL_GPIO_Init(LED5_GPIO_PORT, &gpio); 00043 00044 //Start timer 00045 HAL_TIM_Base_Start(&hTim); 00046 HAL_TIM_PWM_Start(&hTim, TIM_CHANNEL_1); 00047 00048 while(1) {} 00049 } 00050 00051 /************** TODO ********************** 00052 - Increase frequency 00053 - Control pwm brightness with joystick 00054 00055 */
Generated on Tue Jul 12 2022 18:10:40 by
