From 6a3e343ec6bcb2667e91d9bce4bf052b9181a30c Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Mon, 16 Dec 2019 13:16:51 +0100 Subject: [PATCH 1/3] Fix for issue #12104 (STM32 can_init_freq() ignores frequency) --- targets/TARGET_STM/can_api.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/targets/TARGET_STM/can_api.c b/targets/TARGET_STM/can_api.c index c9888dc59c1..57e0f991a86 100644 --- a/targets/TARGET_STM/can_api.c +++ b/targets/TARGET_STM/can_api.c @@ -195,7 +195,7 @@ void can_init_freq(can_t *obj, PinName rd, PinName td, int hz) const can_pinmap_t static_pinmap = {peripheral, rd, function_rd, td, function_td}; - CAN_INIT_FREQ_DIRECT(obj, &static_pinmap, 100000); + CAN_INIT_FREQ_DIRECT(obj, &static_pinmap, hz); } @@ -692,7 +692,7 @@ void can_init_freq(can_t *obj, PinName rd, PinName td, int hz) const can_pinmap_t static_pinmap = {peripheral, rd, function_rd, td, function_td}; - CAN_INIT_FREQ_DIRECT(obj, &static_pinmap, 100000); + CAN_INIT_FREQ_DIRECT(obj, &static_pinmap, hz); } void can_irq_init(can_t *obj, can_irq_handler handler, uint32_t id) From e0e280aeaf686cb4d8be37801ba271abe4532cf7 Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Mon, 16 Dec 2019 14:09:54 +0100 Subject: [PATCH 2/3] optimize can_init(): call can_init_freq() with default freq --- targets/TARGET_STM/can_api.c | 39 ++++++++---------------------------- 1 file changed, 8 insertions(+), 31 deletions(-) diff --git a/targets/TARGET_STM/can_api.c b/targets/TARGET_STM/can_api.c index 57e0f991a86..0d28226a486 100644 --- a/targets/TARGET_STM/can_api.c +++ b/targets/TARGET_STM/can_api.c @@ -167,23 +167,6 @@ static void _can_init_direct(can_t *obj, const can_pinmap_t *pinmap) CAN_INIT_FREQ_DIRECT(obj, pinmap, 100000); } -void can_init(can_t *obj, PinName rd, PinName td) -{ - CANName can_rd = (CANName)pinmap_peripheral(rd, PinMap_CAN_RD); - CANName can_td = (CANName)pinmap_peripheral(td, PinMap_CAN_TD); - int peripheral = (int) pinmap_merge(can_rd, can_td); - - int function_rd = (int)pinmap_find_function(rd, PinMap_CAN_RD); - int function_td = (int)pinmap_find_function(td, PinMap_CAN_TD); - - const can_pinmap_t static_pinmap = {peripheral, rd, function_rd, td, function_td}; - - /* default frequency is 100 kHz */ - CAN_INIT_DIRECT(obj, &static_pinmap); -} - - - void can_init_freq(can_t *obj, PinName rd, PinName td, int hz) { CANName can_rd = (CANName)pinmap_peripheral(rd, PinMap_CAN_RD); @@ -198,6 +181,10 @@ void can_init_freq(can_t *obj, PinName rd, PinName td, int hz) CAN_INIT_FREQ_DIRECT(obj, &static_pinmap, hz); } +void can_init(can_t *obj, PinName rd, PinName td) +{ + can_init_freq(obj, rd, td, 100000); +} void can_irq_init(can_t *obj, can_irq_handler handler, uint32_t id) { @@ -666,7 +653,7 @@ static void _can_init_direct(can_t *obj, const can_pinmap_t *pinmap) CAN_INIT_FREQ_DIRECT(obj, pinmap, 100000); } -void can_init(can_t *obj, PinName rd, PinName td) +void can_init_freq(can_t *obj, PinName rd, PinName td, int hz) { CANName can_rd = (CANName)pinmap_peripheral(rd, PinMap_CAN_RD); CANName can_td = (CANName)pinmap_peripheral(td, PinMap_CAN_TD); @@ -677,22 +664,12 @@ void can_init(can_t *obj, PinName rd, PinName td) const can_pinmap_t static_pinmap = {peripheral, rd, function_rd, td, function_td}; - /* default frequency is 100 kHz */ - CAN_INIT_DIRECT(obj, &static_pinmap); + CAN_INIT_FREQ_DIRECT(obj, &static_pinmap, hz); } -void can_init_freq(can_t *obj, PinName rd, PinName td, int hz) +void can_init(can_t *obj, PinName rd, PinName td) { - CANName can_rd = (CANName)pinmap_peripheral(rd, PinMap_CAN_RD); - CANName can_td = (CANName)pinmap_peripheral(td, PinMap_CAN_TD); - int peripheral = (int) pinmap_merge(can_rd, can_td); - - int function_rd = (int)pinmap_find_function(rd, PinMap_CAN_RD); - int function_td = (int)pinmap_find_function(td, PinMap_CAN_TD); - - const can_pinmap_t static_pinmap = {peripheral, rd, function_rd, td, function_td}; - - CAN_INIT_FREQ_DIRECT(obj, &static_pinmap, hz); + can_init_freq(obj, rd, td, 100000); } void can_irq_init(can_t *obj, can_irq_handler handler, uint32_t id) From fffc30ffdade76035b1cd8d0c9a3aab905caa72a Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Wed, 18 Dec 2019 10:43:55 +0100 Subject: [PATCH 3/3] STM CAN: remove CAN_INIT_DIRECT macro --- targets/TARGET_STM/can_api.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/targets/TARGET_STM/can_api.c b/targets/TARGET_STM/can_api.c index 0d28226a486..4ee8b9e99d8 100644 --- a/targets/TARGET_STM/can_api.c +++ b/targets/TARGET_STM/can_api.c @@ -155,13 +155,7 @@ static void _can_init_freq_direct(can_t *obj, const can_pinmap_t *pinmap, int hz can_internal_init(obj); } -#if STATIC_PINMAP_READY -#define CAN_INIT_DIRECT can_init_direct void can_init_direct(can_t *obj, const can_pinmap_t *pinmap) -#else -#define CAN_INIT_DIRECT _can_init_direct -static void _can_init_direct(can_t *obj, const can_pinmap_t *pinmap) -#endif { /* default frequency is 100 kHz */ CAN_INIT_FREQ_DIRECT(obj, pinmap, 100000); @@ -641,13 +635,7 @@ static void _can_init_freq_direct(can_t *obj, const can_pinmap_t *pinmap, int hz can_filter(obj, 0, 0, CANStandard, filter_number); } -#if STATIC_PINMAP_READY -#define CAN_INIT_DIRECT can_init_direct void can_init_direct(can_t *obj, const can_pinmap_t *pinmap) -#else -#define CAN_INIT_DIRECT _can_init_direct -static void _can_init_direct(can_t *obj, const can_pinmap_t *pinmap) -#endif { /* default frequency is 100 kHz */ CAN_INIT_FREQ_DIRECT(obj, pinmap, 100000);