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

usb_dc_stm32: Minor bugfixes #9412

Merged
merged 2 commits into from
Apr 17, 2019
Merged

Conversation

atx
Copy link
Contributor

@atx atx commented Aug 13, 2018

A few minor bugs I noticed when playing with an STM32F0 and the USB stack.

EDIT: Added missing S-o-b lines

Fixes #15443

@erwango erwango added area: USB Universal Serial Bus platform: STM32 ST Micro STM32 labels Aug 14, 2018
Copy link
Collaborator

@ydamigos ydamigos left a 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?

@@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

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

"prompt" is missing.

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.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

; also is missing

@atx
Copy link
Contributor Author

atx commented Aug 16, 2018

Fixed the commits.

Which board did you use to test it? Could you add support for this board?

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.

@@ -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
Copy link
Collaborator

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);
}
Copy link
Collaborator

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.

Copy link
Collaborator

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.

Copy link
Member

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?

Copy link
Contributor Author

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.

@atx
Copy link
Contributor Author

atx commented Aug 23, 2018

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).

Copy link
Collaborator

@ydamigos ydamigos left a 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 */

type: boolean
category: optional
description: Some chips allow (or require) remapping the USB data pair to
non-default pins.
Copy link
Collaborator

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)

@atx atx requested a review from erwango as a code owner August 25, 2018 10:33
@atx atx force-pushed the usb_dc_stm32 branch 2 times, most recently from 74c11aa to baccfd8 Compare August 25, 2018 10:37
@atx
Copy link
Contributor Author

atx commented Aug 25, 2018

Pin remap is related to the SoC and not the board. It is better to add something like the following in stm32f0 fixup file

Oh right, I haven't noticed that there are fixup files for individual SoCs as well.

Updated the commits.

Copy link
Collaborator

@ydamigos ydamigos left a 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"

@erwango erwango added priority: medium Medium impact/importance bug area: Debugging labels Aug 29, 2018
Copy link
Collaborator

@ydamigos ydamigos left a 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);
}
Copy link
Collaborator

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.

@atx
Copy link
Contributor Author

atx commented Sep 26, 2018

@ydamigos I have rebased on top of master
@loicpoulain Already done in the current version (altough I use k_sem_give as we need to set the semaphore to 1 on reset)

@loicpoulain
Copy link
Collaborator

loicpoulain commented Sep 27, 2018

@loicpoulain Already done in the current version (altough I use k_sem_give as we need to set the semaphore to 1 on reset)

Sorry but I don't see any k_sem_reset prior to the k_sem_give, have you push the new commit?

@atx
Copy link
Contributor Author

atx commented Sep 27, 2018

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.

@erwango
Copy link
Member

erwango commented Oct 8, 2018

@loicpoulain , can you check if @atx answer is ok for you?

@erwango
Copy link
Member

erwango commented Nov 8, 2018

@atx , can you rebase?

@atx
Copy link
Contributor Author

atx commented Nov 8, 2018

@erwango Done

@loicpoulain
Copy link
Collaborator

ok it looks good.

galak
galak previously requested changes Nov 8, 2018
Copy link
Collaborator

@galak galak left a 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

@@ -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
Copy link
Collaborator

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?

Copy link
Contributor Author

@atx atx Nov 8, 2018

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.

Copy link
Member

Choose a reason for hiding this comment

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

@galak , are you good?

@aescolar aescolar removed the priority: medium Medium impact/importance bug label Mar 30, 2019
@aescolar aescolar requested a review from galak March 30, 2019 11:32
@aescolar
Copy link
Member

aescolar commented Mar 30, 2019

@atx Please create a gitHub "bug" issue, labeled as medium priority, so it can be properly tracked.
After creating it, add a "Fixes: #XYZ" line in the PR body so it will be linked to the issue itself.
This PR was likely forgotten as there was no linked issue.
I remove the "priority: medium" label from here, as PRs priorities are not looked at by anybody following our current way of working.

You may also want to rebase the changes, as unfortunately there is new merge conflicts.

@carlescufi
Copy link
Member

@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]>
@atx
Copy link
Contributor Author

atx commented Apr 13, 2019

@aescolar @carlescufi Rebased and created issue #15443

Hopefully nothing is broken as I don't have time to test everything properly.

@zephyrbot
Copy link
Collaborator

zephyrbot commented Apr 13, 2019

All checks are passing now.

Review history of this comment for details about previous failed status.
Note that some checks might have not completed yet.

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]>
@galak galak added backport v1.14-branch bug The issue is a bug, or the PR is fixing a bug labels Apr 17, 2019
@galak galak merged commit f01a725 into zephyrproject-rtos:master Apr 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Debugging area: USB Universal Serial Bus bug The issue is a bug, or the PR is fixing a bug platform: STM32 ST Micro STM32
Projects
None yet
Development

Successfully merging this pull request may close these issues.

usb_dc_stm32: Missing semaphore initialization and missing pin remapping configuration
9 participants