cancel
Showing results for 
Search instead for 
Did you mean: 

PWM , ENCODER, and etc in STM32 F407 HAL driver

ismimusyafani
Associate II
Posted on September 16, 2015 at 20:17

my name is musyafani, i am a student in Politeknik Elektronika Negeri Surabaya , Indonesia.

i want to ask, how to config PWM, USART, GPIO, I2C, TIMER, ENCODER in stm32f4_hal driver, not using std_periph driver. Usually i used std_periph driver, but in this case i must using HAL driver

please help me, because my final project in collage is using STM32F4 with Hal library

#stm32f4-hal-driver
4 REPLIES 4
Posted on September 16, 2015 at 22:59

If I were you, I'd start digging through the board/project examples included in the Cube F4 release

STM32Cube_FW_F4_V1.3.0\Projects\STM324x9I_EVAL\Examples\TIM\TIM_PWMOutput

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ismimusyafani
Associate II
Posted on September 20, 2015 at 20:15

i need encoder config, please tell me about it mr. clive. Thank you for your information. its very help me.

ismimusyafani
Associate II
Posted on September 20, 2015 at 21:40

   //usart config with HAL driver

 UartHandle.Instance          = USART1;

  UartHandle.Init.BaudRate     = 9600;

  UartHandle.Init.WordLength   = UART_WORDLENGTH_8B;

  UartHandle.Init.StopBits     = UART_STOPBITS_1;

  UartHandle.Init.Parity       = UART_PARITY_NONE;

  UartHandle.Init.HwFlowCtl    = UART_HWCONTROL_NONE;

  UartHandle.Init.Mode         = UART_MODE_TX_RX;

  UartHandle.Init.OverSampling = UART_OVERSAMPLING_16;

    

    HAL_UART_Init(&UartHandle);

 in this case, how to connect the pin to the usart ? In Std Periph is using AF (Alternate Function) like this code :

   //STD perih driver

    GPIO_PinAFConfig(GPIOB, GPIO_PinSource14, GPIO_AF_TIM12);   //TIM2_CH1

    GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_TIM12);    //TIM2_CH2

  please help me again mr clive, your information is important for me . thank you very much Mr. CLive

matic
Associate III
Posted on September 20, 2015 at 21:41

For Encoder (A,B,Z signals) configuration in Cube do that:

- First configure everything else (clock, SWDIO, SWCLK,...)

-  In

Pinout view

choose one timer where you want to have connected your encoder (preferably 32-bit timer, depends also on encoder resolution). In dropdown menu of that timer select ''

Encoder mode

''. This will reserve two pins (channel 1 and 2) for A and B inputs.

- If you want to have also Z signal (reference), configure channel 3 as ''

Input capture mode

''. This will reserve third pin for Z input.

- Then go to the

Configuration

view, where you have to do some additional configurations for that timer. Set ''

Period

'' to 0xFFFF (in case of 16-bit timer) or 0xFFFFFFFF (if it is 32-bit)

- Little bit further down you have to select that counter will increment on both edges (rising and falling) on both input signals (A and B). 

This is pretty much it. If you choose 16-bit timer and you will like to increase period to 32-bit, then you will have to do that in software (update interrupt enable, counting overflows/underflows, some shifting, etc., etc.). Not big deal.

If something doesn't work look in yours SFRs which bits are set and look in good trusty Reference Manual which bits should be set. There you have detailed description of that Encoder mode. I found this approach much more useful to learn something than just clicking in Cube and hoping it will work.