Page 1 of 1
Pin remapping problem
Posted: Tue Apr 29, 2014 8:24 pm
by kab
hi!
I try to find why i cannot remap pin PA15 but i miss something important.
I'm using my custom board based on stm32 f103c8t6. Code is following:
Code: Select all
main() {
halInit();
chSysInit();
// disable JTAG, free PA15 pin
AFIO->MAPR &= 0xF0FFFFFF;
AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_NOJNTRST;
AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_JTAGDISABLE;
chThdSleepMilliseconds(100);
palSetPadMode(IOPORT1, 15, PAL_MODE_OUTPUT_PUSHPULL);
palClearPad(IOPORT1, 15);
chThdSleepMilliseconds(100);
palSetPad(IOPORT1, 15);
...
And nothing happen, state on PA15 did not changed. What i miss?
Thanks!
Re: Pin remapping problem
Posted: Tue Apr 29, 2014 8:41 pm
by Giovanni
Not sure, you should examine the state of the GPIO and AFIO registers.
Is the pin unconnected externally? are you sure you need to modify AFIO? probably you just need to change the pin mode.
Giovanni
Re: Pin remapping problem
Posted: Tue Apr 29, 2014 9:01 pm
by kab
hi!
Yep, pin is disconnected.
I've check, AFIO->MAPR = 0.
Why this can happen?
Code: Select all
AFIO->MAPR: 0x0
GPIOA->CRL: 0x88888888
GPIOA->CRH: 0x38888888
Re: Pin remapping problem
Posted: Tue Apr 29, 2014 9:04 pm
by Giovanni
Not sure, it would be a good idea to ask also on the ST STM32 forum.
Giovanni
Re: Pin remapping problem
Posted: Wed Apr 30, 2014 11:51 am
by kab
Strange, when i clone and use this function from StdPeriphLib - remapping working:
Code: Select all
void GPIO_PinRemapConfig(uint32_t GPIO_Remap, FunctionalState NewState)
{
uint32_t tmp = 0x00, tmp1 = 0x00, tmpreg = 0x00, tmpmask = 0x00;
if((GPIO_Remap & 0x80000000) == 0x80000000)
{
tmpreg = AFIO->MAPR2;
}
else
{
tmpreg = AFIO->MAPR;
}
tmpmask = (GPIO_Remap & DBGAFR_POSITION_MASK) >> 0x10;
tmp = GPIO_Remap & LSB_MASK;
if ((GPIO_Remap & (DBGAFR_LOCATION_MASK | DBGAFR_NUMBITS_MASK)) == (DBGAFR_LOCATION_MASK | DBGAFR_NUMBITS_MASK))
{
tmpreg &= DBGAFR_SWJCFG_MASK;
AFIO->MAPR &= DBGAFR_SWJCFG_MASK;
}
else if ((GPIO_Remap & DBGAFR_NUMBITS_MASK) == DBGAFR_NUMBITS_MASK)
{
tmp1 = ((uint32_t)0x03) << tmpmask;
tmpreg &= ~tmp1;
tmpreg |= ~DBGAFR_SWJCFG_MASK;
}
else
{
tmpreg &= ~(tmp << ((GPIO_Remap >> 0x15)*0x10));
tmpreg |= ~DBGAFR_SWJCFG_MASK;
}
if (NewState != DISABLE)
{
tmpreg |= (tmp << ((GPIO_Remap >> 0x15)*0x10));
}
if((GPIO_Remap & 0x80000000) == 0x80000000)
{
AFIO->MAPR2 = tmpreg;
}
else
{
AFIO->MAPR = tmpreg;
}
}
Anyone have any clue why?
Re: Pin remapping problem
Posted: Wed Apr 30, 2014 11:56 am
by Giovanni
The RM states that AFIO_MAPR_SWJ_CFG reads back always as zero, you should use |= and &= carefully.
Giovanni
Re: Pin remapping problem
Posted: Wed Apr 30, 2014 12:49 pm
by kab
Thanks for advice!
Now all working and i keep code as it is and do not touch.
