Images tagged "timer"


  1. Pingback: centrifugal pump tutorial -- CFD Online Discussion Forums

  2. Pingback: STM32 And Custom USB HID Device? Yes Please! - Damogran Labs

  3. Pingback: STM32 USB CDC communication device | Damogran Labs

  4. Pingback: STM32 USB CDC communication device | Damogran Labs

  5. Pingback: STM32 And Custom USB HID Device? Yes Please! | Damogran Labs

  6. Pingback: 备忘文章三篇 – 用树莓派做数码相机

  7. Thanks for sharing, good explanation and easy way to get started with USB.

  8. Pingback: How To Make Indestructible Housings - Labyrinth Ljubljana Flashlights | Damogran Labs

  9. Pingback: How To Use CNC For Plastics | Damogran Labs

  10. Pingback: SPI Bus Cable Length - nRF24 | Damogran Labs

  11. Hi,
    Thanks for sharing.
    I have a question related to STM32 USB CDC behaviour when compared to CP210x.
    In linux machine STM enumberated as ‘/dev/ttyACM*’ where as CP210x as ‘/dev/ttyUSB*’. I believe drivers used are different on linux kernel. Is there any way to match STM32’s USB driver to enumerate as ‘/dev/ttyUSB’ i.e. same as CP210x?

  12. 1. Thank you Domen you save me a lot of time, your example works perfectly well
    2. Did you try to use this usb driver with FreeRtos (I mean Cube+HAL+FreeRtos)? Seems that it doesnt work, cant find a reason why (the programm triggers HardFault_Handler). Try to search such a cases in a google, but cant find any helpful information, may be it is well known issue for you?

    • Hello Mikhail,
      unfortunately I have no experience with FreeRTOS so far.
      Anyway, if standard ‘debug’ procedure with setting breakpoints and searching the execution line that throws Hardfault doesn’t give any clues, the first thing I would check is that stack and heap sizes are large enough.

      Please, let me and others know if you solve this problem. Good luck!

      • Hello Domen, seems that problem was in a size of stack that was reserved for OS task, I increased size then everything went fine

      • sorry, I didn’t read the tail of your post when begun to type answer) your assumption was correct. Thanks for your article and for your answer

  13. Pingback: Settings Menu for Arduino-based Devices | Damogran Labs

  14. Great news!
    Thank you and good luck. 🙂

  15. Hi Domen,
    I use STM32F103RBT. What I understand is that I should generate the file ‘usbd_conf.h’ with Cube MX for STM32F103RBT to use with STM32 USB CDC lib.
    I don’t know how to use Cube MX. Could you help me?

  16. Thanks for your sharing but what should I change in usbd_hid_core.c?

  17. Pingback: OpenFOAM and Rotating Machinery: Relative Velocity | Damogran Labs

  18. Pingback: Parallel ParaView | Damogran Labs

  19. Hello, stupid question here.
    Is the STM32 can be possibly to b the host and able to connect to MCP2200?

  20. Thanks a lot for the helpful description.
    As a hint: I needed to deinstall the driver of the HID Mouse Device in the Windows Device Manager manually to have the keyboard beeing recognized after the change from the mouse example.

    • Yes! I’ve experienced the same issue when I was playing with different VID/PID numbers.
      Also, I am not sure, but Windows might cache already recognised devices, which could be a problem if a device configuration has changed in the meantime. This is not the case with of-the-shelf hardware.

  21. Thanks for this great work. And working as expected.
    Is variable store on this “miTestInt, miTestFloat, miTestChoice,” for further use in program. and how can serial.print these variable.

  22. Hi there, i’m trying to implement the stm32 blue pill board as a slave on a PCB that gets controller by the user via USB, the problem is that when i plug in the board (USB (pc) to microUSB(uC)) it’s just a power supply, no com port is detected or anything, can u help?

    • Hello. If there is absolutely no reaction once device is connected to PC, I would assume one of the following issues is present:
      – you have a wrong cable (I once used some cheap power supply usb cables without data wires) or other hardware issue.
      – your device configuration (code) is invalid or CPU don’t even do initialization due some error
      – one of other 341532 possible issues 😀
      I would first try to search for any visible hardware issues, than I would program the most basic (default) USB example (CubeMX HID device) and try to get this working. Than, when you are sure that the board is OK, move on with CDC.

      p.s.: Do yourself a favor and while asking for help, describe as much details as you possibly can. What do you wish to accomplish, what have you already tried and what are the results of that, what have you changed in a given example, what did you discover when debugging code, … It is nearly impossible to help with no info.

  23. Lilian Chabannes

    Thanks, it helped a lot!
    I didn’t manage to do this with Paraview, I had to use paraFoam since step 3 “Filters > Cell data to point data” did not work. Basically my block was empty of data. Did I forget to click something?

  24. How is this comparable to Atollic TrueStudio

  25. Atollic TrueStudio (and others) is a more complete, advanced IDE package. Which means, for any serious project where debug/multicore/OS/trace/… is needed, some sort of advanced IDE is the only way to go, and Atollic TrueStudio is fine I think.

    For a simpler projects you sometimes just want two things: a good text editor and a basic debug capabilities. This is what this project is about. It cannot compare with other advanced IDEs in terms of features, but it can compare (and probably win) in terms of simplicity and straight-forwardness.

    In fact, I tried Atollic TrueStudio, and it is a good capable IDE – if you wish to bother configuring Eclipse and all 10^8 settings to blink a LED. 😀

  26. Thanks for your reply.
    As I am a noob, and an Arduino user, I find these complicated IDE (like Atollic) quite troublesome and not straight forward. Just adding and deleting files could cause a compile errors if you are not careful, not to mention importing other eclipse project.
    Thanks anyway for the thought.

  27. hi, i have one question.
    How can you combine USB CDC files which are created with CubeMX and other program written in sw4stm32 or Atollic TrueStudio with standard peripheral library?

    • I wouldn’t do that. Standard peripheral libraries is already outdated, and as far as I know, STM32 does not develop it anymore. Not the case with STM8, but for STM32, stick to either old StdPeripheral library or port to HAL/LowLayer.

      In case of CubeMX generated USB files, they are based on HAL, so it would be really hard to port this files to StdPeripheral lib. Maybe you could include required HAL libraries in the project, but this would take time – I wouldn’t go this way.

      You would probably re-write/port whole application to HAL/LL much faster than re-implement USB to use StdPeripheral lib. This would also alow you to regenerate project with CubeMX.

  28. Pingback: How To: Python Application Structure | Damogran Labs

  29. Shashank Mishra

    Hey Domen ,
    I found your blog very helpfull.
    I generated my code for USB HID from STMCUBEMX for STM32F107 and by just changing the VID & PID (As i just want to varify my device get detected before proceding further for the application) i downloaded it to my setup but i am getting the error (Device descriptor Error).
    what is the issue?
    Could you just help me with any sample code for STM32F107 ?

    • I won’t be available for some time, so I can’t write any code. Anyway, what you are experiencing completely makes sense: by changing VID or PID, PC can’t found the drivers needed to communicate with this device. Although you didn’t change descriptors on target side, there is still a PC side code (drivers) that take care of communication and other low level stuff.
      Your device should get detected just with the same VID/PID.
      Good luck!

      • Shashank Mishra

        Thanks for the reply.
        Now I am out of ideas as i tried almost everything on this, It will be helpful if you could guide me with your valuable suggestion and some fresh ideas.
        You can connect with me on

      • Bilaal Shaafiilana

        I’m really grateful to find this blog. It’s very useful, because I need it to complete my thesis.
        I’ve followed the guide, I could run the USB HID Mouse feature, but when I tried to run the Keyboard one, the device was detected as USB device, but it couldn’t type any letters (I’ve tried the example that you provide in this blog). Do you have any idea to solve my problem?
        Thanks before, Domen

      • It is always hard to guess what the problem might be – what have you already tried, what does device manager say, did you do any modifications to the example, do you try to plug this device in some other PC? If you didn’t think of this questions, try to go through this first. If the example does not work on your PC, try to remove (in device manager) the device, uninstall drivers, … (also for the mouse example).
        And before you do anything, just make sure you really have a working example, leave out all your modifications. Sometimes just a faulty descriptor can make the device unrecognisable by PC…
        Good luck!

  30. ParaView and paraFoam use different OpenFOAM readers. With the latest ParaView
    (version 5.6) you can choose “Read zones” and then “Copy data to cell zones”, then extract block and all.

  31. If you find you can’t debug your USB:

    I’m working on a Blue Pill (stm32f103c) CDC, using the new StmCubeIDE. I couldn’t debug USB until I pulsed the D+ USB line (A12 on the Blue Pill) low with a 100 ohm resistor. This causes the link to re-register.

    Later I defined line A10 (portA pin 10) as open-drain, and pulse it low for 100ms. before the main program loop. I found some boards (Nucleo) have a transistor to do this.

  32. What’s happening if I can see it in the Device Manager but can’t open it?
    I tried adding your line to a STM32F303CTB’s CubeMX program; when I plug it in, it enumerates and shows up as a com port (Com8). It doesn’t show up in Teraterm, and if I try to open it, I get “Cannot be opened.”

    It shows up in WMI… but can’t be used.
    Also… is there a real need for CRC’s and such over USB, or is that adequately handled at a lower level (in the USB communication stack)?

  33. “When I plug it in, it enumerates and shows up as a com port (Com8). It doesn’t show up in Teraterm, and if I try to open it, I get “Cannot be opened.”

    Are you sure you have only one connection to this port (If you connect with some other software/scripts to this port, port might not be accessible, although it is listed). Another question is: is your STM responsive (can CPU handle USB stack and data, or is in your while (1) loop or some hardfault handler?

    Also… is there a real need for CRC’s and such over USB, or is that adequately handled at a lower level (in the USB communication stack)?

    The most honest answer I can give: I don’t know. But, first google look up lead me to a interesting forum topic:

    • That’s cool!
      I found the issue; evidently my “init code” (check ADC voltages, etc) was “too busy” and it wasn’t initializing correctly (too much of a gap between “plugging in” and “MX_USB_DEVICE_Init”, so the PC was getting confused).

      Pulling DM & DP low for 1sec before the MX_USB_DEVICE_Init() in main forced the computer to do an “unplug and replug” event and now it’s working well. Onwards!

      Now I’m really liking the USB… I’m not sure I’ll ever go back to normal serial:
      – Baud rate? Don’t care, but if I did, the STM32 can read what the PC wanted.
      – Which com port? Look at the USB info and find the “ThisPortIsMine” and I know which com port to open, no matter what the PC enumerates it as.
      – 2 Pins… and I get CD/RTS/CTS and everything else… and I can have multiple devices if I wanted to (so HID to send some control signals back and forth and…); no need to “decode and handle” line breaks (for a forced reset), etc.

  34. After doing a Reset in STM32F103, I verified a successful SW Reset. However, I lose the connection with the USB Host PC. I want to be able to reestablish the connection without removing/replacing the USB cables. Can you explain why and suggest any sollution?

  35. It resets the traffic (which disconnect windows), but it doesn’t do the “replug” event to cause the windows box to restart the connection. I fixed it by making the port GPIO and holding DM&DP “low” for 500ms before calling the MX_USB_DEVICE_Init() function.

    It means that every time you restart the device, it “unplugs and replugs”, but it does work. You need to let the device run without breakpoints for a couple of seconds after the USB_DEVICE_Init() so it will finalize the connection (you can put breakpoints in, but don’t stop the CPU for a little bit).

  36. This had just became an amazing tool. Thank you very much for your effort.

  37. Thanks for tutorial firs of all.
    In the error of the keyboard, when testing the mouse example correctly.
    The same error occurred to me that windows didn’t recognize the HID keyboard correctly.
    The solution was in “usbd_hid.h” to change:

    I hope this solution serves.

  38. Hi,

    Re:Unable to Transmit the Data (USB CDC ) to PC (STM32L476RG Eval Board).

    I am trying to transmit the data(USB CDC) over PC but I didn’t see any message printing on Serial Putty Console. Do I need to change any configuration settings. May I know , why transmission was not happening.. I am trying to dig into deep. so could you anyone try to help me out to overcome this Problem.I also followed your suggestion Loop back test. I tried but No Data Transmit was happened.

    • Hello Lakshmikanth. For anyone to help you, you would need to make a little effort and explain:
      – What does work? Where does your code stuck (did you try to debug it?)? Does it transmit anything or is ti completely dead?
      – Can you receive anything from some other board/device?
      – …
      If you need help, we are happy to help you – but we won’t guess what is going on or what you did or didn’t do.
      Learn how to ask for help and how to write an issue report.

      • Hi Domen,

        Thank you for your quick response.

        1) What are the steps I have been followed ?

        As per below link I followed the steps


        I generated code in CubeMx as per above link.
        I have added little bit code to Transmit the data to PC as mention below.
        – Enable LED pin (GPIO_SET)
        – Transmit The data (CDC_Transmit Function) CDC_Transmit_FS(UserTxBuffer,7);
        – Disable the LED pin(GPIO_RESET)

        2) What does work?

        Till Now I haven’t seen any Data Transmit(From Board STM32L476RG) to PC (Putty)

        3) Where does your code stuck (did you try to debug it?)?

        1) I tried to put in debug mode (In CubeMX enable SW in Debug options).
        2) I can able to see in the log ,it’s enter into CDC_Transmit Function and displayed as shown in below syntax.
        3) Debug_write(“Message Transmitted”,(uint16_t)20);
        i.e Message Trasmitted was displayed on Serial wire viewer on both STLINK Utiity/Atollic IDE (SWO output)
        4) I enabled USBD_DEBUG_LEVEL 3.Find the Below log for reference.

        [2.160] read(): Rx: $vFlashWrite:80051b0:\001\004\002\010\000\020\020\020\004\020\020\020\002\020\020\020\010ERROR: \000Invalid Device handle\000Invalid Class handle\000USBD SWO test1\000DEBUG : \000USBD SWO test2\000End\000\000\000\000\000\000\000\000\000\001\002\003\004\006\007\010\011\000\000\000\000\001\002\003\004\000\377\377\001\000@\015\003\000\377\032\006\000\0005\014\000@B\017\000\377\377\036\000\000\011=\000\000\022z\000\000}\004\377\000\0006n\001\000H\377\001\000l\377\002Message received\012\000CDC Receive\000Message Transmitted\000CDC Transmit\000Message:Buf\000\000\002\001\002CDC Config\000CDC Interface\000STMicroelectronics\000STM32 Virtual ComPort\000\000\000\000\377\001\000 \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000…
        [3.469] spawnCubeProgrammer(): 19:04:05:899 STLinkUSBDriver.dll loaded

        5) I have seen in the Log (Invalid Device/Class).. I noticed the it’s unable to find the Device/class.

        4) Does it transmit anything or is it completely dead?

        I could see any data transmission on PC (Putty)

        – Can you receive anything from some other board/device?
        I couldn’t receiving any data from board/device.

  39. Hi Domen,

    Thank you for response and giving some good instructions.
    Please find the below link for reference which has mention cleared.

    • Hi Domen,

      Actually, I tried to debug the USB CDC Communication.
      The Function CDC_Transmit_FS() => always return USBD_BUSY state.
      Need to Find the overcome of USBD_BUSY state.could you please help me out of this problem. I am looking forward for your reply

      • Well, I must respond in the same way as with first comment – if you need help, make an effort and describe what is going on in details, what you already tried, …
        I’m sorry, I didn’t notice your previous comment was sent to spam.

        I generated code in CubeMx as per above link.

        I can’t offer help for samples that are not part of this blog post. It is hard to advise for a specific problems that are not this project specific. I can only offer (if at all) generic answers, which you could probably google faster than you read this :).

        2) What does work?

        First, try to achieve that your board is registered by PC. Do you have correct drivers? In order to send/receive data, you must be sure your device is properly enumerated by PC OS.

        I tried to put in debug mode (In CubeMX enable SW in Debug options

        Logging is good. BUT, make sure your extensive logging does not cause delays – you should not block CPU to periodicaly handle USB stack.

        5) I have seen in the Log (Invalid Device/Class).. I noticed the it’s unable to find the Device/class.

        This is your homework. 🙂 Research what could go wrong when device needs to be enumerated by PC. You must see it in device manager, as it is displayed in this blog post.

  40. Hi Domen,

    Thank you for your prompt response.

    Hope you did’nt notice the Previous comment which was I mention that the Function CDC_Transmit_FS() => always return USBD_BUSY state.
    That why Data Transmission was not happening..

  41. Pingback: SALOME for multiregion meshing | Damogran Labs

  42. Pingback: SALOME for multiregion meshing | Damogran Labs

  43. Hi Domen,

    The issue is resolved after connecting with new USB daughter board along with USB Type A Cable. Actually I have seen below reference readme.txt of different controller Board from that I got to know.


    Thank you for your support.

  44. Thank.
    Very interesting.
    I’ll try to figure it out.

  45. Thank you very much for the nice work. Things progressed nicely. I get the following message when running “Enter path or command for ‘stm32SvdPath:”Any help in resolving it is appreciated.

    • Hello Gargamel,
      please create an issue here:
      Describe (with as much details as you can) how I can reproduce this issue, how exactly your environment is set (where project is located, where is/should be your .svd file, …). Copy task output and give as much clues as you can – what you have already tried, …

      But, first of all, make sure you use the latest version of ideScripts.

      Thank you, good luck!

  46. I have it all installed but fails once I enter the path to stm32svd.path. It complains that access is denied. wondering if I have something in the wrong directory. Running Windows 10

  47. Pingback: Points and Vectors | Damogran Labs

  48. Pingback: Points and Vectors | Damogran Labs

  49. Hi Domen,
    In my project, I convert STM32 USB CDC to WINUSB Device with HAL library and now I want to use virtual com port too. But the problem is in a moment just an application running, so can I edit some points in descriptor or something to choose which application I wanna use?

  50. Hi,
    In Update time i got error
    ERROR (8 seconds).
    Unexpected error occured during ‘Update’ procedure. Exception:
    Traceback (most recent call last):
    File “d:/STM32/VSCode_STM32_IDE/STM32CubeMx_WS/STM32_Test/ideScripts/”, line 56, in
    makefileData = makefile.getMakefileData(makeExePath, gccExePath)
    File “d:\STM32\VSCode_STM32_IDE\STM32CubeMx_WS\STM32_Test\ideScripts\”, line 93, in getMakefileData
    projectName = self.getMakefileVariable(makeExePath, gccExePath, self.mkfStr.projectName)[0]
    File “d:\STM32\VSCode_STM32_IDE\STM32CubeMx_WS\STM32_Test\ideScripts\”, line 366, in getMakefileVariable
    proc = Popen(arguments, stdout=PIPE)
    File “C:\Users\kumar\AppData\Local\Programs\Python\Python38-32\lib\”, line 854, in init
    self._execute_child(args, executable, preexec_fn, close_fds,
    File “C:\Users\kumar\AppData\Local\Programs\Python\Python38-32\lib\”, line 1307, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
    PermissionError: [WinError 5] Access is denied

  51. It works. Thank You 🙂 Now I can make sudo uptate & upgrade just by inset usb device 🙂

  52. Dear,
    In your last update you add “miTestText” its working fine when we print it.But how we can compare it in if statement.

    In below example code “Y” or “N” is not printing. I am trying to use this text as a comparison between values.

    lcd.setCursor(0, 1);

    if (miTestText->getValue() == 123456) {
    lcd.setCursor(13, 1);
    else if (miTestText->getValue() == ! 123456) {
    lcd.setCursor(13, 1);

  53. Pingback: Classy Classes for blockMesh | Damogran Labs

  54. Thank you for all the hard work you did to make this tool and then for sharing it for others such as myself. It is too bad that there isn’t a VSCode extension that would make CubeMX work directly from within VSCode.
    By the way, many people are now using Stm32CubeIDE which includes the cross-compiler tools and debugger interface tools in the setup (!!). It is a “slam dunk” to install, run, compile, debug. The makefile directory structure that results using it is slightly different than the Stm32CubeMX one but almost the same.
    Could your tool be adapted to work with this instead (CubeIDE)? It seems valuable to be able to use the Eclipse based tool to verify things if or when there is a problem using VSCode. And again, it simplifies setting up a working set of tools. It might even make it so that your Python scripts can find everything without having to ask the user since those tools are all in a defined place.
    I will note that I am having some trouble applying your tool to my Mac OS computer with CubeMX on it. Hopefully I figure it out but for now I am stuck relying on using CubeIDE for my work while on the Mac.

    • Hello and thank you.
      This of course is possible, but doesn’t make sense – although VS Code is an amazing editor, it still doesn’t have proper debug capabilities and other things you usually need when developing embedded application. VS Code STM32 IDE project was meant for simple projects and can’t compare with proper IDEs.
      However, what you are asking is possible, maybe even easier to do than with CubeMX usage, but it is basically a rewrite – project is tightly coupled to CubeMX and read/generate makefile. Maybe STM32CubeIDE has better capabilities external control (like triggering build process or regenerate workspace, …), but this is a whole other story.
      I don’t have time, but feel free to take my project as a template and expand it. I can only offer you a help for a current project. And think twice – for more comple embedded projects just go with their or others IDE.

      Good luck, Domen

  55. Hi Domen,
    I have a problem with my own implementation of USB CDC device, so I find your example code and ran it, but get the same error I had before.
    The problem is that my USB device is not recognized by my PC (“Unknow Device” error 43), I tested in WXP, W7 and W10 PCs.
    I think I have a kind of HW problem here because I have tested the SW a LOT without results, I am using a STM32L100C-DISCO board and a USB cable.

    I have some HW related questions if you please could help me on this:
    1 – Did you connect STM32L100-DISCO PA11_DM and PA12_DP directly to USB cable – (green) and + (white) wires?
    2 – Did you use external pullpup resistor connected between DP and Vcc?
    3 – Did you connected +,- and GND USB cable wires only, no Vcc right?
    4 – I know PC driver is needed for USB enumeration, but it is needed for USB board description? I mean, even without a driver I should see the device description (“STM32 Virtual ComPort”) and no “Unknow Device” right?
    I will be very grateful if you could helm me on this.

    • Hello Jose,
      1. Yes. Make sure you have a good shielded usb cable and that unshielded part of cable that connects to PCB is as short as possible (< 1cm).
      2. I belive I have. Read this and add pull-up:
      I’ve even found a picture of test setup back then:
      3.Yes. Vcc is not needed since you power your board (probably) over onboard debug USB. Note that good GND is very important. Keep GND and data +/- connectors as close as possible and make sure the contact is good.
      4. No, I think you need the drivers in order to communicate with STM32 implementation of the USB.

      My advice: first make sure sort out all hardware settings and work with some basic default workspace (project).

      • Hi Domen,

        Thanks a lot.
        Could you please post a link to the windows driver you used to test your code?
        I just want to make sure I am testing your code using exactly the same environment you have.


  56. Do you have an example for receiving CapsLock NumLock status from pc.

    • No, I currently don’t have any other examples. You should probably check how to read IN Endpoint of this HID device, which is not implemented in examples.
      Good luck.

  57. Since you already have your ST development board operationable, I assume you already have the necessary drivers.
    Do ‘official’ CubeMX generated examples work? If not, you probably have some HW issues. If they do work, did you change anything(!) in my example code?

  58. Hi Domen,
    I have been working with my STM32L100-DISCO board for some other apps without a problem, recently I did a driver code for an OLED display and also I coded an app for SDCard read and write, I am not an expert but have some experience with the board an CubeMX, but now I am trying to test a USB app and have an “Unknow Device (error 43)” error and can’t find the problem so far.
    That’s why I appreciate a lot your example code, because I could contrast my code with yours having the security that your code works.
    Regarding your question, I had to change your code clock setup, because I have not a crystal o resonator, I am using the 8MHz HSE clock provided in the board, and multiplying it for 12 and divided by 3, the result is a USB clock of 48MHz, so it should work this way.
    I also did a blinking led in my code (yours already have a button code) just to be sure that code is working, also coded a PA_11 and PA_12 port output toggle test app just to be sure both ports are working.
    I looked at PA_11 and PA_12 using an oscilloscope and looks like no data from the microcontroller is present, just the data from the PC, it is hard to be sure of that because both are present in the same lines but looks like if the board were not connected at all, I mean I saw the same data on the cable wires with and without the board.
    At this moment I asked my business partner to test another STM32L100C-DISCO board he has, using your example and/or mi test code to see if it works for him because I think the problem is either my board or something in my HW because I also have tested using some other PCs and windows.
    In all the USB code examples I have found or all the examples I saw in the web using the CubeMx the PC recognizes the USD device at once, nobody has complaint of “Unknow Device” error.

    • Hej Jose. The last part:
      In all the USB code examples I have found or all the examples I saw in the web using the CubeMx the PC recognizes the USD device at once, nobody has complaint of “Unknow Device” error.
      Start here. Create a bare minimum USB example with CubeMX and try to make it work. If you stuck there, try other board and other USB port on a PC.
      Make sure you don’t have any blocking code segments (delays or long running functions). The best is just to use some verified project, that is not mine. 🙂

  59. Awesome man! you save me lot of time!

  60. Pingback: STM32 USB HID Mouse And Keyboard (guide) | Damogran Labs

  61. Very nice. Thanks.

  62. Pingback: Classy Classes for blockMesh | Damogran Labs

  63. Pingback: STM32 USB HID Mouse And Keyboard (guide) | Damogran Labs

  64. Your code link is broken to github

  65. Matthew Kefford

    This is the first time I’ve seen anyone explain what an endpoint is and why the naming is reversed. Looking through the code I was so confused why data in is Tx and data out is Rx. So thank you for that. Unfortunately I had already got this far with working comms and was hoping this guide would help with the next step. I’m not sure how to detect in our app when we have been sent data. I know it is automatically placed into the UserRxBuffer but the USB interrupt is already used for the sending/receiving state machine. How are we alerted when we have been sent a packet and need to go deal with it?
    Thanks 🙂

    • Matthew Kefford

      Replying to my own thing here but…I suppose the receive function is essentially an interrupt as it’s a callback triggered by asynchronous events. Just wondering how to deal with the data once it’s arrived, move it to another buffer? Start processing it for start byte, packet number etc, pass it to another function?

      • Generally speaking (not this project/STM specific): you have to know what you are dealing with. Let me explain: you (well, your code) is the one that is generating USB data to send. You have to know how much data you will have to send in a worst case scenario and you must take care that buffers and endpoints are configured accordingly. The same goes for RX data, you have to know what to expect and how to handle all scenarios, including failures and garbage data. From my other projects I’ve learned that the best practice for communication data is to have a large-enough FIFO buffer, that is filled with data when the data is ready and pumped out in some interrupt based/DMA routine.

        Now, I am a bit out of these USB-based projects, but I am sure some kind of callback/interrupt is available once data is received/sent. There might be some USB specifics, but at the end of the day, data must be stored somewhere so some mechanisms are surelly implemented.

        Example: with my SDP, buffers are used as mentioned above:

  66. Thank you very much for this excellent tutorial! Keyboard emulation worked like a charm!

  67. Very good material, thanks!!!!!!

  68. Pingback: A Parametric CFD Model: Wind Turbine from Pipes | Damogran Labs

  69. Pingback: OpenFOAM and DAKOTA: a Complete Guide | Damogran Labs

  70. Pingback: A Parametric CFD Model: Wind Turbine from Pipes | Damogran Labs

  71. Pingback: Classy Classes for blockMesh | Damogran Labs

  72. Pingback: Arduino settings menu: updated | Damogran Labs

  73. Pingback: Air Assist Nozzle for Laser Cutter | Damogran Labs

  74. Pingback: Laser Cutting Burn Marks And How to Get Rid of Them | Damogran Labs

  75. Pingback: MS Natural Ergonomic Keyboard 4000 + Kensington trackball mouse | Damogran Labs

  76. Hello
    I am very impressed by your skills using Salome.
    I try to follow your procedure but I am not very familiar with python files etc.

    I am using Salome 9.5 on Windows 10. I am stuck at the first step! where I have to define the pathes in the file. Can you help me please?

    I write for the os:

    • study_dir = “C:\Users\julien\Desktop\Salome96\salome9.5\salome-multiregion/”
      input_file = “C:\Users\julien\Desktop\Salome96\salome9.5\salome-multiregion\model/model.step”
      output_dir = “C:\Users\julien\Desktop\Salome96\salome9.5\salome-multiregion/geometry”

      I have the error in Salome:

      exec(open(“C:/Users/julien/Desktop/Salome96/salome9.5/salome-multiregion/”, “rb”).read())
      Traceback (most recent call last):
      File “”, line 1, in
      File “”, line 3
      SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape

  77. Absolutely helpful!! really thank you for pointing out such extraordinary tricks 😀

  78. Pingback: STM32 USB HID Mouse And Keyboard (guide) – PCA2Z

  79. Pingback: STM32 USB HID Mouse And Keyboard (guide) – PCA2Z

  80. Is there a way for Windows to remember this setting? I have to re-select this setting every time I reboot.

  81. Hai Domen,
    ISSUE:The Function CDC_Transmit_FS() => always return USBD_BUSY state.

    I’m using stm32f070c6 controller for USB CDC application ,I tried to debug the USB CDC Communication., The Function CDC_Transmit_FS() => always return USBD_BUSY state. Need to Find the overcome of USBD_BUSY state. and it shows unknown device(device descriptor request failed), I have increased the heap size ,and i have connected 1.5k resistor between the vbus and d+ ,i have checked the respected pins voltages vbus-5v,d+ =3.1v,I have shifted to different IDE “S but no use ,please if you have any idea about of this problem please give a suggestion how to overcome this error, why the CDC_TRANSMIT function always return usbd_busy, I have tried with different ways but no use

    • It is relatively hard to say just by your description. Based on my experiences, you are dealing with hardware issue(s). Try generating the most basic HID device with CubeMX and check if your PC recognise it (it should). If not, you most likely have some wiring or interference issues. Keep short cables and unshielded parts really short.

  82. Michael Blankenship

    I do not see that file in my task manager.

  83. swetha vutlapalli

    Hi Nejc,

    It’s interesting to find these developments in blockMesh utility and looking forward to more

  84. Hi,

    I’m trying to do the exact same thing for my project with the exact same board and softwares. I tried to use the .zip file without modifying anything. Nevertheless, once loaded, the com port is not detected. I just have “STMicroelectronics STLink dongle” in my USB Devices but no com port.
    Is that normal?

    Thank you in advance for your help.

    • Well, technically it should work out of the box with the attached files. In most cases, hardware issues are the reason that it doesn’t work, so make sure you really take care of that first.

      Try to download the code and after CPU is already running, insert the USB cable to PC.

  85. Hi
    I am using the Nucleoh745ziq board. I interface the USB as custome HID. USING HID DEMONSTRATOR app I am checking the interfacing I am able to send the data “Hello world” in HID DEMONSTRATOR APP. But I try to receive the data from HID DEMONSTRATOR but I am unable to receive it. USBD_HID_OUTEVENTS(uint8_t event _idx, uint8_t state) in this function I am try to receiving the data. But unable to receive it.

    • Unfortunatelly, I have no experience with this board or its USB implementation library. Although they might be similar, I can only assume things – you have better chance with just keep googling.
      Good luck.

      btw, for me, USBD_HID_OUTEVENTS is kind of a strange function name for what you want. For example, in the code above CDC_Receive_FS() is used. Check if you are really using the right functions.

      • I am using the Nucleo-h745ziq board.Board interface with User usb port as custome HID.Through USB I am sending and receving the data.For this I am using the USB HID Demonstartor (v1.0.2).
        I am able to send the data but unable to receive from USB HID Demonstrator.

        Here is my code:

        uint8_t USBD_CUSTOM_HID_ReceivePacket(USBD_HandleTypeDef *pdev)


        USBD_CUSTOM_HID_HandleTypeDef *hhid;

        if (pdev->pClassData == NULL)


        return (uint8_t)USBD_FAIL;


        hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassData;

        /* Resume USB Out process */

        (void)USBD_LL_PrepareReceive(pdev, CUSTOM_HID_EPOUT_ADDR, hhid->Report_buf,


        for(uint8_t i=0;i<1;i++)




        if(rx_data[0]==1) HAL_GPIO_TogglePin(GPIOE, GPIO_PIN_1);

        if(rx_data[0]==2) HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_14);

        return (uint8_t)USBD_OK;



        {/* USER CODE BEGIN 0 */

        0x06, 0x00, 0xFF, // Usage Page = 0xFF00 (Vendor Defined Page 1)

        0x09, 0x01, // Usage (Vendor Usage 1)

        0xA1, 0x01, // Collection (Application)

        // Input report

        0x19, 0x01, // Usage Minimum

        0x29, 0x40, // Usage Maximum

        0x15, 0x80,//0x00, // Logical Minimum (data bytes in the report may have minimum value = 0x00)

        //0x26, 0xFF, 0x00, // Logical Maximum (data bytes in the report may have maximum value = 0x00FF = unsigned 255)


        0x75, 0x08, // Report Size: 8-bit field size

        0x95, CUSTOM_HID_EPIN_SIZE,// Report Count

        0x81, 0x02, // Input (Data, Array, Abs)

        // Output report

        0x19, 0x01, // Usage Minimum

        0x29, 0x40, // Usage Maximum

        0x75, 0x08, // Report Size: 8-bit field size

        0x95, CUSTOM_HID_EPOUT_SIZE,// Report Count

        0x91, 0x02, // Output (Data, Array, Abs)


        /* USER CODE END 0 */

        /* END_COLLECTION */


        #ifndef CUSTOM_HID_EPIN_SIZE

        #define CUSTOM_HID_EPIN_SIZE 0x20U


        #define CUSTOM_HID_EPOUT_ADDR 0x01U

        #ifndef CUSTOM_HID_EPOUT_SIZE

        #define CUSTOM_HID_EPOUT_SIZE 0x20U


        Here is I setup done.I am unable to receive data .I forgot to intilasation the parameter or I am using wrong terminal? Because I am using USB Custome HID inerface.Can someone Help me?

  86. Dudi Varshavski

    Hi, I am using USB CDC on STM32H743 and sending about 32bytes every 10ms to linux. If I disconnect the USB cable and reconnect it, I sometimes get 16 bytes which looks like part of last message before cable disconnected.
    Where these bytes are stored with cable is disconnected?
    How can I remove them?
    How can I identify disconnection via interrupt?

    • I don’t know. I assume this is USB-implementation-specific, and can probably vary even among STM devices. It can further depend on If you use any DMA between user data buffer and USB endpoints.I would start by searching for “STM32 USB buffer” or similar, but you’ve probably already thought of that, so sorry, can’t help here.

  87. Thank you!

    I had multiple issues, Chrome remote desktop freezing, Photoshop not refreshing etc. and changing the priority to high (also with real time) fixed it.
    If you don’t see those process in the Task Manager:
    In the Processes tab, they have the names
    – Desktop Integration Process (32 bits)
    – Host Process (32 bits)

    You can check the detail and you will see that the location of those process are something like:
    C:\Program Files (x86)\Google\Chrome Remote Desktop\93.0.4577.8

    Right click on it and click on “Go to details”. It will switch you to the Task Manager Details tab.

    Alright now you see the exe files:
    – remoting_desktop.exe (the Desktop Integration Process (32 bits))
    – remoting_host.exe (the Host Process (32 bits))

    You can now right click and set the priority.

    But that too much work. Just run this with Powershell as admin:

    Get-WmiObject Win32_process -Filter ‘name=”remoting_host.exe”‘ | ForEach-Object {$_.SetPriority(128)}

    128 is High, 256 is real time

    And not sure if the second one is also needed:
    Get-WmiObject Win32_process -Filter ‘name=”remoting_desktop.exe”‘ | ForEach-Object {$_.SetPriority(128)}

    • Great work, thank you for your input!

    • Thanks a lot for this solution. However, I got an error when running the code as admin. The error message is:

      “Get-WmiObject : Invalid query “select * from Win32_process where name=”remoting_host.exe””
      At line:1 char:1
      + Get-WmiObject Win32_process -Filter ‘name=”remoting_host.exe”‘ | ForE …

      Any suggestions? Thanks again!

  88. Do you make these changes in the remote computer, the local computer, and/or both?

  89. It is EXTREMELY unlikely that my i9 is showing random CRD freezes because of the massive CPU load on the computer. (Rarely gets above 20%) Much more likely just to be countless Google software bugs.

  90. Hi, great job !
    as far as possible i also use blockMesh.
    but on question: sHM needs pure hex cells with asect ratio approx. 1. As your basemesh violates this criterion, due to the radial face growth, does sHM really work ? I have a similar problem and failed.

  91. Thanks for the material. I am getting issues with running delta p. Please have a look at the error. Also find my control dict code below. Any idea on how to resolve the issue.

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

    –> FOAM Warning :
    Unknown function type fieldValueDelta

    Valid function types :


    From static Foam::autoPtr<Foam::functionObject> Foam::functionObject::New(const Foam::word&, const Foam::Time&, const Foam::dictionary&)
    in file db/functionObjects/functionObject/functionObject.C at line 117.

    –> loading function object ‘delta_p’

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

    /——————————–– C++ –———————————-\
    | ========= | |
    | \ / F ield | OpenFOAM: The Open Source CFD Toolbox |
    | \ / O peration | Version: v2106 |
    | \ / A nd | Website: |
    | \/ M anipulation | |
    version 2.0;
    format ascii;
    class dictionary;
    location “system”;
    object controlDict;
    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

    application simpleFoam;

    startFrom latestTime;

    startTime 0;

    stopAt endTime;

    endTime 1.8;

    deltaT 0.003;

    writeControl timeStep;

    writeInterval 200;//100;

    purgeWrite 0;

    writeFormat ascii;

    writePrecision 6;

    writeCompression off;

    timeFormat general;

    timePrecision 6;

    runTimeModifiable true;

    “” // this is for forces

    //#includeFunc residuals

    type forces;
    //functionObjectLibs (""); //Found [v1612] 'functionObjectLibs' entry
    libs (""); //In new
    patches (impeller); // sum the forces and moments on those patches
    writeControl timeStep;
    writeInterval 1;
    p p;
    U U;
    log true;
    rhoInf 998.2;
    rho rhoInf;
    CofR (0 0 0.094289); //centreOfRotation

    type wallShearStress;
    libs ("");
    // Optional entries
    patches (impeller); // sum the forces and moments on those patch
    executeControl timeStep;
    writeControl writeTime;

    // pressure difference between inlet and outlet for head calculation
    type fieldValueDelta;
    libs (fieldFunctionObjects);
    operation subtract;

    type surfaceFieldValue;
    operation average;
    fields (p);
    writeFields no;
    regionType patch;
    name outlet;

    type surfaceFieldValue;
    operation average;
    fields (p);
    writeFields no;
    regionType patch;
    name inlet;
    // flow (is specified in 0/U but here it's added for an additional check)
    type surfaceFieldValue;
    libs ("");

    writeFields false;
    surfaceFormat foam;

    regionType patch;
    name outlet;

    operation areaIntegrate;


    // maximum values: maximum velocity should be around impeller circumferential velocity
    // difference between minimum pressure and inlet pressure is NPSH
    type fieldMinMax;
    libs ("");

    writeToFile no;
    log yes;
    location no;
    mode magnitude;
    fields (U p);


    // ************************************************************************* //

  92. I have made the suggested changes on both the local and remote machines.

    I have stopped ALL Google Chrome extensions with the exception of Remote Desktop on the remote machine.

    I have removed Chrome and the Chrome Remote Desktop from the remote machine and reinstalled same.

    I have utilized the remote desktop WITHOUT Chrome running on the remote machine to conserve usage.

    NOTHING has worked to stop the freezes. Seems a bit random and lasts anywhere from 15 seconds to over one minute.

    I’m ready to bag Chrome’s remote desktop and just purchase Remote PC. Life is too short to put up with Google and their software.

  93. Hi, it may well be caused by a slow uplink on the remotely accessed PC broadband line. If theuplink speed is less than 1 mbps this will be you problem. You then need to change a few parms in remoting_host.exe in Program files,X86,Google , Remote Desktop, x10….. Click: Compatibility Mode, Reduced Color, Run 640, then Change for all users, the run the ‘Compatibility Trouble Shooter’, then make sure it says ‘fixed’, then your in buisiness to overcome the slow uplink prob on remote PC. Good luck 🙂

  94. GPU! For me when the HDMI video cable is unplugged from the computer then everything lags like hell. As soon I connect the Video cable to GPU port then everything is perfect.
    Sounds like this is a bug between windows and google.

    • Yep! Same issue as Stryker. Another person borrowed my external monitor and unplugged the HDMI cable from the remote PC. Horrible performance ever since. Barely usable.

      • Hello. I was using only one monitor connected with an HDMI cable and since I connect another monitor with a display port I have had this issue. How can I solve it?

  95. I see. I use an old-fashion RGB connector and it used to work fine until July 17, 2022. I took the fancy screen with me. I will unplug the conflicting cable and see how it works. I will keep you guys posted, thanks!

  96. Hi! It is fixed now! I did not make any chages in my set up. Maybe this thread got to be known by the right people. Thank you Google / Microsoft!

  97. this works for me. thank you very much!

  98. I agree with Enrique. Without further corrections to any of the machines, the problem simply disappeared. Every so often there is a five second freeze with Outlook, but other than this, it works as advertised now.

    • Enrique García Franco

      Indeed, it is just a matter of restarting the remote computer. Windows allows remote use at the username-password screen with Wake on WAN.

      For that, one needs to have a stable internet connection and googling ‘wake on WAN”. It is set up at the BIOS.

      Wake on WAN is also safer than just leaving the PC on, because there is a password or code to be entered to use the computer