Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port pmic driver and add scheduler for it #1

Closed
wants to merge 101 commits into from

Conversation

ocklin
Copy link
Contributor

@ocklin ocklin commented Feb 8, 2022

  • move watchdog pmic driver to inverter lib
  • make a template off it for easier test/mock
  • break out specific platform dependent SPI class
  • add a small scheduler class used to strobe watchdog
  • add a small test program targeting inverter board

Ignoring parameters with ID==0 when loading
Added division support to CAN tx
Update the c2000 inverter application to use the gate driver.
This involves turning on the gate drive PSU before initialising
the gate drivers for each phase. The fault state of the gate
drivers is reported to stdout every second.

Add a simple heartbeat LED toggle to the main loop to
compensate for the gate drive fault LED no longer being on (!)
as a way of determinig if the inverter is powered up.

Tests:
 - Run on the Tesla M3 inverter and verify it operates with the
   gate drive fault LED extinguished and not gate drive fault is
   reported.
davefiddes and others added 5 commits February 9, 2022 18:23
Prior to merging this repo into the parent c2000-inverter repo we move the contents into a sub-directory with the same name.

Follows the guide at https://medium.com/walkme-engineering/how-to-merge-a-git-submodule-into-its-main-repository-d83a215a319c
This moves the main STM32F1 inverter code into a platform
directory so it follows the style and layout of the C2000 port.

STM32 platform specific code remains in libopeninv.

Tests:
 - Build all variants of the CMake build process
 - Build FOC and SINE variants with STM32 Makefile
Copy link
Owner

@davefiddes davefiddes left a comment

Choose a reason for hiding this comment

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

Back merging into a PR isn't good practice and makes for confusing git history. Best to leave merges to me.

Also, it seems out of scope of the PR which is about the basic PMIC driver and test application. I would prefer the integration into the inverter proper comes in a new PR. This should make things a lot more straight forward to understand, debug and test.

@davefiddes
Copy link
Owner

I have been testing this code. It mostly seems to work. The return result from TeslaM3PowerWatchdog<PmicSpiDriver>::Init() is ignored in the test application. When I print this out it indicates Error::StateTransitionFail. Having dug into the failure it seems like the DEVSTAT register is reporting the TLF35584_DEVSTAT_STBYEN is set even though it was not requested during configuration. Is this a behaviour you see?

As above, I'd really like to see the remaining issues in this code fixed and the PR merged.

@ocklin
Copy link
Contributor Author

ocklin commented Feb 10, 2022

Back merging into a PR isn't good practice and makes for confusing git history. Best to leave merges to me.

Arhh, indeed should not have ended up there. Let me see if I can revert that.

@ocklin
Copy link
Contributor Author

ocklin commented Feb 10, 2022

Would you be able to rebase this PR to another branch? Only way I see to remove the back merge.

https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/configuring-pull-request-merges/configuring-commit-rebasing-for-pull-requests

@ocklin
Copy link
Contributor Author

ocklin commented Feb 10, 2022

Would you be able to rebase this PR to another branch? Only way I see to remove the back merge.
New branch is pmicport in my fork. Almost al comments addressed.

@davefiddes
Copy link
Owner

Yep. I'll put this PR on a separate branch for PMIC integration work. I've had it done to my PRs but not done it myself. Bear with me while I read the Github docs on how best to do this.

@davefiddes davefiddes changed the base branch from portable-cpp to pmic-integration February 10, 2022 18:16
@davefiddes
Copy link
Owner

I've created a pmic-integration branch that starts where your first changeset started. Once you update the PR with your fixes I can merge this PR onto that branch. When you've got the inverter going I'll merge the branch back to "portable-cpp" (my master/main).

@ocklin
Copy link
Contributor Author

ocklin commented Feb 10, 2022

I have been testing this code. It mostly seems to work. The return result from TeslaM3PowerWatchdog<PmicSpiDriver>::Init() is ignored in the test application. When I print this out it indicates Error::StateTransitionFail. Having dug into the failure it seems like the DEVSTAT register is reporting the TLF35584_DEVSTAT_STBYEN is set even though it was not requested during configuration. Is this a behaviour you see?

