llawrence12
(Lane Lawrence)
November 6, 2020, 12:29am
1
Hello,
I am trying to use the USBMSD library to have an SD card connected via SPI to a NUCLEO-H743ZI2 come up on a PC as a storage device. I have gotten it to work half of the time, but the other half of the time on board reset, or when the USB for the MSD is plugged in I get a crash with the error message “Assertion Failed: ret == HAL_OK”. If I reset the board repeatedly it will eventually work, but I’ll need it to work every time because this can’t happen when it is deployed to customers. Any ideas as to why this may be happening? Also when this does go out to customers it will be using an STM32F767xI MCU instead, with a dedicated SPI flash chip, but until I get the NUCLEO-F767ZI this is the one I am testing with.
Thanks
JojoS
(Johannes Stratmann)
November 6, 2020, 1:38pm
2
the H743 board is not yet enabled for USBDevice. I have fixed some problem that exists with H7 and USB, but in addition also the clock configuration has to be changed. So in general Mbed USB will work with this board, it just takes some time for checking the PR.
ARMmbed:master
← JojoS62:PR-fix-H7-USB
opened 11:03PM - 16 Oct 20 UTC
Problem as descriibed in https://github.com/ARMmbed/mbed-os/issues/13641
USBD… evice was not working with STM32H7 targets.
in sleep mode, USB interrupts were disabled
and USB Device was not working. Sleep mode is default in Mbed-os
e.g. in a call to sleep_for()
<!--
For more information on the requirements for pull requests, please see [the contributing guidelines](https://os.mbed.com/docs/mbed-os/latest/contributing/workflow.html).
NOTE: Do not remove any of the template headings (even for optional sections) as this
template is automatically parsed.
-->
### Summary of changes
Disabling ULPI clock in sleep mode is required for H7 targets. Added conditional disabling when macro exists.
<!--
Please provide the following information:
Description of the the change (what is this fixing / adding / removing?).
Why the change is needed (if this is fixing a reported issue please summarize what
the issue is and add the reference. E.g. Fixes #17119).
NOTE: This section is automatically written to release notes for Feature and
Major releases and should contain enough details for a user.
-->
Fix is necessary to make USBDevice working on STM32H7 targets.
#### Impact of changes
<!--
If there are any implications for users taking this change then they must be
provided here. For Major PR types this field is MANDATORY.
NOTE: This section is automatically written to release notes for Feature and
Major releases and should contain enough details for a user.
-->
Tests were performed on STM32H743VI and Nucleo STM32H7A3ZIT6Q.
Targets without ULPI should not be affected. STM32F401 ompiled and tested positiv.
#### Migration actions required
<!--
This should only be applicable in Major PR types for which this field is MANDATORY.
NOTE: This section is automatically written to release notes for Feature and
Major releases and should contain enough details for a user.
-->
Targets with H7 MCU can be checked and USBDevice can be enabled
### Documentation
<!--
Please provide details of any document updates required, including links to any
related PRs against the docs repository.
If no document updates are required please specify 'None', this at least tells us
that this has been considered.
-->
not affected
----------------------------------------------------------------------------------------------------------------
### Pull request type
<!--
Please add only one X to one of the following types. Do not fill multiple types (split the pull request otherwise).
Please note this is not a GitHub task list, indenting the boxes or changing the format to add a '.' or '*' in front of them would change the meaning incorrectly.
-->
[x] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)
----------------------------------------------------------------------------------------------------------------
### Test results
<!--
Provide all the information required, listing all the testing performed. For new targets please attach full test results for all supported compilers.
-->
[] No Tests required for this change (E.g docs only update)
[] Covered by existing mbed-os tests (Greentea or Unittest)
[] Tests / results supplied as part of this PR
----------------------------------------------------------------------------------------------------------------
### Reviewers
<!--
Request additional reviewers with @username or @team
-->
----------------------------------------------------------------------------------------------------------------
targets.json needs an device_has USBDEVICE entry and for the clock check this:
ARMmbed:master
← JojoS62:PR-fix-H7-USB
That maybe an issue with the clock setting. There is an errata that the clock re… covery system is not working with HSI48, so I used PLL3Q for my custom board.
could you please use this init in SetSystemClock:
https://github.com/JojoS62/custom_targets/blob/bfd51a0af6535af534cd7af54393975d84187780/TARGET_STM/TARGET_STM32H7/TARGET_STM32H743xI/TARGET_DEVEBOX_H743VI/system_clock.c#L287-L304
The multiplier and dividers need to be adjusted for a 8 MHz xtal.
```
PeriphClkInitStruct.PLL3.PLL3M = 2; // 8 MHz / 2 = 4MHz
PeriphClkInitStruct.PLL3.PLL3N = 48; // * 48 = 192 MHz
PeriphClkInitStruct.PLL3.PLL3P = 2; // 192 / 2 = 96 MHz (unused)
PeriphClkInitStruct.PLL3.PLL3Q = 4; // 192 / 4 = 48 MHz (USB)
```
This setting maybe also necessary for the H743ZI2:
```
"config": {
"usb_speed": {
"help": "USE_USB_OTG_FS or USE_USB_OTG_HS or USE_USB_HS_IN_FS",
"value": "USE_USB_OTG_FS"
},
```