USB HID Keyboard with stm32F429ZI MCU using mikro C Pro for ARM

General discussion on mikroC PRO for ARM.
Post Reply
Author
Message
emb
Posts: 8
Joined: 20 Feb 2020 10:01

USB HID Keyboard with stm32F429ZI MCU using mikro C Pro for ARM

#1 Post by emb » 30 Jan 2024 07:18

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.
Attachments
clocksetting.pdf
(582.89 KiB) Downloaded 22 times
USB_Host_ARM - demo.rar
(1.48 MiB) Downloaded 31 times

emb
Posts: 8
Joined: 20 Feb 2020 10:01

Re: USB HID Keyboard with stm32F429ZI MCU using mikro C Pro for ARM

#2 Post by emb » 07 Feb 2024 11:58

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.

AntiMember
Posts: 136
Joined: 02 Jan 2020 19:00

Re: USB HID Keyboard with stm32F429ZI MCU using mikro C Pro for ARM

#3 Post by AntiMember » 07 Feb 2024 16:02

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.

emb
Posts: 8
Joined: 20 Feb 2020 10:01

Re: USB HID Keyboard with stm32F429ZI MCU using mikro C Pro for ARM

#4 Post by emb » 08 Feb 2024 12:59

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.
Attachments
STMPS2151STR.JPG
STMPS2151STR.JPG (50 KiB) Viewed 505 times
circuitref.JPG
circuitref.JPG (41.81 KiB) Viewed 505 times

AntiMember
Posts: 136
Joined: 02 Jan 2020 19:00

Re: USB HID Keyboard with stm32F429ZI MCU using mikro C Pro for ARM

#5 Post by AntiMember » 08 Feb 2024 19:30

emb wrote:
08 Feb 2024 12:59
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;
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.

AntiMember
Posts: 136
Joined: 02 Jan 2020 19:00

Re: USB HID Keyboard with stm32F429ZI MCU using mikro C Pro for ARM

#6 Post by AntiMember » 15 Feb 2024 17:54

If it's not a secret, of course, I wonder how it ended...

Thomas.Pahl@t-online.de
Posts: 158
Joined: 24 May 2008 15:55
Location: Germany

Re: USB HID Keyboard with stm32F429ZI MCU using mikro C Pro for ARM

#7 Post by Thomas.Pahl@t-online.de » 16 Feb 2024 11:37

GPIO_Alternate_Function_Enable(@_GPIO_MODULE_OTG_FS_PA89_10_11_12)

does the trick in Basic

emb
Posts: 8
Joined: 20 Feb 2020 10:01

Re: USB HID Keyboard with stm32F429ZI MCU using mikro C Pro for ARM

#8 Post by emb » 19 Feb 2024 06:47

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.

Thomas.Pahl@t-online.de
Posts: 158
Joined: 24 May 2008 15:55
Location: Germany

Re: USB HID Keyboard with stm32F429ZI MCU using mikro C Pro for ARM

#9 Post by Thomas.Pahl@t-online.de » 19 Feb 2024 14:42

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.
USB_Host_init.zip
(1.06 KiB) Downloaded 12 times
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

emb
Posts: 8
Joined: 20 Feb 2020 10:01

Re: USB HID Keyboard with stm32F429ZI MCU using mikro C Pro for ARM

#10 Post by emb » 27 Feb 2024 09:35

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.

Thomas.Pahl@t-online.de
Posts: 158
Joined: 24 May 2008 15:55
Location: Germany

Re: USB HID Keyboard with stm32F429ZI MCU using mikro C Pro for ARM

#11 Post by Thomas.Pahl@t-online.de » 27 Feb 2024 16:39

Hi emb,

my code is in Mikro Basic not Bascom. There is no Bascom for ARM processors :D .

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

Thomas.Pahl@t-online.de
Posts: 158
Joined: 24 May 2008 15:55
Location: Germany

Re: USB HID Keyboard with stm32F429ZI MCU using mikro C Pro for ARM

#12 Post by Thomas.Pahl@t-online.de » 27 Feb 2024 18:11

perhaps this is easier for you:

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);
  }

Post Reply

Return to “mikroC PRO for ARM General”