Selecting Alternate Function on STM32F1xx series
Posted: Sat Dec 24, 2016 2:43 am
TL;DR
On STM32F4xx I could use PAL_MODE_ALTERNATE(n) to configure a pin for a particular alternate function.
How to make sure on STM32F1xx that a pin in initialized correctly for a particular alternate function? Do I need to see the reference manual every time to find out the appropriate setting (PAL_MODE_STM32_ALTERNATE_PUSHPULL, PAL_MODE_INPUT_PULLUP, etc.) for each pin against each alternate function or is there some more elegant way to correctly initialize the required pins?
Hi all,
On an STM32F407-Discovery Kit, I could easily tell PA2 and PA3 to connect to SERIAL 2 hardware using:
I came across some cheap STM32F103C8-MINIMUM boards. I copied RT-STM32F103-STM3210E_EVAL-FATFS-USB demo project, and made appropriate changes in the Makefile. Then, removed most of the demo code and replaced it with a very simple LED blinking code. Compiled it and after a few tries, it worked fine. Then I tried to enable SERIAL 2 hardware on PA2 and PA3, only to learn that STM32F1xx series doesn't number the alternate function like STM32F4xx.
ST's Reference manual for STM32F1xx says that:
Following instructions from ST reference manual (Table 24: USARTs), I learnt that I could configure PA2 and PA3 for SERIAL 2 using:
So here's my question:
On STM32F4xx I could use PAL_MODE_ALTERNATE(n) to configure a pin for a particular alternate function.
How to make sure on STM32F1xx that a pin in initialized correctly for a particular alternate function? Do I need to see the reference manual every time to find out the appropriate setting (PAL_MODE_STM32_ALTERNATE_PUSHPULL, PAL_MODE_INPUT_PULLUP, etc.) for each pin against each alternate function or is there some more elegant way to correctly initialize the required pins?
Cheers.
On STM32F4xx I could use PAL_MODE_ALTERNATE(n) to configure a pin for a particular alternate function.
How to make sure on STM32F1xx that a pin in initialized correctly for a particular alternate function? Do I need to see the reference manual every time to find out the appropriate setting (PAL_MODE_STM32_ALTERNATE_PUSHPULL, PAL_MODE_INPUT_PULLUP, etc.) for each pin against each alternate function or is there some more elegant way to correctly initialize the required pins?
Hi all,
On an STM32F407-Discovery Kit, I could easily tell PA2 and PA3 to connect to SERIAL 2 hardware using:
Code: Select all
//Pins initialization for STM32F4xx
palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7));
palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7));
I came across some cheap STM32F103C8-MINIMUM boards. I copied RT-STM32F103-STM3210E_EVAL-FATFS-USB demo project, and made appropriate changes in the Makefile. Then, removed most of the demo code and replaced it with a very simple LED blinking code. Compiled it and after a few tries, it worked fine. Then I tried to enable SERIAL 2 hardware on PA2 and PA3, only to learn that STM32F1xx series doesn't number the alternate function like STM32F4xx.
ST's Reference manual for STM32F1xx says that:
If several peripherals share the same I/O pin, to avoid conflict between these alternate functions only one peripheral should be enabled at a time through the peripheral clock enable bit (in the corresponding RCC peripheral clock enable register).
Following instructions from ST reference manual (Table 24: USARTs), I learnt that I could configure PA2 and PA3 for SERIAL 2 using:
Code: Select all
//Pins initialization for STM32F1xx
palSetPadMode(GPIOA, 2, PAL_MODE_STM32_ALTERNATE_PUSHPULL );
palSetPadMode(GPIOA, 3, PAL_MODE_INPUT_PULLUP );
So here's my question:
On STM32F4xx I could use PAL_MODE_ALTERNATE(n) to configure a pin for a particular alternate function.
How to make sure on STM32F1xx that a pin in initialized correctly for a particular alternate function? Do I need to see the reference manual every time to find out the appropriate setting (PAL_MODE_STM32_ALTERNATE_PUSHPULL, PAL_MODE_INPUT_PULLUP, etc.) for each pin against each alternate function or is there some more elegant way to correctly initialize the required pins?
Cheers.