From 581cd809431de1c501b81461582bd76ebb99a684 Mon Sep 17 00:00:00 2001 From: chdelfs <109847651+chdelfs@users.noreply.github.com> Date: Thu, 4 Aug 2022 18:48:22 +0200 Subject: [PATCH 1/2] Fix for calculating CAN timing settings. NominalPrescaler value needs to be as high as possible to ensure a good approximation of the target CAN speed. Previous usage of macro IS_FDCAN_DATA_TSEG1 refers to (unsupported by Mbed ) FDCAN CAN controller settings and leads to too low prescaler values. Usage Macro IS_FDCAN_NOMINAL_TSEG1 yields optimum results. See also correct macro usage in line #158. --- targets/TARGET_STM/can_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/targets/TARGET_STM/can_api.c b/targets/TARGET_STM/can_api.c index a2f34a96df7..abf7c608380 100644 --- a/targets/TARGET_STM/can_api.c +++ b/targets/TARGET_STM/can_api.c @@ -335,7 +335,7 @@ int can_frequency(can_t *obj, int f) // !When the sample point should be lower than 50%, this must be changed to // !IS_FDCAN_DATA_TSEG2(ntq/nominalPrescaler), since // NTSEG2 and SJW max values are lower. For now the sample point is fix @75% - while (!IS_FDCAN_DATA_TSEG1(ntq / nominalPrescaler)) { + while (!IS_FDCAN_NOMINAL_TSEG1(ntq / nominalPrescaler)) { nominalPrescaler ++; if (!IS_FDCAN_NOMINAL_PRESCALER(nominalPrescaler)) { error("Could not determine good nominalPrescaler. Bad clock value\n"); From 9cd4854cb84b755dbe932076931cbc2583750f6b Mon Sep 17 00:00:00 2001 From: chdelfs <109847651+chdelfs@users.noreply.github.com> Date: Wed, 12 Oct 2022 17:16:59 +0200 Subject: [PATCH 2/2] Update can_api.c Modified comment as discussed. --- targets/TARGET_STM/can_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/targets/TARGET_STM/can_api.c b/targets/TARGET_STM/can_api.c index abf7c608380..f3c27aae133 100644 --- a/targets/TARGET_STM/can_api.c +++ b/targets/TARGET_STM/can_api.c @@ -333,7 +333,7 @@ int can_frequency(can_t *obj, int f) uint32_t nominalPrescaler = 1; // !When the sample point should be lower than 50%, this must be changed to - // !IS_FDCAN_DATA_TSEG2(ntq/nominalPrescaler), since + // !IS_FDCAN_NOMINAL_TSEG2(ntq/nominalPrescaler), since // NTSEG2 and SJW max values are lower. For now the sample point is fix @75% while (!IS_FDCAN_NOMINAL_TSEG1(ntq / nominalPrescaler)) { nominalPrescaler ++;