Yes. I see the same in debugging. Not sure if its a bug or a feature though.

printf() doesn't work for me. .text full. I would need to play with the ld scripts to accommodate. Probably due to too long path names in the debug info? Also on Mac the RTOS tools for printf seem broken.

As above, I'd really like to see the remaining issues in this code fixed and the PR merged.

Code issues addressed if I didn't miss any.

@davefiddes
Copy link
Owner

davefiddes commented Feb 10, 2022

Try this to fix the lack of space in .text. It adds another 8kB.
linker-script.txt

To fix the Standby LDO perhaps we should just enable it even though it's a deviation from the Tesla config? Function should definitely not return anything other than Error::Ok in the test app.

Shame about printf not working. The support in Linux/Windows isn't great compared to ARM semi-hosting but it does achieve working output.

@ocklin
Copy link
Contributor Author

ocklin commented Feb 11, 2022

To fix the Standby LDO perhaps we should just enable it even though it's a deviation from the Tesla config? Function should definitely not return anything other than Error::Ok in the test app.

Looked through Tesla logs again, also started reading the datasheet in more depth. But didn't find anything new. Thus I can state only what we already know: original SPI traffic is different. It is never reading DEVSTAT. Instead it reads and then explicitly resets bits of IF, MONSFx and SYSSF, probably in response to an INT.

I hope to get around to a bit of playing today. TGIF.

@davefiddes
Copy link
Owner

That rings a bell. When I wrote the original code a year ago I decided to go for a super basic driver as Damien and Johannes were looking for it quickly (I had no HW then). The state change verification process was where I chose to deviate. That may have been a false economy. :(

@ocklin
Copy link
Contributor Author

ocklin commented Feb 11, 2022

That rings a bell. When I wrote the original code a year ago I decided to go for a super basic driver as Damien and Johannes were looking for it quickly (I had no HW then). The state change verification process was where I chose to deviate. That may have been a false economy. :(

Normal engineering decision that we take 30 times per day. No worries, I will take that part. Still also need to verify if brute force reset of all registers is what is causing this and if it is even needed.

I would suggest to disable DEVSTAT verification now, file a bug. Better to have the code in the main branch, it is not a regression.

@davefiddes
Copy link
Owner

Agreed. Good to get your code landed.

davefiddes and others added 3 commits February 11, 2022 12:15
This change moves all of the STM32 specific parts of libopeninv into the platform/stm32f1 directory. This leaves the libopeninv directory in the top-level to contain only cross-platform code.

No code changes were required only build system updates.

Tests:
 - Build all CMake variants
 - Build FOC and SINE variants using the old stm32_sine
   Makefile
The C2000 inverter erroneously reported "Gate Drive PSU
OFF" when it was in fact turned on. The PSU was in the
desired state it was just the message.

Tests:
 - Run on the Tesla M3 inverter and verify the updated
   message is displayed when running the inverter
@ocklin
Copy link
Contributor Author

ocklin commented Feb 15, 2022

No idea what happend - I merged your last updates to my portable-cpp branch. Now it looks like this PR points back to my portable-cpp instead of my pmicdriver-branch.

@ocklin ocklin closed this Feb 15, 2022
@ocklin ocklin deleted the portable-cpp branch February 15, 2022 19:28
@ocklin ocklin restored the portable-cpp branch February 15, 2022 19:29
@ocklin ocklin deleted the portable-cpp branch February 15, 2022 19:33
@davefiddes
Copy link
Owner

The important thing to understand about github is that generally all of the merges on a project need to happen on github.com. Before a PR has been raised you can rebase or merge to your hearts content (I personally prefer rebase). Once a PR has been raised all you can/should do is push new commits. Merging is then something for the repo owner to deal with.

If you'd pushed the remaining commits on your "pmicport" branch I would have happily (and speedily) merged this PR.

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.

None yet

3 participants