STM32F4 - USB HUB library - no HAL / no SPL - Page 1
Forum section: electronics / general

author: Dawid
author_rank: Contributor
timestamp: September 12, 2016, 12:15:44 pm
content: Hi guys,is there anything like that? USB hub library for STM32F4 but without that hopeless HAL? Just CMSIS and registers? Did anybody tried to do that?EDIT: It should be 'Host'. I know, my mistake.

author: tatus1969
author_rank: Super Contributor
timestamp: September 12, 2016, 02:33:31 pm
content: I use HAL on these micros without problems. Don't see them as hopeless?

author: MosherIV
author_rank: Super Contributor
timestamp: September 12, 2016, 02:47:34 pm
content: The STM32F4 can be a USB host or a USB device. I am not aware that it can be a HUB device.HUB devices do things that the ST32 cannot : provide multiple USB ports, do negociation with USB devices, control power to USB port.So I do not think that the STM32F4 can be a HUB device.

author: technix
author_rank: Super Contributor
timestamp: September 12, 2016, 04:32:55 pm
content: STM32F4 have only one USB port so you cannot use it as a hub. If you are seeking to implement multiple virtual devices inside your chip try to implement the USB Composite Device class. If you are actualy looking to connect multiple USB devices (as in chips) to the host you can use some USB Hub ASIC like FE1.1s (that is a USB 2.0 chip despite the 1.1 name in the model number. It was a 1.1 chip several revisions ago but later implemented USB 2.0 without changing the pinout, so the manufacturer got lazy and kept its original part number as it is a drop in replacement.)

author: Dawid
author_rank: Contributor
timestamp: September 12, 2016, 06:48:15 pm
content: I'm sorry, stupid me. It should be 'host' of course.I don't like HAL, I tried and I had more problems with that than positive results. Don't try to convince me to the HAL/SPL. I just want to know if anybody knows about any library for USB Host that does not push me into the HAL/SPL.Thank you and I apologize for my mistake in the first post.

author: technix
author_rank: Super Contributor
timestamp: September 12, 2016, 07:44:07 pm
content: Quote from: Dawid on September 12, 2016, 06:48:15 pmSo far I have not seen any of it. I second your opinion on HAL/SPL which is messy as hell to me. Why can't something as simple as opening a serial port be implemented in something as simple as uart_open(USART1, 115200, 128) and have to go through all that structures, let alone the fact that even those structures aren't the whole business? If you prefer structures I might as well go directly to the hardware registers.

author: MosherIV
author_rank: Super Contributor
timestamp: September 12, 2016, 07:59:08 pm
content: Sorry, I do not know of any libraries which provide USB host via direct register access.The Data sheets and USB Application notes are your best bet to write your own. However, I found that there is not enough information in them to write a complete driver. You may need to do some reverse engineering of the ST Hal libraries.I found it was just easier to work with the ST libraries. Use the ST forum, if you have any problems, ask Clive !

author: Dawid
author_rank: Contributor
timestamp: September 12, 2016, 08:01:47 pm
content: I'm very close to the decision to write my USB host (yes, I even don't know 50% of problems I need to go through).In HAL annoying thing is that I prepared my own, clear, nice library to decode Manchester Code and I cannot use this because there is some conflict with the HAL drivers (I can compile the code but it does work properly). I like to know what I do and with HAL it's really hard. It's like reverse engineering the code written by somebody else.Thank you guys! I will check the ST forum.If you have any ideas let me know please!

author: MosherIV
author_rank: Super Contributor
timestamp: September 12, 2016, 08:06:40 pm
content: It sounds like you are thinking and trying to treat the USB as a device and device driver.That is the wrong approach. The USB host or device is a communications stack, the HAL takes care of driving the low level hardware for you. You just pump or retrieve data from the stack, or setup or tear down the stack depending on what device is being implemented/talked to.Does that make sense?

author: Dawid
author_rank: Contributor
timestamp: September 12, 2016, 08:45:17 pm
content: Ok, so there is no module like for UART that gives me the data in some register? I found in the reference manual the description of some registers to setup the USB communication. Is it wrong path? I have deal with the whole data coming from the USB?

author: MosherIV
author_rank: Super Contributor
timestamp: September 12, 2016, 09:13:18 pm
content: QuoteUnlike UART the data comes in packets, so USB provides the data in a buffer. The interaction with USB is so fast that the buffer must be emptied as quickly as possible, so the USB end point is serviced by irq.So there must be a number of layer, and each layer has buffers.While, you can access the USB peripheral registers, it is not in any way like a serial device.Like I said, treat it like a communications stack which has layers. Your code only needs to interact with the top layer. The USB Hal code handles everything else. That is how I used the USB CDC device and the USB Hal code.

author: dannyf
author_rank: Super Contributor
timestamp: September 12, 2016, 10:25:15 pm
content: The SPL is nothing but a set of routines that works on the registers.So implement your task on SPL. And then trace out how the SPL sets up the registers and replicate that yourself.Done.

author: dannyf
author_rank: Super Contributor
timestamp: September 12, 2016, 10:27:30 pm
content: SPL isntbthat offensive, with a few exceptions.The biggest mistake people make with vendor libraries like the SPL is to use then in their code directly.Once you do that, your code is hardwired to the SPL and it is difficult to migrate away from it.Use middleware instead.