cancel
Showing results for 
Search instead for 
Did you mean: 

USB HID Mouse Device on STM32f4discovery

guitardenver
Associate II
Posted on June 29, 2013 at 21:22

I want to make the STM32f4discovery a usb HID mouse. I have been googling and researching for a couple days now and am just overwhelmed with code I don't understand enough to be able to use it. 

I am using Keil uVision4 IDE. Windows 7 on PC side.

Is there a library that I can just call something like USB_init( x,y,z) and then pass a function with some coordinates to move the mouse?

Or does anybody know of some step by step examples/tutorial to get usb HID class libraries to compile and work? Or just any examples already made for the STM32f4discovery?

My st board came with a USB mouse example with the accelerometer. I can't seem to find that again. Anybody know where I can download that?

Thanks for the advice

#usb-hid-mouse-device
8 REPLIES 8
guitardenver
Associate II
Posted on July 01, 2013 at 07:47

Ok so I found the demo example. But when I tried to replicate the demo it has a fault. It gets stuck at the line '' BX      R0'' It never gets to the main function.

[code]

Reset_Handler    PROC

                 EXPORT  Reset_Handler             [WEAK]

        IMPORT  SystemInit

        IMPORT  __main

                 LDR     R0, =SystemInit

                 BLX     R0

                 LDR     R0, = __main

                 BX      R0

                 ENDP

[/code]

Posted on July 01, 2013 at 14:20

As that's standard Keil startup code, I think we can safely look elsewhere for the problem.

Do you have the right HSE_VALUE defined in the project, and PLL settings in system_stm32f4xx.c? Remember the Discovery board has an 8 MHz external crystal, the EVAL boards typically have 25 MHz.

The routine being called here is the C runtime code's startup and initialization code for the statics (copy, zero), and subsequently calls your main() routine.

What's happening? Are you getting a Hard Fault, can you step into the code?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
guitardenver
Associate II
Posted on July 01, 2013 at 19:38

The demo code is the code that was made for the board I purchased. The project that I downloaded works just fine. But what I did is tried to duplicate the project with the same files and same everything so I can change the copy and not the original. The HSE is at 8Mhz. Core clock is at 168Mhz.

Yes, It does end up in the Hard_Fault handler. What does that mean? I step through the code using the ''step one line'' and it freezes at the line ''BX      R0''. Then I hit the ''Stop Code Execution Button'' and it jumps to the hard fault handler.

Posted on July 01, 2013 at 21:30

What value does R0 contain? It will need to point to a usable memory area, and not EVEN as this denotes 32-bit ARM code which is not executable by the STM32.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
guitardenver
Associate II
Posted on July 01, 2013 at 21:41

At the ''BX  R0'' line when it freezes R0 contains 0x8000189 and when I hit stop and it jumps to the while(1) loop in the handler it contains 0x03000000. Just out of curiosity, what is R0?

Posted on July 01, 2013 at 21:51

R0 is Register 0, the ARM architecture has 16 32-bit registers, R0 .. R15, some may also be named R15=PC, R14=LR, R13=SP

You shouldn't have to stop it, you want to ''Step In'' and follow the execution.

The value for R0 seems reasonable. You might want to consider what SystemInit() is configuring with respect to the clocks, pll, buses and flash. Check also the value for SP/R13, it needs to point to RAM
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
guitardenver
Associate II
Posted on July 01, 2013 at 22:19

Ok I used a different version of the system_stm32f4xx.c made on 30-september-2011 as opposed to the one I was using made on 19-september-2011. And it works!

30-sept

-------------------------------------------------

  *        PLLI2S_N                               | 192

  *-----------------------------------------------------------------------------

  *        PLLI2S_R                               | 5

  *-----------------------------------------------------------------------------

  *        I2S input clock(Hz)                    | 38400000

  *-----------------------------------------------------------------------------

  *        VDD(V)                                 | 3.3

  *-----------------------------------------------------------------------------

  *        High Performance mode                  | Enabled

-------------------------------------------------------------------------

19-sept

  *-----------------------------------------------------------------------------

  *        PLLI2S_N                               | NA

  *-----------------------------------------------------------------------------

  *        PLLI2S_R                               | NA

  *-----------------------------------------------------------------------------

  *        I2S input clock                        | NA

  *-----------------------------------------------------------------------------

  *        VDD(V)                                 | 3.3

  *-----------------------------------------------------------------------------

  *        Main regulator output voltage          | Scale1 mode

Do you think any of these setting made a difference?

Here is the Init function for the 19-sept version: And the R13 value is 0x020000ED8. And I cant ''step in'' the only options are ''Step one line'', ''step over the current line'', ''step out of the current function'', and ''run to the current cursor position''. all of these freeze at the ''BX  R0'' line and does not show how it gets to the fault handler. It's weird that I have the same system_stm32f4xx.c file as the demo project that works. 

void SystemInit(void)

{

  /* Reset the RCC clock configuration to the default reset state ------------*/

  /* Set HSION bit */

  RCC->CR |= (uint32_t)0x00000001;

  /* Reset CFGR register */

  RCC->CFGR = 0x00000000;

  /* Reset HSEON, CSSON and PLLON bits */

  RCC->CR &= (uint32_t)0xFEF6FFFF;

  /* Reset PLLCFGR register */

  RCC->PLLCFGR = 0x24003010;

  /* Reset HSEBYP bit */

  RCC->CR &= (uint32_t)0xFFFBFFFF;

  /* Disable all interrupts */

  RCC->CIR = 0x00000000;

#ifdef DATA_IN_ExtSRAM

  SystemInit_ExtMemCtl(); 

#endif /* DATA_IN_ExtSRAM */

         

  /* Configure the System clock source, PLL Multiplier and Divider factors, 

     AHB/APBx prescalers and Flash settings ----------------------------------*/

  SetSysClock();

  /* Configure the Vector Table location add offset address ------------------*/

#ifdef VECT_TAB_SRAM

  SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */

#else

  SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */

#endif

}

Posted on July 01, 2013 at 23:07

It's weird that I have the same system_stm32f4xx.c file as the demo project that works.

Only in so far as there is stuff in the options and settings which are quite important here. Do you have the FPU Enabled (Use FPU)? Try adding these lines in the front of SystemInit()

/* FPU settings ------------------------------------------------------------*/
SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */

The help mouse-over probably says ''Step'', but look at the icons, Step In, Step Over, Step Out, and where the arrows go. If stepping in Hard Faults, then you'll need to look at the assembler code at the __main location in the disassembler view.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..