cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 PD0 / PD1 - Cannot get them to remap as GPIO

john23
Associate II
Posted on August 14, 2013 at 18:11

Hello,

I am attempting to remap pins PD0 and PD1 as GPIO and whenever I try to change the pin state, it stays low. Am I setting something up wrong?

Init Code:

    GPIO_InitTypeDef  GPIO_InitStructure;

    /*GPIOD Output Initialization*/

    //Disable HSE

    RCC->CR &= 0xFEFF;

    //Drive source and destination enable signals

    //Enable the GPIOD peripheral

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);

    //Re-map PD0 and PD1 as GPIO pins

    GPIO_PinRemapConfig(GPIO_Remap_PD01, ENABLE);

    GPIO_InitStructure.GPIO_Pin          = GPIO_Pin_0   |

                                                                   GPIO_Pin_1;

    //Set the pin(s) to output mode, Push Pull

    GPIO_InitStructure.GPIO_Mode      = GPIO_Mode_AF_PP;

    //initialize the above settings

    GPIO_Init(GPIOD, &GPIO_InitStructure);

Code used for toggling:

        GPIOD->ODR &= ~(GPIO_Pin_0|GPIO_Pin_1);

        GPIOD->ODR   |=    (GPIO_Pin_0|GPIO_Pin_1);

Thanks in advanced!

#pd0-pd1-gpio-remap-stm32-f103
4 REPLIES 4
Posted on August 14, 2013 at 19:02

Am I setting something up wrong?

You want them as GPIOs, configure them as such

/* GPIOD Periph clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
/* Configure PD0 and PD1 in output pushpull mode */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOD, &GPIO_InitStructure);

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

I tried that but it didn't work. I guess the pins' default function is the high speed external oscillator. To access the GPIO, the reference manual said to remap the pins. Unfortunately I can't get that to work properly (Code posted above). Any ideas?

Posted on August 14, 2013 at 20:25

For a ReMap to work you'd need to enable the clock on the AFIO peripheral

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
john23
Associate II
Posted on August 14, 2013 at 20:37

Thanks! That was it!