Skip to content

Commit a0d4fdc

Browse files
projectgusdpgeorge
authored andcommitted
stm32/pyb_can: Fix STM32G4 FDCAN source clock frequency.
Fixes automatic baudrate calculation results. Default clock source on this SoC is HSE not PCLK1. We could fix this by switching to PCLK1 instead, but two extra complications: - PCLK1 on this board is a 42.5MHz and the Pyboard CAN sample_point calculation requires an exact match, which is harder to hit with this source frequency. - Would be a breaking change for any existing Python code on this board, i.e. specifying brp, bs1, bs2 to initialise CAN. In the future it might be worth looking switching to the PLL source on this SoC instead, as this is a much higher frequency that would give higher quality BRS bitrate matches (probably too high without using the second divider going into the CAN peripheral though, so more code changes needed also). This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
1 parent 47ae739 commit a0d4fdc

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

ports/stm32/pyb_can.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,10 @@ static uint32_t pyb_can_get_source_freq() {
182182
break;
183183
}
184184
}
185-
#else // F4 and F7 and assume other MCUs too.
185+
#elif defined(STM32G4)
186+
// STM32G4 CAN clock from reset is HSE, unchanged by MicroPython
187+
can_kern_clk = HSE_VALUE;
188+
#else // G0, F4, F7 and assume other MCUs too.
186189
// CAN1/CAN2/CAN3 on APB1 use GetPCLK1Freq, alternatively use the following:
187190
// can_kern_clk = ((HSE_VALUE / osc_config.PLL.PLLM ) * osc_config.PLL.PLLN) /
188191
// (osc_config.PLL.PLLQ * clk_init.AHBCLKDivider * clk_init.APB1CLKDivider);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy