STM32F107VC CAN bus pin remap

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
venkat09
Posts: 2
Joined: Wed Jun 20, 2012 10:41 pm

STM32F107VC CAN bus pin remap

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

Re: STM32F107VC CAN bus pin remap

Post by Giovanni »

Is the AFIO clock enabled?

Giovanni
venkat09
Posts: 2
Joined: Wed Jun 20, 2012 10:41 pm

Re: STM32F107VC CAN bus pin remap

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

Re: STM32F107VC CAN bus pin remap

Post 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
Akronoz
Posts: 10
Joined: Mon Mar 31, 2014 7:58 am

Re: STM32F107VC CAN bus pin remap

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

Re: STM32F107VC CAN bus pin remap

Post 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
Post Reply