-
Notifications
You must be signed in to change notification settings - Fork 7k
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
usb_dc_stm32: Minor bugfixes #9412
Conversation
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.
Which board did you use to test it? Could you add support for this board?
drivers/usb/device/Kconfig
Outdated
@@ -95,4 +95,10 @@ config USB_DC_STM32_DISCONN_ENABLE | |||
Say Y if your board uses USB DISCONNECT pin to enable the | |||
pull-up resistor on USB DP. | |||
|
|||
config USB_DC_STM32_PA11_PA12_REMAP | |||
bool |
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.
"prompt" is missing.
drivers/usb/device/usb_dc_stm32.c
Outdated
if (LL_APB1_GRP2_IsEnabledClock(LL_APB1_GRP2_PERIPH_SYSCFG)) { | ||
LL_SYSCFG_EnablePinRemap(); | ||
} else { | ||
SYS_LOG_ERR("System Configuration Controller clock is " | ||
"disable. Unable to enable pin remapping." | ||
"disable. Unable to enable pin remapping.") |
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.
;
also is missing
Fixed the commits.
I'm developing on a custom STM32F042 board. My patch for the F042 is here but I basically just copied the F072 configs and haven't really checked for correctness. |
drivers/usb/device/Kconfig
Outdated
@@ -95,4 +95,11 @@ config USB_DC_STM32_DISCONN_ENABLE | |||
Say Y if your board uses USB DISCONNECT pin to enable the | |||
pull-up resistor on USB DP. | |||
|
|||
config USB_DC_STM32_PA11_PA12_REMAP |
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 was thinking if this should be done in DT. We could add an optional property without value in the st,stm32-usb.yaml and add it to STM32F0 SoCs on QFN28 and TSSOP20 packages with USB controller. What do you think?
* */ | ||
for (i = 0; i < CONFIG_USB_NUM_BIDIR_ENDPOINTS; i++) { | ||
k_sem_init(&usb_dc_stm32_state.in_ep_state[i].write_sem, 1, 1); | ||
} |
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 agree that we should reset semaphores during a reset. Do we need to initialize them again? Did you try to reset them with k_sem_reset()
instead?
The comment also is confusing. Something like "Reset IN endpoints semaphores" sounds better to me.
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.
Agree k_sem_reset seems to be the right way, avoiding unbalanced sem after 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.
@atx , reason not to follow @loicpoulain & @ydamigos request?
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.
@erwango See my earlier comment
The semaphores have maximum permitted count of 1 and k_sem_give will therefore either set them to 1 or keep them at 1. Furthermore, it's unclear to me if k_sem_reset is ISR-safe as the documentation does not explicitly say so.
I have updated the branch. Not sure if moving the pin remap to the device tree is a win for now, as it requires a fixup file (such as the one in the olimexino_stm32). |
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.
Not sure if moving the pin remap to the device tree is a win for now, as it requires a fixup file (such as the one in the olimexino_stm32).
Pin remap is related to the SoC and not the board. It is better to add something like the following in stm32f0 fixup file:
#ifdef ST_STM32_USB_40005C00_ENABLE_PIN_REMAP
#define CONFIG_USB_ENABLE_PIN_REMAP ST_STM32_USB_40005C00_ENABLE_PIN_REMAP
#endif /* ST_STM32_USB_40005C00_ENABLE_PIN_REMAP */
dts/bindings/usb/st,stm32-usb.yaml
Outdated
type: boolean | ||
category: optional | ||
description: Some chips allow (or require) remapping the USB data pair to | ||
non-default pins. |
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.
Could you update the description with the reason we need this property:
For STM32F0 series SoCs on QFN28 and TSSOP20 packages enable PIN
pair PA11/12 mapped instead of PA9/10 (e.g. stm32f070x6)
74c11aa
to
baccfd8
Compare
Oh right, I haven't noticed that there are fixup files for individual SoCs as well. Updated the commits. |
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.
While we are waiting for @loicpoulain to check the PR, could you also fix the errors reported by shippable:
Commit 870f19c038:
1: UC5 Title exceeds max length (73>72): "drivers: usb_dc_stm32: Reinitialize the write semaphores on USB bus reset"
3: UC4 Line exceeds max length (79>72): "If the user attempts to send data before the USB connection is established (see"
4: UC4 Line exceeds max length (74>72): "the HID sample for an example of such code), the DataInCallback never gets"
Commit d29d76ae7c:
3: UC4 Line exceeds max length (81>72): "The SYSCFG_CFGR1_PA11_PA12_RMP define is present even on packages where the remap"
4: UC4 Line exceeds max length (75>72): "isn't strictly required. This commit makes the remap optional based on a DT"
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.
@atx Please resolve the conflicts.
@loicpoulain Could you also check it?
* */ | ||
for (i = 0; i < CONFIG_USB_NUM_BIDIR_ENDPOINTS; i++) { | ||
k_sem_init(&usb_dc_stm32_state.in_ep_state[i].write_sem, 1, 1); | ||
} |
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.
Agree k_sem_reset seems to be the right way, avoiding unbalanced sem after reset.
@ydamigos I have rebased on top of master |
Sorry but I don't see any k_sem_reset prior to the k_sem_give, have you push the new commit? |
Right, sorry, I misunderstood - you want to call both k_sem_reset and k_sem_give? I sort of figured that it would be redundant, as this is a binary semaphore. Is calling k_sem_reset in an ISR safe? The docs don't explicitly mention it. |
@loicpoulain , can you check if @atx answer is ok for you? |
@atx , can you rebase? |
@erwango Done |
ok it looks good. |
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 think you need the ifdef in the dts_fixup.h
soc/arm/st_stm32/stm32f0/dts_fixup.h
Outdated
@@ -60,6 +60,10 @@ | |||
#define CONFIG_USB_NUM_BIDIR_ENDPOINTS ST_STM32_USB_40005C00_NUM_BIDIR_ENDPOINTS | |||
#define CONFIG_USB_RAM_SIZE ST_STM32_USB_40005C00_RAM_SIZE | |||
|
|||
#ifdef ST_STM32_USB_40005C00_ENABLE_PIN_REMAP |
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.
Why do you need the ifdef here?
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.
#ifdefs don't do chain resolution right?
e. g.:
#define SOMETHING SOMETHINGELSE
#if defined(SOMETHING)
#error "Wat?"
#endif
So the define() check in the driver code would always succeed.
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.
@galak , are you good?
@atx Please create a gitHub "bug" issue, labeled as medium priority, so it can be properly tracked. You may also want to rebase the changes, as unfortunately there is new merge conflicts. |
@atx can you please rebase this PR? Thanks! |
The SYSCFG_CFGR1_PA11_PA12_RMP define is present even on packages where the remap isn't strictly required. This commit makes the remap optional based on a DT property. Also fixes syntax error caused by a missing );. Signed-off-by: Josef Gajdusek <[email protected]>
@aescolar @carlescufi Rebased and created issue #15443 Hopefully nothing is broken as I don't have time to test everything properly. |
All checks are passing now. Review history of this comment for details about previous failed status. |
If the user attempts to send data before the USB connection is established (see the HID sample for an example of such code), the DataInCallback never gets called which leaves the write semaphore in a taken state forever. Signed-off-by: Josef Gajdusek <[email protected]>
A few minor bugs I noticed when playing with an STM32F0 and the USB stack.
EDIT: Added missing S-o-b lines
Fixes #15443