Appendix A STM32CubeMX pin assignment rules ¶
The following pin assignment rules are implemented in STM32CubeMX:
Rule 1: Block consistency
Rule 2: Block inter-dependency
Rule 3: One block = one peripheral mode
Rule 4: Block remapping (only for STM32F10x)
Rule 5: Function remapping
Rule 6: Block shifting (only for STM32F10x)
Rule 7: Setting or clearing a peripheral mode
Rule 8: Mapping a function individually (if Keep Current Placement is unchecked)
Rule 9: GPIO signals mapping
A.1 Block consistency ¶
When setting a pin signal (provided there is no ambiguity about the corresponding peripheral mode), all the pins/signals required for this mode are mapped and pins are shown in green (otherwise the configured pin is shown in orange).
When clearing a pin signal, all the pins/signals required for this mode are unmapped simultaneously and the pins turn back to gray.
Example of block mapping with an STM32F107x MCU ¶
If the user assigns I2C1_SMBA function to PB5, then STM32CubeMX configures pins and modes as follows:
I2C1_SCL and I2C1_SDA signals are mapped to the PB6 and PB7 pins, respectively (see Figure 728).
I2C1 peripheral mode is set to SMBus-Alert mode.
Figure 728. Block mapping
Example of block remapping with an STM32F107x MCU ¶
If the user assigns GPIO_Output to PB6, STM32CubeMX automatically disables I2C1 SMBus-Alert peripheral mode from the peripheral tree view and updates the other I2C1 pins (PB5 and PB7) as follows:
If they are unpinned, the pin configuration is reset (pin grayed out). • If they are pinned, the peripheral signal assigned to the pins is kept and the pins are highlighted in orange since they no longer match a peripheral mode (see Figure 729).
Figure 729. Block remapping
Figure 730. Block remapping - Example 1 ¶
A.2 Block inter-dependency ¶
On the Pinout view, the same signal can appear as an alternate function for multiple pins. However it can be mapped only once.
As a consequence, for STM32F1 MCUs, two blocks of pins cannot be selected simultaneously for the same peripheral mode: when a block/signal from a block is selected, the alternate blocks are cleared.
Example of block remapping of SPI in full-duplex master mode with an STM32F107x MCU ¶
If SPI1 full-duplex master mode is selected from the tree view, by default the corresponding SPI signals are assigned to PB3, PB4 and PB5 pins (see Figure 732).
If the user assigns to PA6 the SPI1_MISO function currently assigned to PB4,
STM32CubeMX clears the PB4 pin from the SPI1_MISO function, as well as all the other pins configured for this block, and moves the corresponding SPI1 functions to the relevant pins in the same block as the PB4 pin (see Figure 733).
(by pressing CTRL and clicking PB4 to show PA6 alternate function in blue, then drag and drop the signal to pin PA6)
Figure 732. Block inter-dependency - SPI signals assigned to PB3/4/5 ¶
Figure 733. Block inter-dependency - SPI1_MISO function assigned to PA6 ¶
A.3 One block = one peripheral mode ¶
When a block of pins is fully configured in the Pinout view (shown in green), the related peripheral mode is automatically set in the Peripherals tree.
Example of STM32F107x MCU ¶
Assigning the I2C1_SMBA function to PB5 automatically configures I2C1 peripheral in SMBus-Alert mode (see Peripheral tree in Figure 734).
Figure 734. One block = one peripheral mode - I2C1_SMBA function assigned to PB5
A.4 Block remapping (STM32F10x only) ¶
To configure a peripheral mode, STM32CubeMX selects a block of pins and assigns each mode signal to a pin in this block. In doing so, it looks for the first free block to which the mode can be mapped.
When setting a peripheral mode, if at least one pin in the default block is already used,
STM32CubeMX tries to find an alternate block. If none can be found, it either selects the
functions in a different sequence, or unchecks , and remaps all the blocks to find a solution.
Example ¶
STM32CubeMX remaps USART3 hardware-flow-control mode to the (PD8-PD9-PD11PD12) block, because PB14 of USART3 default block is already allocated to the SPI2_MISO function (see Figure 735).
A.5 Function remapping ¶
To configure a peripheral mode, STM32CubeMX assigns each signal of the mode to a pin. In doing so, it will look for the first free pin the signal can be mapped to.
Example using STM32F415x ¶
When configuring USART3 for the Synchronous mode, STM32CubeMX discovered that the default PB10 pin for USART3_TX signal was already used by SPI. It thus remapped it to PD8 (see Figure 736).
A.6 Block shifting (only for STM32F10x and when
“Keep Current Signals placement” is unchecked) ¶
If a block cannot be mapped and there are no free alternate solutions, STM32CubeMX tries to free the pins by remapping all the peripheral modes impacted by the shared pin.
Example ¶
With the Keep current signal placement enabled, if USART3 synchronous mode is set first, the Asynchronous default block (PB10-PB11) is mapped and Ethernet becomes unavailable (shown in red) (see Figure 737).
Unchecking allows STM32CubeMX shifting blocks around and freeing a block for the Ethernet MII mode. (see Figure 738).
A.7 Setting and clearing a peripheral mode ¶
The Peripherals panel and the Pinout view are linked: when a peripheral mode is set or cleared, the corresponding pin functions are set or cleared.
A.8 Mapping a function individually ¶
When STM32CubeMX needs a pin that has already been assigned manually to a function (no peripheral mode set), it can move this function to another pin, only if is unchecked and the function is not pinned (no pin icon).