Dear Sir,
I have to integrate the USB HID keyboard using Mikro C Pro for ARM compiler with my product which is based on the STM32F429ZI MCU.
I have the hardware connections as per mentioned below:
USB DP - PA12 (104 pin number of MCU)
USB DM - PA11 (103 pin number of MCU)
USB VBUS - PA9 (101 pin number of MCU)
Power Switch - PD3 (117 GPIO pin of MCU) --> STMPS2151STR IC is used which EN High
The above mentioned hardware has been tested with the STM Cube IDE custom USB HID keyboard example and it is working fine.
Now I have to use the USB HID keyboard with the Mikroc so the example code (USB_Host_ARM - demo -> Examples ->ST-> HIDKeyboard) provided by mikro c has been modified accordingly but with no success. The clock setting used are attached herewith along with the modified code example (the same clock settings are working with the STMCUBE IDE).
The HIDEventHandler function is not called (verified using message display on GLCD or LED blink off) when keyboard is connected,disconnected or enumerated.
Please help me to find out the issue in the attached code since the product is in the production and I have to deliver it asap.
Your support in this regard will be highly appreciated.
USB HID Keyboard with stm32F429ZI MCU using mikro C Pro for ARM
USB HID Keyboard with stm32F429ZI MCU using mikro C Pro for ARM
- Attachments
-
- clocksetting.pdf
- (582.89 KiB) Downloaded 25 times
-
- USB_Host_ARM - demo.rar
- (1.48 MiB) Downloaded 32 times
Re: USB HID Keyboard with stm32F429ZI MCU using mikro C Pro for ARM
Hello,
It has been more than 5 days but I have not received any response from the Mikroe team.
I expect the better response from the mikroe team. It is very urgent task since we need to deliver it to the production asap.
It has been more than 5 days but I have not received any response from the Mikroe team.
I expect the better response from the mikroe team. It is very urgent task since we need to deliver it to the production asap.
-
- Posts: 136
- Joined: 02 Jan 2020 19:00
Re: USB HID Keyboard with stm32F429ZI MCU using mikro C Pro for ARM
I'm not from mikroe, sorry.
But five days ago I checked your config against the datasheet:
<VAL>$40023800:$1010080</VAL>
</VALUE0>
<VALUE1>
<VAL>$40023804:$3401204</VAL>
it looks right.
Also pay attention to
<Turn ON PSW and VBUS switches at SW12.7 and SW12.8 (board specific).>
https://download.mikroe.com/documents/f ... c-v102.pdf
PA10 - power switch
PA9 - VBUS
It will not work with PD3 - there are no source codes...
And pay attention to D1 and R40 in the schematic diagram.
But five days ago I checked your config against the datasheet:
<VAL>$40023800:$1010080</VAL>
</VALUE0>
<VALUE1>
<VAL>$40023804:$3401204</VAL>
it looks right.
Also pay attention to
<Turn ON PSW and VBUS switches at SW12.7 and SW12.8 (board specific).>
https://download.mikroe.com/documents/f ... c-v102.pdf
PA10 - power switch
PA9 - VBUS
It will not work with PD3 - there are no source codes...
And pay attention to D1 and R40 in the schematic diagram.
Re: USB HID Keyboard with stm32F429ZI MCU using mikro C Pro for ARM
Thank you for you reply.
I am using custom board designed own using the same circuit as described by Mikroe. The same hardware is working with the STMCUBE IDE.
As per your suggestion I have changed the PSW line to PA10 to turn on the switch as given below:
sfr sbit PSW at GPIOA_ODR.B10;
During the init function also turned on the switch by writing the following code. Since I am using STMPS2152STR (EN- Active High), so PSW will be on by writing 1.
PSW = 0;
Delay_ms(100);
PSW = 1;
After doing this the USB keyboard still is not enumerated/ Connected.
Please suggest any solution to this problem. It will be great help to us.
I am using custom board designed own using the same circuit as described by Mikroe. The same hardware is working with the STMCUBE IDE.
As per your suggestion I have changed the PSW line to PA10 to turn on the switch as given below:
sfr sbit PSW at GPIOA_ODR.B10;
During the init function also turned on the switch by writing the following code. Since I am using STMPS2152STR (EN- Active High), so PSW will be on by writing 1.
PSW = 0;
Delay_ms(100);
PSW = 1;
After doing this the USB keyboard still is not enumerated/ Connected.
Please suggest any solution to this problem. It will be great help to us.
- Attachments
-
- STMPS2151STR.JPG (50 KiB) Viewed 531 times
-
- circuitref.JPG (41.81 KiB) Viewed 531 times
-
- Posts: 136
- Joined: 02 Jan 2020 19:00
Re: USB HID Keyboard with stm32F429ZI MCU using mikro C Pro for ARM
And the mikroe library will successfully turn this off during initialization...
They have an active low. You can check the USB power with a voltmeter after initialization.
-
- Posts: 136
- Joined: 02 Jan 2020 19:00
Re: USB HID Keyboard with stm32F429ZI MCU using mikro C Pro for ARM
If it's not a secret, of course, I wonder how it ended...
-
- Posts: 158
- Joined: 24 May 2008 15:55
- Location: Germany
Re: USB HID Keyboard with stm32F429ZI MCU using mikro C Pro for ARM
GPIO_Alternate_Function_Enable(@_GPIO_MODULE_OTG_FS_PA89_10_11_12)
does the trick in Basic
does the trick in Basic
Re: USB HID Keyboard with stm32F429ZI MCU using mikro C Pro for ARM
Hello,
Can you please provide the working code example with your hardware so that I can compare it with my code and make it work.
I am stuck here since I have to provide this in the production code.
Please help us to resolve the issue.
Can you please provide the working code example with your hardware so that I can compare it with my code and make it work.
I am stuck here since I have to provide this in the production code.
Please help us to resolve the issue.
-
- Posts: 158
- Joined: 24 May 2008 15:55
- Location: Germany
Re: USB HID Keyboard with stm32F429ZI MCU using mikro C Pro for ARM
My project is not a tiny one (about 18000 lines) . I can only share the initiation routine. But you will not be happy with it. I am not too. But the problem is the library. ME never ever tested their library on arm. The device library works like a charm. But host library example is bad. Problem is the enumerating process. After enumerating it works very reliably, I have a 5ms timer interrupt that does (among other things) the USBHost_Main() function call. That works fine for a usb keyboard.
PS: If you find a better solution please post it.
greetings
The enumerating is successful only about every 2nd try. So i retry it after failure. The keyboard startup therefor takes some seconds. I can live with that. The logitech k400 wireless Keyboard starts best.PS: If you find a better solution please post it.
greetings
Re: USB HID Keyboard with stm32F429ZI MCU using mikro C Pro for ARM
Thank You Thomas for your reply..
But can you please eloborate how can I use the shared code since it is in the BashCoM language.
Can you please explain what are you trying to do by writing this code and where are you using it in the example code provided by mikroe.
Thank you for your support in this regard.
But can you please eloborate how can I use the shared code since it is in the BashCoM language.
Can you please explain what are you trying to do by writing this code and where are you using it in the example code provided by mikroe.
Thank you for your support in this regard.
-
- Posts: 158
- Joined: 24 May 2008 15:55
- Location: Germany
Re: USB HID Keyboard with stm32F429ZI MCU using mikro C Pro for ARM
Hi emb,
my code is in Mikro Basic not Bascom. There is no Bascom for ARM processors .
It should work with ME's HID Host example. But you should translate my code to C and delete all lines that are special for my project. The library functions have the same name in Mikro Basic as in Mikro C so there is not much difference. In Basic there is no need for semikolons (;). I expected you recognize that my code is a variant of mikroe code. The main difference is the order of library function calls. I have tested different orders and the one i use delivers the best result. It is far from perfect - i mentioned that it has to repeat the usb init several times. In Mikroe example there are only 4 or 5 lines that initialize the usb. I have an additional while loop that repeats the five steps when the usb does not enumerate. The other code of Me's example should work as is.
My project makes use of both roles of the usb. The device code is much more reliable.
I am sorry that I can only help with Basic code, but Mikro Basic is very C-like.
Greetings
my code is in Mikro Basic not Bascom. There is no Bascom for ARM processors .
It should work with ME's HID Host example. But you should translate my code to C and delete all lines that are special for my project. The library functions have the same name in Mikro Basic as in Mikro C so there is not much difference. In Basic there is no need for semikolons (;). I expected you recognize that my code is a variant of mikroe code. The main difference is the order of library function calls. I have tested different orders and the one i use delivers the best result. It is far from perfect - i mentioned that it has to repeat the usb init several times. In Mikroe example there are only 4 or 5 lines that initialize the usb. I have an additional while loop that repeats the five steps when the usb does not enumerate. The other code of Me's example should work as is.
My project makes use of both roles of the usb. The device code is much more reliable.
I am sorry that I can only help with Basic code, but Mikro Basic is very C-like.
Greetings
-
- Posts: 158
- Joined: 24 May 2008 15:55
- Location: Germany
Re: USB HID Keyboard with stm32F429ZI MCU using mikro C Pro for ARM
perhaps this is easier for you:
from HIDDevice_Keyboard_events_code.c
from HIDDevice_Keyboard_events_code.c
Code: Select all
// Initialise rest of MCU modules
void InitMcu() {
// Initialize SPI module
hidEvent = 255;
// Initialization of USB module
UART3_Init_Advanced(9600, _UART_8_BIT_DATA, _UART_NOPARITY, _UART_ONE_STOPBIT, &_GPIO_MODULE_USART3_PB10_11);
GPIO_Alternate_Function_Enable(&GPIO_MODULE_OTG_FS_PA89_10_11_12); <=========================== INSERT THIS LINE AND TEST EXAMPLE AGAIN
GPIO_Digital_Output(&GPIOA_BASE, _GPIO_PINMASK_10);
GPIO_Digital_Output(&GPIOD_BASE, _GPIO_PINMASK_3);
GPIO_Digital_Output(&GPIOF_BASE, _GPIO_PINMASK_13);
Glcd_Init(); // Initialize GLCD
Glcd_Set_Side(0); // set side GLCD
Glcd_Fill(0); // Clear Screen
PSW = 0;
ID=1;
Delay_ms(100);
PSW = 1; ID=0;
LED=1;
USBHost_HIDInit();
USBHost_RegisterDeviceEventHandler(HIDEventHandler);
USBHost_Init();
NVIC_IntEnable(IVT_INT_OTG_FS);
//Sound_Init(&GPIOE_ODR, 14);
}