Page 1 of 1

STM32F107VC CAN bus pin remap

Posted: Wed Jun 20, 2012 10:52 pm
by venkat09
hi.

i am using the STM32F107VC board from IAR i have some example code for CAN but in my Board they used the PD0 and PD1 for CAN i dont know how to remap it in my code. i have 2 board and i want to sent data between 2 boards.

void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;

// GPIO_PinRemapConfig(GPIO_Remap2_CAN1 , ENABLE);
/* Configure CAN pin: RX */
//GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_CAN_RX;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIO_CAN, &GPIO_InitStructure);

/* Configure CAN pin: TX */
//GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_CAN_TX;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIO_CAN, &GPIO_InitStructure);

GPIO_PinRemapConfig(GPIO_Remap_CAN , ENABLE);
}

can any one pls help me solve this problem..

thanks...

Re: STM32F107VC CAN bus pin remap

Posted: Thu Jun 21, 2012 7:17 am
by Giovanni
Is the AFIO clock enabled?

Giovanni

Re: STM32F107VC CAN bus pin remap

Posted: Thu Jun 21, 2012 10:19 am
by venkat09
yes i did like this...

/* Enable GPIOD and AFIO clocks for remapping */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOD, ENABLE);

/* Configure CAN1 RX pin */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOD, &GPIO_InitStructure);

/* Configure CAN1 TX pin */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);

/* Remap CAN1 GPIOs */
GPIO_PinRemapConfig(GPIO_Remap2_CAN1 , ENABLE); /* PD 0 and 1 */

/* CAN1 Periph clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);

/* CAN1 register init */
CAN_DeInit(CAN1);

Re: STM32F107VC CAN bus pin remap

Posted: Thu Jun 21, 2012 7:29 pm
by Giovanni
This forum is about ChibiOS support so I can only give some generic advice about problems related to ST library.

I am not a huge fan of ST library :-) probably you should ask about this in the ST forum, usually this kind of questions are quickly answered there.

Giovanni

Re: STM32F107VC CAN bus pin remap

Posted: Fri Apr 04, 2014 5:56 pm
by Akronoz
Hi, Im trying to use the chibios CANDriver, in loopbackmode all works ok, but how to do it for transmit outside MCU? in my case is PB9 and PB8 for CANTx and CANRx, how I can tell chibios that I use CAN in these pins? I read about remap and I find that in STM32f10x

#define AFIO_MAPR_CAN_REMAP_REMAP2 ((uint32_t)0x00004000) /*!< CANRX mapped to PB8, CANTX mapped to PB9 */

but I dont know if it is necesary with chibios. How can I use that define?

Thanks.

Re: STM32F107VC CAN bus pin remap

Posted: Fri Apr 04, 2014 6:00 pm
by Giovanni
Hi,

You have to write directly the AFIO register using that constant, see the Reference Manual, also verify if there are errata regarding CAN remapping.

Giovanni