From 407c368c20ec81c6c2ed3ce54a6790e330e41a1b Mon Sep 17 00:00:00 2001 From: Bartosz Szczepanski Date: Thu, 12 May 2016 13:11:44 +0200 Subject: [PATCH 1/2] [STM32F4] Get PCLK1 clock and set initial CAN frequency CAN bus opperates on APB1 peripheral clock due to that we need to get PCLK1 freq in *can_frequency()* function to properly calculate CAN speed and reconfigure BS1, BS2, SJW bits. Also to fully communicate with other ST platform we set the initical CAN frequency to 100kb/s to be able to work with the slowest platform which supports CAN, which is NUCLEO_F303K8 (APB1 is 32MHz). Change-Id: I10af3aa8d715dd61c9d1b216ef813193449fecbd --- .../mbed/targets/hal/TARGET_STM/TARGET_STM32F4/can_api.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/can_api.c b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/can_api.c index 2539af020f7..beb356d093b 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/can_api.c +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/can_api.c @@ -75,6 +75,9 @@ void can_init(can_t *obj, PinName rd, PinName td) filter_number = (obj->can == CAN_1) ? 0 : 14; + // Set initial CAN frequency to 100kb/s + can_frequency(obj, 100000); + can_filter(obj, 0, 0, CANStandard, filter_number); } @@ -177,7 +180,7 @@ static unsigned int can_speed(unsigned int pclk, unsigned int cclk, unsigned cha int can_frequency(can_t *obj, int f) { - int pclk ; //= PeripheralClock; + int pclk = HAL_RCC_GetPCLK1Freq(); int btr = can_speed(pclk, (unsigned int)f, 1); CAN_TypeDef *can = (CAN_TypeDef *)(obj->can); From 08a71bceed60ca8b206f4603e74a11d5ac8f7c54 Mon Sep 17 00:00:00 2001 From: Bartosz Szczepanski Date: Fri, 13 May 2016 08:36:08 +0200 Subject: [PATCH 2/2] [STM32F4] Fix for CAN2 interrupt index CAN2 interrupt index was wrong leading to not properly registering interrupt. Having this fix allow us to pass MBED_30 test. Change-Id: I33f9ca7c81286f7746a8f8352619e213bdf9756a --- libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/can_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/can_api.c b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/can_api.c index beb356d093b..446b4fdfbbe 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/can_api.c +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/can_api.c @@ -42,7 +42,7 @@ void can_init(can_t *obj, PinName rd, PinName td) obj->index = 0; } else { __HAL_RCC_CAN2_CLK_ENABLE(); - obj->index = 0; + obj->index = 1; } // Configure the CAN pins