-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Add basic EFM32HG support - CMU/GPIO/USB #874
Conversation
Please to make it easier to review this, use more appropriate commit line tags. Don't prefix common usb code changes with "efm32hg: " for instance. |
include/libopencm3/efm32/hg/gpio.h
Outdated
@@ -2,7 +2,6 @@ | |||
* This file is part of the libopencm3 project. | |||
* | |||
* Copyright (C) 2015 Kuldeep Singh Dhaka <kuldeepdhaka9@gmail.com> | |||
* Copyright (C) 2018 Seb Holzapfel <schnommus@gmail.com> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try and squish this sort of commit back out of existance, rather than introducing code early in a series and promptly deleting it. Just don't add it in the first place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing, I should have checked out the other PRs and noticed you were doing per-commit reviews rather than looking at all the changes at once. Cheers!
lib/usb/usb_efm32hg.c
Outdated
CMU_LFCLKSEL = (CMU_LFCLKSEL & ~CMU_LFCLKSEL_LFC_MASK) | CMU_LFCLKSEL_LFC_LFRCO; | ||
CMU_LFCCLKEN0 |= CMU_LFCCLKEN0_USBLE; | ||
|
||
// Calibrate USB based on communications |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't mix in c++ comments here. keep them all the same style
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was fixed by a later commit in the chain (and a good reason for me to clean the commit structure up as you suggested!)
lib/usb/usb_efm32hg.c
Outdated
USB_PCGCCTL &= ~(USB_PCGCCTL_PWRCLMP | USB_PCGCCTL_RSTPDWNMODULE); | ||
|
||
/* Core Soft Reset */ | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for these blocks here, we don't use this style at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'll make that change.
lib/usb/usb_efm32hg.c
Outdated
USB_GAHBCFG |= USB_GAHBCFG_GLBLINTRMSK; | ||
USB_GINTMSK = USB_GINTMSK_USBRSTMSK | | ||
USB_GINTMSK_ENUMDONEMSK | USB_GINTMSK_IEPINTMSK | USB_GINTMSK_OEPINTMSK | ||
/*| USB_GINTMSK_WKUPINTMSK*/; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drop the dead code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was fixed by a later commit in the chain (and another good reason for me to clean the commit structure up as you suggested!)
Thanks @karlp for the extremely rapid response! |
I haven't looked at this in any real depth yet, these were just some preliminary comments. I tend to look at both, the "whole set" and also each commit. Particularly for large changes like this, it's nice to look at both to see how things have developed. What would be super nice is if you could add a test for efm32 to the usb gadget zero tests. That would give a lot of assurance that it's working as well as other platforms. see the "tests" directory in the main repo |
Definitely, it would be nice to have a gadget-zero test. I'll work on adding one for EFM32HG (I don't have a dev board for EFM32LG as well unfortunately). I'll just tack it onto this PR if that's okay? The PR will grow a bit as I'll have to add a timer driver as well - but hopefully it's mostly the same as for EFM32LG. |
632dd77
to
7bdcb0e
Compare
Alright, @karlp - v2 of this PR has the following additions:
Since the USB OTG core driver was modified (so that it worked on CM0 platforms) I have run gadget0 tests on STM32F4 as well to gain some assurance it doesn't break things. It would be nice to make the EFM32LG USB implementation use this common |
…chips use DesignWare USB IP cores
… STM32 and EFM32 chips use the same dwc USB IP cores
7bdcb0e
to
aad71a3
Compare
Heya @karlp, v3 of this PR has the following changes (based on your feedback):
|
I've just ran the gadget0 tests on my efm32hg starter kit (BRD2012A) and it works flawlessly. I love it when people do that :) Just going to run it on a bunch of other boards now :) |
perf on f4 before: ie, the same. good :) |
Just FYI, I'm not going to pull in things like "usb-msc: fix write acknowledgement bug in msc driver from PR #409" in the first round. |
For the record, the efm32hg performance is |
#define GPIO_P_MODEL_MODE6(mode) GPIO_P_MODEL_MODEx(6, mode) | ||
|
||
#define GPIO_P_MODEL_MODE7_MASK GPIO_P_MODEL_MODEx_MASK(7) | ||
#define GPIO_P_MODEL_MODE7(mode) GPIO_P_MODEL_MODEx(7, mode) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thinkall of this is gross, no-one's ever going to use the GPIO_P_MODEL_MODE7_MASK macros individually, but whatever, I see this is just how the existing lg code was, so it's fine :)
#define CMU_HFPERCLKDIV_HFPERCLKDIV_DIV256 \ | ||
CMU_HFPERCLKDIV_HFPERCLKDIV_HFCLK256 | ||
#define CMU_HFPERCLKDIV_HFPERCLKDIV_DIV512 \ | ||
CMU_HFPERCLKDIV_HFPERCLKDIV_HFCLK512 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what on earth is this garbage?! I mean, ok, it will get grandfathered, but yuck!
* This file is part of the libopencm3 project. | ||
* | ||
* Copyright (C) 2015 Kuldeep Singh Dhaka <kuldeepdhaka9@gmail.com> | ||
* Copyright (C) 2018 Seb Holzapfel <schnommus@gmail.com> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nevermind, see it in the .h, was looking for .c)
Awesome, thanks @karlp for the rapid response (as usual!). |
this has all landed, but I'm about to push up another branch with all the WG/EZR32WG changes too, and I'd like to see about sharing the USB code there too. |
The open-hardware http://tomu.im/ project uses an EFM32HG, and the USB stack from libopencm3 works great on it. (disclaimer: I don't have any official role in the project, just having fun hacking at it)
The changes in this PR add basic EFM32HG support for CMU, GPIO, USB & WDOG, a lot copied from the existing EFM32LG support.
Main questions/concerns I have are:
lib/usb/usb_standard.c
but it might be worth reducing this to a compile-time check (as to whether we're running on a Cortex-M0).I have tested the GPIO, CMU and USB support extensively on hardware, using the examples in my fork here: https://github.com/schnommus/libopencm3-examples - at
examples/efm32/efm32hg/tomu-efm32hg309
Thanks!