I'm writing a program where I want to use the intensity/brightness of one of the onboard LEDs to indicate a specific state change. Is it possible to use PWM or some other means to modify the brightness of one of the onboard LEDs?
I have set a timer into PWM mode that ticks via interrupt every 50 ms and provides the PWM value range that I want. However, I'm unsure of how to make the GPIO pin (LD pins) respond to the ticks of the timer/PWM. I've tried configuring the LD/onboard-LED pins in the GPIO.c with the following code:
GPIO_InitStruct.Pin = LD4_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;
From the information I have gathered from the HAL manual and other online information, I hoped that these changes (setting GPIO_InitStruct.Mode = GPIO_MODE_AF_PP and GPIO_InitStruct.Alternate = GPIO_AF1_TIM2) would allow the timer to control the LED output however, with this code the LED doesn't activate at all.
Is there something I'm missing with this method or is this the completely wrong method to be trying to control the brightness of the onboard LED?
Any assistance on this would be appreciated.