Pin remapping problem

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
kab
Posts: 70
Joined: Sun Sep 16, 2012 6:18 pm

Pin remapping problem

Post 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!
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Pin remapping problem

Post 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
kab
Posts: 70
Joined: Sun Sep 16, 2012 6:18 pm

Re: Pin remapping problem

Post 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
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Pin remapping problem

Post by Giovanni »

Not sure, it would be a good idea to ask also on the ST STM32 forum.

Giovanni
kab
Posts: 70
Joined: Sun Sep 16, 2012 6:18 pm

Re: Pin remapping problem

Post 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?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Pin remapping problem

Post by Giovanni »

The RM states that AFIO_MAPR_SWJ_CFG reads back always as zero, you should use |= and &= carefully.

Giovanni
kab
Posts: 70
Joined: Sun Sep 16, 2012 6:18 pm

Re: Pin remapping problem

Post by kab »

Thanks for advice!

Now all working and i keep code as it is and do not touch. :-)
Post Reply