Skip to content

Features/g4 can - #19

Open
jacobh460 wants to merge 9 commits into
mainfrom
features/G4-CAN
Open

jacobh460 wants to merge 9 commits into
mainfrom
features/G4-CAN

Conversation

@jacobh460

Copy link
Copy Markdown
Contributor

Adds G4 support to CAN library. Also moves board-specific things out of the fdcan_toad.c/.h files.

@jacobh460
jacobh460 requested a review from RobertJN64 November 1, 2026 01:43
Comment thread firmware/lib/fdcan/fdcan_toad.h Resolved
Comment thread firmware/lib/fdcan/fdcan_toad.h Resolved
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV4;
RCC_OscInitStruct.PLL.PLLN = 85;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are now using external OSC? is this intentional / do we want to do this on H7 as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is intentional; we have an 8MHz mems oscillator on the board

@jacobh460 jacobh460 Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

H7 also has 8MHz mems so we should use that as well, best to do it in a new PR for organization

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concur with second PR

HAL_RCCEx_CRSConfig(&pInit);

PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB;
PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting that this works on G4, while HSI48 had issues on H7...
(usb wouldn't work if we set the clock to HSI48 like we are doing here)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this have something to do with the fact that we have CRS disabled on the H7? HSI48 is not precise enough alone to be used for USB

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah that's almost certainly it - we could consider HSI48 + CRS on the H7 then?

Not sure what's actually better, but I assume the same thing is better for both. Anyhow, issue for future PRs.

RCC_OscInitStruct.PLL.PLLN = 60;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV4;
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have we checked that we are hitting max CPU clock with this config?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not, this hits 120MHz. Maximum frequency is 170MHz, is this really a big deal?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine w/ 120 MHz, just want to note down that we are reducing our max frequency on the G4 in this PR.

Presumably the original config with the 85 scaler was to get to 170?

@RobertJN64

Copy link
Copy Markdown
Contributor

FDCAN stuff seems solid, a few unused vars I think...

Clock stuff is probably fine b/c it is working, but I think we should check if we want to propagate some of the changes to the H7 - fine to defer to another PR if desired.

@RobertJN64 RobertJN64 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants