How to create USB Host CDC
Re: How to create USB Host CDC
@neilh20 - Since you are working on USB Host CDC, is there any chance you are interested in Host MSC as well? This would be to allow the OTG Host to access the filesystem on a USB flash drive.
I'm interested in this because of the work I am doing on I2S (Inter-IC-Sound). Audio files tend to be large, and the internal flash filesystem on the pyboard (112kB) can store less than 1 second of audio at 16-bit 44.1kHz stereo (CD quality). For the pyboard, this isn't an issue, as a multi-GB SD card can store hours of audio; but the pyboard doesn't have a built-in I2S audio codec. While I have designed and built a daughterboard for that - http://forum.micropython.org/viewtopic.php?f=5&t=917 I don't expect that I'll be able to make it widely available in the very near future
The STM32F4-DISCOVERY board does have an I2S codec built in, and I would love to use that as an example of I2S usage. Unfortunately, the Discovery board doesn't have an SD card slot built in. All of ST's examples for using I2S on the Discovery board use the USB port in Host mode to connect to a USB flash drive (via an unconventional cable as well…) If MicroPython had the ability to support USB MSC in Host mode, that would provide at least one avenue for working with I2S audio in MicroPython on a widely available platform.
-Bryan
I'm interested in this because of the work I am doing on I2S (Inter-IC-Sound). Audio files tend to be large, and the internal flash filesystem on the pyboard (112kB) can store less than 1 second of audio at 16-bit 44.1kHz stereo (CD quality). For the pyboard, this isn't an issue, as a multi-GB SD card can store hours of audio; but the pyboard doesn't have a built-in I2S audio codec. While I have designed and built a daughterboard for that - http://forum.micropython.org/viewtopic.php?f=5&t=917 I don't expect that I'll be able to make it widely available in the very near future
The STM32F4-DISCOVERY board does have an I2S codec built in, and I would love to use that as an example of I2S usage. Unfortunately, the Discovery board doesn't have an SD card slot built in. All of ST's examples for using I2S on the Discovery board use the USB port in Host mode to connect to a USB flash drive (via an unconventional cable as well…) If MicroPython had the ability to support USB MSC in Host mode, that would provide at least one avenue for working with I2S audio in MicroPython on a widely available platform.
-Bryan
Re: How to create USB Host CDC
Hi Bryan, yes I expect that MSC will come out of it, and will be a real test of the speed of the interface.
CDC is perhaps the easiest to do/test and will verify the drivers/hw interface.
I've counted over 10 commercial vendors that supply a USB Host stack - however only limited support from manufacturers, and STMcube has some examples. However seems the stack examples are iffy on actual working, and trying to make a simple situation.
So I'm working through the details and if I can get the drivers/hardware to mesh will offer it up for further discussion - its a complex interface.
Neil.
CDC is perhaps the easiest to do/test and will verify the drivers/hw interface.
I've counted over 10 commercial vendors that supply a USB Host stack - however only limited support from manufacturers, and STMcube has some examples. However seems the stack examples are iffy on actual working, and trying to make a simple situation.
So I'm working through the details and if I can get the drivers/hardware to mesh will offer it up for further discussion - its a complex interface.
Neil.
Re: How to create USB Host CDC
I found an MP3 project online that I was able to compile on the Discovery board and read some thumb drives.
See: https://github.com/micropython/micropython/issues/212
See: https://github.com/micropython/micropython/issues/212
Re: How to create USB Host CDC
@neilh20 - That is very encouraging; I wouldn't feel up to trying to tackle it myself. I can say that I'll have an application for it whenever it is ready!
@dhylands - Thanks for the link, I had forgotten that discussion about getting USB Host mode up on the pyboard.
-Bryan
@dhylands - Thanks for the link, I had forgotten that discussion about getting USB Host mode up on the pyboard.
-Bryan
Re: How to create USB Host CDC
Some status: I've been using the STM32F4cubeMX examples for USB-Host.
I started off wiring a Nucleo-F401 ST-LINK to the pyboard
The structure of the CubeMX examples edited with SWstm32 openStem32.com (supported by AC6) is very fragile. Its an eclipse based virtual project (scarey with the what appears to be SwStm32 bugs I've tripped over). However to build a project it requires using the CubeMX examples (~1G) which includes 4 different tool chains including the SWstm32. I copy the examples to a known directory and prune off all the other tool chains, and example /boards I don't use to get it to ~330Mb disk space.
Its workable for a basic project example - but becomes a mess for trying to expand it and as I'm finding out the project dies in unexpected ways. openstem32 is soggy on usage and responses to questions.
I switched to a new STM32F429-disco which has a built in ST-Link, USB OTG. The demonstration program for the board is comprehensive including an LCD STEMwin, and includes a simple example of reading from a USB Host MSC Flash drive and displaying a picture on the LCD. A lot of code gets exercised. Though the demo has a few initialization bugs.
The other STM32F429-disco application USB-Host examples are minimal, and don't include any USB-OTG examples, which means trying other boards examples.
I finally got the USB Host CDC sending characters to a Sparkfun USB LCD, however something has broken the MSC Flash drive access. Then in re-arranging a file in the SWstm32 virtual project its messed something up and refuses to build - so trying to to get away from SWstm32 build environment, but have to figure out what broke the MSC flash drive.
I started off wiring a Nucleo-F401 ST-LINK to the pyboard
The structure of the CubeMX examples edited with SWstm32 openStem32.com (supported by AC6) is very fragile. Its an eclipse based virtual project (scarey with the what appears to be SwStm32 bugs I've tripped over). However to build a project it requires using the CubeMX examples (~1G) which includes 4 different tool chains including the SWstm32. I copy the examples to a known directory and prune off all the other tool chains, and example /boards I don't use to get it to ~330Mb disk space.
Its workable for a basic project example - but becomes a mess for trying to expand it and as I'm finding out the project dies in unexpected ways. openstem32 is soggy on usage and responses to questions.
I switched to a new STM32F429-disco which has a built in ST-Link, USB OTG. The demonstration program for the board is comprehensive including an LCD STEMwin, and includes a simple example of reading from a USB Host MSC Flash drive and displaying a picture on the LCD. A lot of code gets exercised. Though the demo has a few initialization bugs.
The other STM32F429-disco application USB-Host examples are minimal, and don't include any USB-OTG examples, which means trying other boards examples.
I finally got the USB Host CDC sending characters to a Sparkfun USB LCD, however something has broken the MSC Flash drive access. Then in re-arranging a file in the SWstm32 virtual project its messed something up and refuses to build - so trying to to get away from SWstm32 build environment, but have to figure out what broke the MSC flash drive.
Re: How to create USB Host CDC
There has been a discussion on another thread about using the USB HS interface on the 429 discovery board.
It turns out that there are a couple of bits that need to be set/clear in order for the HS peripheral to have the clocks stay enabled during a WFI sleep.
See: http://forum.micropython.org/viewtopic.php?p=6959#p6953
It turns out that there are a couple of bits that need to be set/clear in order for the HS peripheral to have the clocks stay enabled during a WFI sleep.
See: http://forum.micropython.org/viewtopic.php?p=6959#p6953
Re: How to create USB Host CDC
Hi Dave/anybody else.
There are some precursors to have two USBs capable of working in the same runtime at the same time, that is both phy's USB_FS and USB_HS at the same time.
So far these are stm32_it.c
usbd_conf.c
stm32f4xx_hal_conf.h
Would it work to put these on a separate branch /pull for 1.5.1
I have still to work through how the OTG shares these - generically a switch between Device to Host based on the USB_ID does do a fast change in silicon - and there is one STM32 example.
There are some precursors to have two USBs capable of working in the same runtime at the same time, that is both phy's USB_FS and USB_HS at the same time.
So far these are stm32_it.c
Code: Select all
extern PCD_HandleTypeDef pcd_fs_handle;
extern PCD_HandleTypeDef pcd_hs_handle;
....
#if defined(USE_USB_FS)
//#define OTG_XX_IRQHandler OTG_FS_IRQHandler
//#define OTG_XX_WKUP_IRQHandler OTG_FS_WKUP_IRQHandler
//void OTG_XX_IRQHandler(void) {
void OTG_FS_IRQHandler(void) {
HAL_PCD_IRQHandler(&pcd_fs_handle);
}
#endif
#if defined(USE_USB_HS)
//#define OTG_XX_IRQHandler OTG_HS_IRQHandler
//#define OTG_XX_WKUP_IRQHandler OTG_HS_WKUP_IRQHandler
//void OTG_XX_IRQHandler(void) {
void OTG_HS_IRQHandler(void) {
HAL_PCD_IRQHandler(&pcd_hs_handle);
}
#if defined(USE_USB_FS)
void OTG_FS_WKUP_IRQHandler(void) {
if ((&pcd_fs_handle)->Init.low_power_enable) {
.....
//#ifdef USE_USB_FS
/* Clear EXTI pending Bit*/
__HAL_USB_FS_EXTI_CLEAR_FLAG();
//#elif defined(USE_USB_HS)
/* Clear EXTI pending Bit*/
// __HAL_USB_HS_EXTI_CLEAR_FLAG();
//#endif
}
#endif
<<<then repeat above for void OTG_HS_WKUP_IRQHandler>>
#endif
Code: Select all
#ifdef USE_USB_FS
PCD_HandleTypeDef pcd_fs_handle;
#endif
#ifdef USE_USB_HS
PCD_HandleTypeDef pcd_hs_handle;
<<< USBD_LL_Init changes for above>>
#endif
Code: Select all
#define USE_USB_FS
#define USE_USB_HS
I have still to work through how the OTG shares these - generically a switch between Device to Host based on the USB_ID does do a fast change in silicon - and there is one STM32 example.
Re: How to create USB Host CDC
separate branch from what? I'm not sure what exactly you're asking.dhylands wrote:Would it work to put these on a separate branch /pull for 1.5.1
You need to put it on a branch in order to create a pull request.
Re: How to create USB Host CDC
Create the changes necessary to support two USB phys at the same time. Currently only one can be invoked at a time - either USB_FS or USB_HS - not both.
Re: How to create USB Host CDC
It sounds like a reaonable feature to me. There are boards which make both easily available, like this one:
https://www.olimex.com/Products/ARM/ST/ ... e-hardware
https://www.olimex.com/Products/ARM/ST/ ... e-hardware