I was able to get dwelche's blinker01 example to work fine; thanks yet again Old Timer!

I headed over to the reference manual to trace through how that code works, and it's easy enough to follow.

  • 1) Enabling Port C using bit 4 on the RCC_APB2ENR register
  • 2) Set bits 21 and 20 of the GPIO_c_CRH to 01 (output max 10Mhz)
  • 2.1) GPIO_c_CRH is 0x4001 1000 GPIO Port C + 0x04 offset
  • 3) Sets bits 23 and 22 to 00 for push-pull output
  • 4) ...you get the point

The trouble I am having is probably a super simple thing from lack of experience:

I could not find out why port C is the one that's enabled? The Pin is called PC13, and there are other pins: PA3 or PB15. Would I then enable Ports A and B for those pins?

Why then are there A through G? I also had trouble figuring out the Alternate Functions for this MCU. My experience with AF's is only from the Raspberry Pi.


2 Answers 2


For the STM32, the common abbreviations are PXDD - Port X Pin DD.

So yes, for PA3, you'd enable Port A, for PB15 Port B.

There are Port A to Z depending on how many GPIOs the biggest device of the family has. Each port supports up to 16 pins. So for 160 GPIOs you need 10 ports (for example).

There are some pins which are linked to a certain port as it seems, because you might encounter port H on a device which only has 24 GPIOs available.

The alternate function mapping is in the pin description of the datasheet of the specific device you are using and cannot be found in the reference manual.

I have four documents I regularly use while developing:

  1. Reference manual
  2. Datasheet
  3. Programmers manual (contains core peripheral description)
  4. Errata (because you might encounter a hardware bug)

The order is actually the order of importance for me.

Just realized you are using a F10x device.

The STM32F1xx family is the oldest one and sadly not the most descriptive one. They have improved especially in the part of the alternate function mapping, as it is quite hard to tell what the pin is actually doing on a F1xx if you enable multiple peripherals using the same pin.

For this family you have the datasheet which tells you which pin can do what. And in the reference manual, you have the description of the AFIO_MAPR which allows you to remap certain functions to other pins.


As you correctly noticed the port identifier in the pin name PC13 states that this pin belongs to the IO bank C. So pin PA3 would belong to IO bank A whereas PB15 belongs to IO bank B. Having the pins devided into separate IO banks offers some flexibility with IO handling, as you can deactivate whole banks or read/write a whole bank.

Regarding the Alternate Functions, you can usually get a first overview from the datasheet, in your case STM32F10x Datasheet.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.