2

I`m trying to create custom HID device with STM32F103C8, IDE that i choose is STM32CubeIDE and the tutorial that i was following is at ST youtube official channel.

ST offers great tool "Device configuration tool" where i can configure microcontroler, and a lot of code based on my configuration will be generated. That generated code has "user code parts" where user creates his logic, and if he needs to reconfigure microcontroller "Device configuration tool" will not remove that parts of code.

Problem: To configure custom usb HID i need to change code generated by "Device configuration tool" in places where is no place for user code and that changes will be removed if i run "Device configuration tool" again. Fields that i only can set in "Device configuration tool" are this: enter image description here

But that is not enough i also need to change CUSTOM_HID_EPIN_SIZE and CUSTOM_HID_EPOUT_SIZE defines which represent amount of bytes device and host send to each other at once, and also if i change the size of "data pack" i will need to change the default generated callback function that receives that data and works with it, for example the tool generates code like this:

{
  USBD_CUSTOM_HID_HandleTypeDef     *hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassData;

  if (hhid->IsReportAvailable == 1U)
  {
    ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->OutEvent(hhid->Report_buf[0],
                                                              hhid->Report_buf[1]);
    hhid->IsReportAvailable = 0U;
  }
  return USBD_OK;
}

but i need the pointer to "Report_buf" not the copy of its first 2 elements, and the default generated code pass only copy of 2 first bytes, and i cant change this in "Device configuration tool".

My current solution: Actually i solved this issue, but i don`t think i solved it the right way and it works. I have changed the template files which are here "STM32CubeIDE_1.3.0\STM32CubeIDE\plugins\com.st.stm32cube.common.mx_5.6.0.202002181639\db\templates" And also changed files at "STM32CubeIDE_1.3.0\en.stm32cubef1.zip_expanded\STM32Cube_FW_F1_V1.8.0\Middlewares\ST\STM32_USB_Device_Library\Class\HID"

I don`t think this is the right way to do it, does any one know the right way to do this thing ?

I also found same question on ST forum here but it was not resolved.

PuFF1k
  • 303
  • 4
  • 13

2 Answers2

0

what you want to achieve is exactly what is explained by st trainer on this link. https://www.youtube.com/watch?v=3JGRt3BFYrM

Trainer is step by step explaining how to change the code to use the pointer to buffer

if (hhid->IsReportAvailable == 1U)
  {
    ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->OutEvent(hhid->Report_buf);
    hhid->IsReportAvailable = 0U;
  }
yasirateeq857
  • 19
  • 1
  • 6
  • The trainer made changes in header file as well as in the function parameters and add pointer to buffer in the function argument . – yasirateeq857 Aug 27 '21 at 09:46
0

I had the same issue where the generated code writes over the changes and its a pain to fix. My solution is have the project in a git repo. Once everything is as you like commit and push the changes. After generation, you only need to run git restore on the affected files.