2020-05-02 03:39 AM
2020-05-02 07:29 AM
20 kHz PWM can be generated on any number of different TIM channel pins.
A 4-wire fan typically needs a 12V supply, which doesn't exist on that board. You'd need an external supply. The PWM signal could come from the board though.
2020-05-02 09:14 AM
1. Find a free pin which can be mapped to a timer channel.
Although there seem to be a lot of pins available on the board, most of them is connected to onboard peripherals as well. Find the ones that are not used for board functions (except being available on the P1 or P2 header) in Table 6. STM32 pin description versus board functions of the board user manual. Make a list of them.
Find out the exact part number of the onboard MCU, get its datasheet, and look up the STM32F429xx alternate function mapping table in it. Check the list of free pins, pick one which has a TIMx_CHy function. Note the AF number in the column header, you will need it later.
From now on, you will need the RM0090 Reference Manual a lot. Check the description of every register and feature I mention below in the manual. If something is not clear, the answer is usually there,
2. Enable the peripheral clock for the pin in RCC->AHB1ENR, and for the timer in RCC->APB1ENR or RCC->APB2ENR. Note which one, it will affect the base frequency of the timer.
3. Take the AF number from step 1, write it to the bitfield corresponding to the pin in the GPIO AFRL or AFRH register. Note that you can access AFRL as AFR[0], and AFRH as AFR[1]. Then set up the bits in the MODER register to alternate mode. Now the pin is connected to the timer channel.
4. Read the Time-base unit, then the PWM mode (not the PWM input) section of the reference manual. There are step-by-step instructions in the PWM mode section, with examples on what bitfields should be set in the timer registers to get a PWM signal. Finally, start the timer with TIMx->CR1|=TIM_CR1_CEN;