libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/pinmap.c
/**
 * Set the pin function (input, output, alternate function or analog) + output speed + AF
 */
Set the pin function (input, output, alternate function or analog) + output speed + AF
Set the pin function ( input output alternate function or analog ) + output speed + AF
void pin_function(PinName pin, int data) {
    if (pin == NC) return;
    uint32_t mode  = STM_PIN_MODE(data);
    uint32_t afnum = STM_PIN_AFNUM(data);
    uint32_t pin_number = (uint32_t)pin;
    uint32_t pin_index  = (pin_number & 0xF);
    uint32_t port_index = (pin_number >> 4);
    GPIO_TypeDef *gpio  = ((GPIO_TypeDef *)(GPIOA_BASE + (port_index << 10)));
    RCC_APB2PeriphClockCmd((uint32_t)(RCC_APB2Periph_GPIOA << port_index), ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
    GPIO_InitTypeDef GPIO_InitStructure;
    GPIO_InitStructure.GPIO_Pin   = (uint16_t)(1 << pin_index);
    GPIO_InitStructure.GPIO_Mode  = (GPIOMode_TypeDef)mode;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(gpio, &GPIO_InitStructure);
    if (afnum > 0) {
        GPIO_PinRemapConfig(AF_mapping[afnum], ENABLE);
    }
    if ((pin == PA_13) || (pin == PA_14)) {
        GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE);
    }
    if ((pin == PA_15) || (pin == PB_3) || (pin == PB_4)) {
        GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
    }    
}
void pin_function ( PinName pin , int data ) { if ( pin == NC ) return ; uint32_t mode = STM_PIN_MODE ( data ) ; uint32_t afnum = STM_PIN_AFNUM ( data ) ; uint32_t pin_number = ( uint32_t ) pin ; uint32_t pin_index = ( pin_number & 0xF ) ; uint32_t port_index = ( pin_number >> 4 ) ; GPIO_TypeDef * gpio = ( ( GPIO_TypeDef * ) ( GPIOA_BASE + ( port_index << 10 ) ) ) ; RCC_APB2PeriphClockCmd ( ( uint32_t ) ( RCC_APB2Periph_GPIOA << port_index ) , ENABLE ) ; RCC_APB2PeriphClockCmd ( RCC_APB2Periph_AFIO , ENABLE ) ; GPIO_InitTypeDef GPIO_InitStructure ; GPIO_InitStructure . GPIO_Pin = ( uint16_t ) ( 1 << pin_index ) ; GPIO_InitStructure . GPIO_Mode = ( GPIOMode_TypeDef ) mode ; GPIO_InitStructure . GPIO_Speed = GPIO_Speed_50MHz ; GPIO_Init ( gpio , & GPIO_InitStructure ) ; if ( afnum > 0 ) { GPIO_PinRemapConfig ( AF_mapping [ afnum ] , ENABLE ) ; } if ( ( pin == PA_13 ) || ( pin == PA_14 ) ) { GPIO_PinRemapConfig ( GPIO_Remap_SWJ_Disable , ENABLE ) ; } if ( ( pin == PA_15 ) || ( pin == PB_3 ) || ( pin == PB_4 ) ) { GPIO_PinRemapConfig ( GPIO_Remap_SWJ_JTAGDisable , ENABLE ) ; } }
Set the pin function (input, output, alternate function or analog) + output speed + AF
Set the pin function ( input output alternate function or analog ) + output speed + AF
// Get the pin mode and alternate-function number // Get GPIO structure base address // Enable GPIO and AFIO clocks // Configure GPIO // Configure Alternate Function // Disconnect JTAG-DP + SW-DP signals. // Warning: Need to reconnect under reset