cancel
Showing results for 
Search instead for 
Did you mean: 

SET_REPORT USB HID class request for STM32

patil
Associate II
Posted on February 10, 2016 at 15:43

I am developing a USB keyboard application using STM32F103 microcontroller. I have written code using a demo example to send keys to the host.

But I am not able to figure out how to write set_report request for turning on CAPS/NUM lock led when the key is pressed.

Can anybody tell me how to write C code for it?

0

http://stackoverflow.com/questions/35317960/set-report-hid-class-request-for-stm32♯

I am developing a USB keyboard application using STM32F103 microcontroller. I have written code using a demo example to send keys to the host.

But I am not able to figure out how to write set_report request for turning on CAPS/NUM lock led when the key is pressed.

Can anybody tell me how to write C code for it?

0

http://stackoverflow.com/questions/35317960/set-report-hid-class-request-for-stm32♯

I am developing a USB keyboard application using STM32F103 microcontroller. I have written code using a demo example to send keys to the host.

But I am not able to figure out how to write set_report request for turning on CAPS/NUM lock led when the key is pressed.

Can anybody tell me how to write C code for it?

0

http://stackoverflow.com/questions/35317960/set-report-hid-class-request-for-stm32♯

I am developing a USB keyboard application using STM32F103 microcontroller. I have written code using a demo example to send keys to the host.

But I am not able to figure out how to write set_report request for turning on CAPS/NUM lock led when the key is pressed.

Can anybody tell me how to write C code for it?

0

http://stackoverflow.com/questions/35317960/set-report-hid-class-request-for-stm32♯

I am developing a USB keyboard application using STM32F103 microcontroller. I have written code using a demo example to send keys to the host.

But I am not able to figure out how to write set_report request for turning on CAPS/NUM lock led when the key is pressed.

Can anybody tell me how to write C code for it?

#usb-hid #usb
3 REPLIES 3
tsuneo
Senior
Posted on February 12, 2016 at 06:07

> using STM32F103 microcontroller.

> using a demo example

> Can anybody tell me how to write C code for it?

Where the ''demo example'' comes from?

There are tons of  ''demo examples'', which have their own way to implement the USB stack.

Specify the library name and its version, if you want exact advice to write your C code.

Also, the name of the compiler and its version, too.

Tsuneo

patil
Associate II
Posted on February 21, 2016 at 07:12

Hi,

Thanks for your reply,

I have a STM32 Performance Stick based on STM32f103rbt6 microcontroller from Hitex, and I use HiTop5 IDE(full license) provided by them with Tasking C compiler

for Cortex V2.0r2.

They have provided a USB mouse demo example with it. I have changed the code to work as a USB keyboard with the help of your post in the SiLabs forum.

I am correctly able to send key values to the host. Now I want to set the led's on the device when CAPS/NUM lock keys are pressed. But the demo example given doesn't have a SET_REPORT request function and I am not able to understand and write it on my own.

I have attached the usb_prop file which contains the USB Standard and HID class specific request functions.

I will be glad if you could help.

________________

Attachments :

usb_prop.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0vl&d=%2Fa%2F0X0000000bge%2F65Dz3gvYLFKt8rlU8vl4NQdsTyxjsa1vDol7r6Ly_lw&asPdf=false
tsuneo
Senior
Posted on February 21, 2016 at 17:14

> I have a STM32 Performance Stick based on STM32f103rbt6 microcontroller from Hitex

It's Hitex STM3210B-PFSTICK. I'm not sure about the USB stack included in this kit, but I suppose it was ST's USBlib 1.0 (old STM32_USB-FS-Device_Lib). In this stack, implementation of Control Write Transfer (including Set_Report request) is tricky, because the stack programmer didn't prepare for it well. Add these declarations to usb_prop.c

usb_prop.c
/* Private variables ---------------------------------------------------------*/
u8 lastRequest = 0;
u8 outReportBuf;
/* Private function prototypes -----------------------------------------------*/
static u8 *HID_Set_Report(u16 Length);

In HID_Data_Setup() routine, insert SET_REPORT handling after GET_PROTOCOL process

RESULT HID_Data_Setup(u8 RequestNo)
{
u8 *(*CopyRoutine)(u16);
CopyRoutine = NULL;
if ((RequestNo == GET_DESCRIPTOR)
&& (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))
&& (pInformation->USBwIndex0 == 0))
{
...
} /* End of GET_DESCRIPTOR */
/*** GET_PROTOCOL ***/
else if ((Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT))
&& RequestNo == GET_PROTOCOL)
{
...
}
// <----------- insert these lines, from here
/*** SET_REPORT ***/
else if ((Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT))
&& RequestNo == SET_REPORT)
{
CopyRoutine = HID_Set_Report;
lastRequest = SET_REPORT;
}
// <----------- insert these lines, to here
if (CopyRoutine == NULL)
{
return USB_UNSUPPORT;
}
pInformation->Ctrl_Info.CopyData = CopyRoutine;
pInformation->Ctrl_Info.Usb_wOffset = 0;
(*CopyRoutine)(0);
return USB_SUCCESS;
}

Add the body of HID_Set_Report() routine,

static u8 *HID_Set_Report(u16 Length)
{
if (Length == 0)
{
pInformation->Ctrl_Info.Usb_wLength = sizeof(outReportBuf);
return NULL;
}
return (u8 *)&outReportBuf;
}

Lastly, modify HID_Status_In() routine. This routine is called by the stack at the Status stage of Control Write and No-data Control transfers. Just when ''lastRequest'' is SET_REPORT, outReportBuf should be filled at the Data stage before this Status stage (tricky coding). Light/down the LEDs, according to the bitmap on outReportBuf, in this routine.

void HID_Status_In(void)
{
if (lastRequest == SET_REPORT)
{
//
// here, flip LEDs according to the bitmap on outReportBuf
//
lastRequest = 0;
}
}

Tsuneo