2013-06-29 12:22 PM
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-device2013-06-30 10:47 PM
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]2013-07-01 05:20 AM
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?2013-07-01 10:38 AM
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.2013-07-01 12:30 PM
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.
2013-07-01 12:41 PM
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?
2013-07-01 12:51 PM
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 RAM2013-07-01 01:19 PM
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 modeDo 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}2013-07-01 02:07 PM
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.