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

Changes for issues with compiling with optimisation #484

Merged

Conversation

AndrewCapon
Copy link
Contributor

There are issues with the HAL usb files: stm32h7xx_ll_usb.h and stm32h7xx_ll_usb.cpp where there can be timing issues due to code being optimised out.

See: https://community.st.com/s/question/0D50X0000BWpRO7SQN/stm32h7-usb-driver-fails-highest-optimization-o3

The solution from that link was to set any io memory locations to _IO and make the delay count variables volatile. I have done this for these files.

@stephenhensley
Copy link
Collaborator

@AndrewCapon thanks for the report, and quick fix!!

I think it looks OK to me.


To clarify a bit, when using the default linker, and running everything from the internal flash the USB works properly even with -O3 set?

Does the failure occur with either USB port, or just one (built-in, or external).

If that's the case, it's interesting that it only becomes an issue when the firmware is executing from SRAM. Are you using the bootloader in core/, and one of the other included linker scrips, or do you have some sort of custom set up running?

I ask because we have seen one other existing issue with that bootloader that we've yet to identify/resolve where one of the external USB pins doesn't function properly after exiting the bootloader.

@AndrewCapon
Copy link
Contributor Author

AndrewCapon commented Feb 17, 2022

It is easier to hit the problem when running from SRAM with the clock at 480 but you could also hit it running from flash depending on how long the register writes take to hold in the underlying usb.

The issue in the reset is that it is checking a bit to see when the reset has occurred, without the loop initial check the initial bit read may be an old version and already at 0 so it exits the loop before it has transitioned to 1 and then back to 0.

So I think that first comparison is enough to get that initial state change it then needs to check for the correct state change!

I had had the odd issue before running from flash, but it was easy to get it in a state in sram where it would repeatedly fail and only work occasionally, some times then for multiple times!

It will be the same with both PHYs.

It might well fix the boot loader issue, they put those loops in for a reason :)

I'm just using a modified linker script at the moment and putting the vector table in flash and the code in ram.

@AndrewCapon
Copy link
Contributor Author

p.s. Has anyone been working on the USB Audio, I worked on some code a few years ago for an stm32f7 that had Composite audio and midi. I may be able to dig that out...

@stephenhensley
Copy link
Collaborator

@AndrewCapon thanks for the clarification!

We'll take a quick look and see if we can repro/validate the fix, but everything looks okay to me.

USB Audio is planned, but there's been no action on it so far. Same with composite devices (which we're hoping to get working before adding too many more device classes since you already have to pick/choose for CDC vs MIDI).

If either or both of those are something you'd be interested in contributing we then that would be very welcome!

@stephenhensley
Copy link
Collaborator

Totally forgot that this was good to go.

Thanks again for the contribution!! 🚀

@stephenhensley stephenhensley merged commit cad55ea into electro-smith:master Apr 29, 2022
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.

2 participants