STM32-P107: how to configure CAN

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

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
jeremie.delaitre
Posts: 26
Joined: Fri Oct 05, 2012 3:16 pm
Been thanked: 1 time

STM32-P107: how to configure CAN

Post by jeremie.delaitre »

Hi,

I'm new to ChibiOS and I'm trying to do some CAN experiments with an Olimex STM32-P107 board. While I have loopback mode working without problem, I struggling to remap the GPIOs I want to use as CAN1.

I want CAN1_RX on PD0 and CAN1_TX on PD1. Thus I have defined VAL_GPIODCRL to 0x38B888B8 in the P107's board.h. Moreover, I added AFIO_MAPR_CAN_REMAP_REMAP3 in the boardInit() function (in board.c).

Is this correct? Do I need something more to have CAN1 usable?

As a side note, I noticed in the todo.txt file that support for the STM32 CAN2 is planned for a 2.5.x release. This is great :)
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32-P107: how to configure CAN

Post by Giovanni »

Hi,

That should be sufficient, did you remove CAN_BTR_LBKM from the CAN configuration?

Giovanni
jeremie.delaitre
Posts: 26
Joined: Fri Oct 05, 2012 3:16 pm
Been thanked: 1 time

Re: STM32-P107: how to configure CAN

Post by jeremie.delaitre »

Yes...
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32-P107: how to configure CAN

Post by Giovanni »

How do you verify if it works? oscilloscope?

Giovanni
jeremie.delaitre
Posts: 26
Joined: Fri Oct 05, 2012 3:16 pm
Been thanked: 1 time

Re: STM32-P107: how to configure CAN

Post by jeremie.delaitre »

Just to be complete, here is what I've done so far.

I'm trying to port the ChibiOS/testhal/STM32F1xx/CAN code to the STM32-P107 board. To do that, I've mostly done 3 things:

1- I've configured the CAN1 TX/RX pins on PD1/PD0 by defining VAL_GPIODCRL to 0x38B888B8 in the P107's board.h and by adding AFIO_MAPR_CAN_REMAP_REMAP3 in the board.c's boardInit() function.
2- I've fixed a bug in the STM32F10X_CL interrupt number definitions (see http://sourceforge.net/tracker/?func=de ... tid=995489 for the bug report and patch).
3- I've fixed compilation problems due to unknown macros in mcuconf.h. Thus, I've replaced the original HAL driver settings (from the example) by:

Code: Select all

#define STM32_NO_INIT                       FALSE
#define STM32_HSI_ENABLED                   TRUE
#define STM32_LSI_ENABLED                   FALSE
#define STM32_HSE_ENABLED                   TRUE
#define STM32_LSE_ENABLED                   FALSE
#define STM32_SW                            STM32_SW_PLL
#define STM32_PLLSRC                        STM32_PLLSRC_PREDIV1
#define STM32_PREDIV1SRC                    STM32_PREDIV1SRC_PLL2
#define STM32_PREDIV1_VALUE                 5
#define STM32_PLLMUL_VALUE                  9
#define STM32_PREDIV2_VALUE                 5
#define STM32_PLL2MUL_VALUE                 8
#define STM32_PLL3MUL_VALUE                 10
#define STM32_HPRE                          STM32_HPRE_DIV1
#define STM32_PPRE1                         STM32_PPRE1_DIV2
#define STM32_PPRE2                         STM32_PPRE2_DIV2
#define STM32_ADCPRE                        STM32_ADCPRE_DIV4
#define STM32_OTG_CLOCK_REQUIRED            TRUE
#define STM32_OTGFSPRE                      STM32_OTGFSPRE_DIV3
#define STM32_I2S_CLOCK_REQUIRED            FALSE
#define STM32_MCOSEL                        STM32_MCOSEL_PLL3
#define STM32_RTCSEL                        STM32_RTCSEL_HSEDIV
#define STM32_PVD_ENABLE                    FALSE
#define STM32_PLS                           STM32_PLS_LEV0


The thing is I don't really know if these HAL settings are correct (I've copy-pasted from a P107 example). Those are a little bit out of my understanding at the moment... Could it be the source of my problem?

I've tried to debug with an oscilloscope to see what happen. To do that, I saw on the Internet that a resistor is needed between the TX and RX pins. So I've added a resistor and the oscilloscope seems to display a correct signal.

However, when I connect a CAN driver/transceiver (this one: http://www.skpang.co.uk/catalog/canbus- ... p-754.html), there is nothing on CAN_H and CAN_L...

Furthermore, I noticed that the tx interrupt handler is never called (I tried to increment a volatile int from there) which seems to corroborate the fact that only 3 frames are queued by canTransmit() when I don't use CAN_MCR_NART in the CANConfig, the following ones resulting in a timeout.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32-P107: how to configure CAN

Post by Giovanni »

About HAL settings, always use a halconf.h from a demo with the same MCU, some settings are different among STM32 sub-families.

It looks like an HW problem to me, are you sure the transceiver id connected correctly and powered? I am looking at the schematic of the Olimex STM32-P103 board and I don't see any resistor between TX and RX, you could use that schematic as example.

Giovanni
jeremie.delaitre
Posts: 26
Joined: Fri Oct 05, 2012 3:16 pm
Been thanked: 1 time

Re: STM32-P107: how to configure CAN

Post by jeremie.delaitre »

The resistor was used to see the TX signal with an oscilloscope when no transceiver was connected. Now that I've connected a transceiver, I've removed the resistor.
Post Reply