1
\$\begingroup\$

I'm making a computer peripheral that will be connected via a USB.
The main brain is an STM32 ARM MCU, it has USB support natively. It has multiple sub-peripherals inside and it uses I2C and SPI to interface with them, and I want the computer to interact with those as well.

I know that the computer can interact with all the sub-peripherals by interacting with the main MCU, but it would need special drivers I guess....
How can I make the computer "see" those sub-peripheral and interact with them directly?

Is a USB hub IC suitable for this task? Is there a way to make the computer "see" all the devices without it using some feature in the MCU?

Thanks a lot.

\$\endgroup\$
6
  • 1
    \$\begingroup\$ If properly designed, you do not need to write any driver for computer. You can build device around WinUSB and libusub which will work without need to write full driver. Alternative and still very popular way is implementing some common USB class like CDC which will also work without explicitely drivers, but interface and capabilities visible to computer are limited. In all cases you need write firmware for STM32 which is quite a lot of work, if you are beginer in this area. Search for tutorials, currently there are pleanty of them. Good luck. \$\endgroup\$
    – Misaz
    Sep 15, 2023 at 17:21
  • \$\begingroup\$ By "properly designed" you mean the STM32 firmware right? I guess the USB specifications are the same for all the operating systems, especially that I want my project to be read by the computer as HID. \$\endgroup\$ Sep 16, 2023 at 7:59
  • 1
    \$\begingroup\$ yes, but there is way how to configure descriptors in a way, that OS will not require full driver, but install some generic instead. If you have HID requirement, than you can go this way and it should work without drivers in most cases by default. \$\endgroup\$
    – Misaz
    Sep 16, 2023 at 9:17
  • \$\begingroup\$ sounds good, can you point me in the right direction? Btw, I know C++ and python, so please name any library that can help me, especially for C. Thanks. \$\endgroup\$ Sep 16, 2023 at 9:55
  • 1
    \$\begingroup\$ You did not mentioned which STM32 family use. For F4 is getting started guide here: st.com/content/st_com/en/support/learning/stm32-education/… \$\endgroup\$
    – Misaz
    Sep 17, 2023 at 10:05

1 Answer 1

4
\$\begingroup\$

That's not how it works.

Your computer will only see the STM32 in which ever way you like. For example a virtual serial port per submodule.

Then you need to make the STM32 software which can provide you a bridge between the PC and e.g SPI or I2C in any way you want.

One way is to make software for STM32 and allow commands from PC to read and write STM32 registers directly.

\$\endgroup\$
6
  • \$\begingroup\$ If the STM32 firmware can do the job I'm ready for the challenge, can you point me in the write direction? And by that I mean point me to DOCs and articles about the USB specification or whatever needed for me to learn about it. But in case I can't develop the STM firmware, the USB hub will work as intended right? \$\endgroup\$ Sep 16, 2023 at 7:50
  • 1
    \$\begingroup\$ @AbdAlhaleemBakkor I don't understand how an USB hub relates to your question. It allows you to plug multiple USB devices to a single computer port, nothing else. Just make whatever SPI and I2C functions you need, and then make them callable under commands from PC. Job done. \$\endgroup\$
    – Justme
    Sep 16, 2023 at 7:59
  • \$\begingroup\$ I mean a USB hub IC, on the hardware design level ... I think that if I put the USB hub IC to interface with the computer and the ICs which support USB behind it it can work... Only issue is that some ICs don't have USB natively and they have to communicate with the STM32 via I2C or SPI \$\endgroup\$ Sep 16, 2023 at 8:58
  • \$\begingroup\$ I agree on the "and then make them callable under commands from PC" part... But is that possible with the firmware on the STM? without writing software/driver on the PC? I want the PC to "read" those devices natively as if they are connected directly to the computer via USB. \$\endgroup\$ Sep 16, 2023 at 9:01
  • \$\begingroup\$ If your STM firmware can receive bytes from PC and do stuff with them, yes. I don't understand why you think it's not possible. And you can't make devices directly available, as it's the STM32 that is directly available, but it can provide e.g. one virtual com port or HID device for each I2C or SPI device if you want. \$\endgroup\$
    – Justme
    Sep 16, 2023 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.