cancel
Showing results for 
Search instead for 
Did you mean: 

How to use stm32f103 as usb hid (Assembly language) ? I want to learn everything about usb hid protocol...

YAY.1
Senior

Thanks for your replies,already.

1 ACCEPTED SOLUTION

Accepted Solutions

As predecesors says: It makes (almost) no sense to study USB (or any other protocols) from assembly language for specific CPU/microcontroller. But If you really want this:

I'm using gcc suite for building of projects, and there is a tool/binary named objdump, which is able disasembly of binary target and part of Makefile looks like:

#######################################
# binaries
#######################################
BINPATH = /opt/arm-tools/arm-none-eabi/bin
PREFIX = arm-none-eabi-
CC = $(BINPATH)/$(PREFIX)gcc
AS = $(BINPATH)/$(PREFIX)gcc -x assembler-with-cpp
CP = $(BINPATH)/$(PREFIX)objcopy
AR = $(BINPATH)/$(PREFIX)ar
SZ = $(BINPATH)/$(PREFIX)size
OBJDUMP = $(BINPATH)/$(PREFIX)objdump
HEX = $(CP) -O ihex
BIN = $(CP) -O binary -S
 
...
 
$(BUILD_DIR)/$(TARGET).uasm: $(BUILD_DIR)/$(TARGET).elf Makefile.linux
	$(OBJDUMP) -d $(BUILD_DIR)/$(TARGET).elf > $@

And result looks like (this is non related to USB_HID but USB_CDC/Serial Comm port)

08004380 <MX_USB_DEVICE_Init>:
 8004380:	b510      	push	{r4, lr}
 8004382:	4c09      	ldr	r4, [pc, #36]	; (80043a8 <MX_USB_DEVICE_Init+0x28>)
 8004384:	2200      	movs	r2, #0
 8004386:	4909      	ldr	r1, [pc, #36]	; (80043ac <MX_USB_DEVICE_Init+0x2c>)
 8004388:	4620      	mov	r0, r4
 800438a:	f004 fe1c 	bl	8008fc6 <USBD_Init>
 800438e:	4908      	ldr	r1, [pc, #32]	; (80043b0 <MX_USB_DEVICE_Init+0x30>)
 8004390:	4620      	mov	r0, r4
 8004392:	f004 fe2d 	bl	8008ff0 <USBD_RegisterClass>
 8004396:	4620      	mov	r0, r4
 8004398:	4906      	ldr	r1, [pc, #24]	; (80043b4 <MX_USB_DEVICE_Init+0x34>)
 800439a:	f004 fc40 	bl	8008c1e <USBD_CDC_RegisterInterface>
 800439e:	4620      	mov	r0, r4
 80043a0:	e8bd 4010 	ldmia.w	sp!, {r4, lr}
 80043a4:	f004 be2b 	b.w	8008ffe <USBD_Start>

View solution in original post

12 REPLIES 12
TDK
Guru

coding USB in assembly language seems like a bad choice. There are usb examples in the cube repositories.

If you feel a post has answered your question, please click "Accept as Solution".

Thanks for your opinon.

i know but i want to do with assembly language because i want to learn everything about usb hid.

Just i need, hid signature with assembly language for windows.

Ok, so what's stopping you reviewing the register level implementation, docs on HID classes (irrespective of the STM32), the C code, or disassembly thereof, and then coding in whatever language you want.

The learning here can be done via "doing" rather than "showing"

The mechanics of the hardware, interrupts and descriptors really isn't going to be any different.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thanks for reply.

But i want to make that with assembly.

Can i convert c program to assembly program ?

Or

How can i learn the protocol ?

YAY.1
Senior

0693W000001srSUQAY.pngJust i could not do this , How can i do this with assembly language ?

As predecesors says: It makes (almost) no sense to study USB (or any other protocols) from assembly language for specific CPU/microcontroller. But If you really want this:

I'm using gcc suite for building of projects, and there is a tool/binary named objdump, which is able disasembly of binary target and part of Makefile looks like:

#######################################
# binaries
#######################################
BINPATH = /opt/arm-tools/arm-none-eabi/bin
PREFIX = arm-none-eabi-
CC = $(BINPATH)/$(PREFIX)gcc
AS = $(BINPATH)/$(PREFIX)gcc -x assembler-with-cpp
CP = $(BINPATH)/$(PREFIX)objcopy
AR = $(BINPATH)/$(PREFIX)ar
SZ = $(BINPATH)/$(PREFIX)size
OBJDUMP = $(BINPATH)/$(PREFIX)objdump
HEX = $(CP) -O ihex
BIN = $(CP) -O binary -S
 
...
 
$(BUILD_DIR)/$(TARGET).uasm: $(BUILD_DIR)/$(TARGET).elf Makefile.linux
	$(OBJDUMP) -d $(BUILD_DIR)/$(TARGET).elf > $@

And result looks like (this is non related to USB_HID but USB_CDC/Serial Comm port)

08004380 <MX_USB_DEVICE_Init>:
 8004380:	b510      	push	{r4, lr}
 8004382:	4c09      	ldr	r4, [pc, #36]	; (80043a8 <MX_USB_DEVICE_Init+0x28>)
 8004384:	2200      	movs	r2, #0
 8004386:	4909      	ldr	r1, [pc, #36]	; (80043ac <MX_USB_DEVICE_Init+0x2c>)
 8004388:	4620      	mov	r0, r4
 800438a:	f004 fe1c 	bl	8008fc6 <USBD_Init>
 800438e:	4908      	ldr	r1, [pc, #32]	; (80043b0 <MX_USB_DEVICE_Init+0x30>)
 8004390:	4620      	mov	r0, r4
 8004392:	f004 fe2d 	bl	8008ff0 <USBD_RegisterClass>
 8004396:	4620      	mov	r0, r4
 8004398:	4906      	ldr	r1, [pc, #24]	; (80043b4 <MX_USB_DEVICE_Init+0x34>)
 800439a:	f004 fc40 	bl	8008c1e <USBD_CDC_RegisterInterface>
 800439e:	4620      	mov	r0, r4
 80043a0:	e8bd 4010 	ldmia.w	sp!, {r4, lr}
 80043a4:	f004 be2b 	b.w	8008ffe <USBD_Start>

Thanks for reply.

Unfortunately, i can't download uvison and stmcube now but i will try.

Is there another way to learn protocol?

https://stm32f4-discovery.net/2014/09/library-34-stm32f4-usb-hid-device/

I will try to make this library with assembly language.

I'd recommend becoming very familiar with http://www.usbmadesimple.co.uk/
If you feel a post has answered your question, please click "Accept as Solution".