Skip to content

Precharge/Contactor Drivers#5

Open
GavinW-UT wants to merge 7 commits intomainfrom
Precharge
Open

Precharge/Contactor Drivers#5
GavinW-UT wants to merge 7 commits intomainfrom
Precharge

Conversation

@GavinW-UT
Copy link

@GavinW-UT GavinW-UT commented Jan 26, 2026

No description provided.

…rote the read function and outlined precharge logic
@gemini-code-assist
Copy link

Summary of Changes

Hello @GavinW-UT, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request establishes the initial firmware structure for an STM32G4xx microcontroller. It configures the system clock and essential peripherals such as ADCs, UART, and GPIOs. The changes lay the groundwork for critical functionalities, including the acquisition of motor and battery voltage data and the preliminary logic for a battery precharge sequence, which is vital for safe power-up in high-voltage systems.

Highlights

  • Initial STM32G4xx Firmware Setup: The pull request introduces the foundational firmware for an STM32G4xx microcontroller, including comprehensive clock configuration and initialization of essential peripherals like GPIO, ADCs, and UART.
  • ADC Voltage Reading Implementation: Functions for reading motor and battery voltages via two Analog-to-Digital Converters (ADC1 and ADC2) have been implemented, converting raw ADC values into floating-point voltage measurements.
  • Precharge Logic Outline: Preliminary precharge logic has been outlined, incorporating voltage monitoring, overvoltage detection, and control signals for precharge and main contactors based on voltage ratios and thresholds.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces the initial firmware structure, including clock and ADC configuration, an ADC reading function, and precharge logic. The changes are a good start, but there are several critical issues that need to be addressed, including an incorrect file include, syntax errors, macros with trailing semicolons, and a potential division-by-zero error in the precharge logic. There is also a high-severity issue with an unhandled overvoltage condition. I've provided suggestions to fix these critical bugs and improve the code's robustness and safety. Additionally, there are some medium-severity suggestions for future performance improvements.

Copy link
Contributor

@Rav4s Rav4s left a comment

Choose a reason for hiding this comment

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

Good start, I left some comments. I think the main thing is to start compartmentalizing stuff into driver files (don't put all this in main) and write tests for each of those drivers. Also make sure to use the BSP ADC instead of the low-level HAL functions. and get all pins defined before continuing to hardcode stuff

@Rav4s Rav4s self-requested a review February 1, 2026 22:13
@Rav4s Rav4s changed the title First few bits of firmware, copy pasted the ADC and clock stuff and w… Precharge/Contactor Drivers Feb 2, 2026
Copy link
Contributor

@Rav4s Rav4s left a comment

Choose a reason for hiding this comment

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

Check the build output on github when you commit, the code doesn't compile for various reasons. You should be compiling and testing locally before pushing.

I don't see a test for precharge ADC reading, can you add a test that just samples the ADCs and prints the raw value + converted voltages?

Good work addressing the previous comments, I added some more :P

Copy link
Contributor

Choose a reason for hiding this comment

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

you should get the contactor functions written as well, work with @CraigGleason7 on this, i think he has most of that stuff done already for BPS Leader

…t is prob some garbage, how makefile so i can build and fix errors
@Rav4s Rav4s self-requested a review February 6, 2026 06:16
Copy link
Contributor

@Rav4s Rav4s left a comment

Choose a reason for hiding this comment

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

nice job, this is a huge improvement already! left a few more comments, let's start getting the test fleshed out so you can test on hardware soon

Copy link
Contributor

Choose a reason for hiding this comment

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

you need to have a main for anything to execute in a test file. add your init functions for VCU to initialize clock, pins, adcs, leds, anything else you need. cubemx can generate most of these, just copy and paste what you need. also pls build this and test on LSOM once embedded-sharepoint adc is updated

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