Forum > Embedded - ARM

blue pill usb hid etc etc [SOLVED]

(1/4) > >>

diego bertotti:
hi

i try to reuse the serrasidis usb hid bootloader in my project.

https://github.com/Serasidis/STM32_HID_Bootloader

bootloader works perfectly!!

i do a little mod in a led unit and works perfect

now i try to reuse the C object files compiled from the hid bootloader, to have usb communication between uC and windows PC .

now uC don't hang but usb host don't recognise it...remember the same code works perfect in the bootloader. actually i burn the flash using it (and compiling using $800 offset)

i dont found why

now a piece of code


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- program something; uses cortexm3, stm32f103fw;  Procedure USB_Init; cdecl; external name'USB_Init';Procedure USB_Shutdown; cdecl; external name'USB_Shutdown';Procedure USB_SendData(EndPoint: byte; var data: word; Lenght: word); cdecl; external name'USB_SendData';Procedure USB_PMA2Buffer(endpoint: byte); cdecl; external name'USB_PMA2Buffer';Procedure USB_Buffer2PMA(endpoint: byte); cdecl; external name'USB_Buffer2PMA';Procedure USB_LP_CAN1_RX0_IRQHandler; cdecl; external name 'USB_LP_CAN1_RX0_IRQHandler';Procedure Pins_Init; cdecl; external name'pins_init';Procedure Pin13_One; cdecl; external name'pin13_one';Procedure Pin13_Cero; cdecl; external name'pin13_cero';  Procedure Pin13(status: byte); cdecl; external name'pin13';Procedure USB_EPHandler(status: word);cdecl; external name'USB_EPHandler'; Procedure USB_Reset; cdecl; external name'USB_Reset'; {$L c:\hidboot\f1\build\usb.o}{$L c:\hidboot\f1\build\hid.o}{$L c:\hidboot\f1\build\flash.o}{$L c:\hidboot\f1\build\led.o}  const  MAX_BUFFER_SIZE = 64;  MAX_EP_NUM = 2;   {$O-} Type   TLed = bitpacked array[0..15] of boolean;   USB_RxTxBuf_t = record        RXB: array[0..MAX_BUFFER_SIZE div 2] of word;        PTXB: word;        RXL: byte;        TXL: byte;        MaxPacketSize: byte;  end;   var DeviceConfigured: word; external name 'DeviceConfigured';DeviceAddress: byte; external name 'DeviceAddress';DeviceStatus: word; external name 'DeviceStatus';UploadStarted: boolean; external name 'UploadStarted';UploadFinished: boolean; external name 'UploadFinished';RxTxBuffer: array[0..MAX_EP_NUM] of USB_RxTxBuf_t; external; PuertoA : TLed absolute PortA.ODR;PuertoB : TLed absolute PortB.ODR;PuertoC : TLed absolute PortC.ODR;PuertoD : TLed absolute PortD.ODR;LedB : TLed absolute PortB.ODR;LedC : TLed absolute PortC.ODR;contador: word;contador2,contador3: word;cuenta_max: word = 20;subiendo: boolean = true;  procedure USB_Low_Priority_or_CAN_RX0_interrupts; public name 'USB_Low_Priority_or_CAN_RX0_interrupts';  interrupt;    begin    USB_LP_CAN1_RX0_IRQHandler;    USB.ISTR:= 0;    end; begin  //************************************************ //**************** RCC  ************************* RCC_HSICmd(Enabled); RCC_DeInit; RCC_HSICmd(Enabled); RCC_HSEConfig(RCC_HSE_On); RCC_WaitForHSEStartUp;  RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_6); //48MHz RCC_PLLCmd(Enabled);   while rcc.cr and  RCC_CR_PLLRDY = 0 do    begin    //wait pll ready    end; RCC_HCLKConfig(RCC_SYSCLK_Div1); RCC_PCLK1Config(RCC_HCLK_Div2); //24MHz RCC_PCLK2Config(RCC_HCLK_Div1); //48MHz RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); while RCC_GetSYSCLKSource <> %1000 do //(RCC_SYSCLKSource_PLLCLK shl 2)   begin   //wait pll source   end; RCC_AHBPeriphClockCmd( RCC_AHBPeriph_DMA1 or RCC_AHBPeriph_DMA2 or RCC_AHBPeriph_SRAM or RCC_AHBPeriph_FLITF, Enabled); RCC_APB2PeriphClockCmd(RCC_APB2Periph_ALL, Enabled); RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, Disabled); RCC_APB1PeriphClockCmd(RCC_APB1Periph_ALL, Enabled); RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2 or RCC_APB1Periph_I2C2 or RCC_APB1Periph_CAN, Disabled); RCC_ADCCLKConfig(RCC_PCLK2_Div8);  //6 MHz RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_Div1); //48MHz RCC_ClockSecuritySystemCmd(Enabled); RCC_GetClocksFreq(RCC_Clocks);    //***************************************************  //******************** Systick **********************  Systick.LOAD:= 6000;   // 1ms main loop  SysTick.CTRL := SysTick.CTRL or CTRL_TICKINT_Set AND (not 4);// interrupt, AHB/8  SysTick.CTRL := SysTick.CTRL or systick_counter_enable ; //enabled   contador:= cuenta_max - 2;   USB_Init;  while true do    begin    If marca then      begin      marca:= False;      Inc(Contador);      Inc(Contador_tick_Segundos);     If Contador_tick_segundos >= 10 then  //1seg        begin        Contador_tick_segundos:= 0;        end;    if contador <= contador2 then LedC[13] := not LedC[13] else LedC[13] := true;    if contador >= cuenta_Max then      begin      contador := 0;      if subiendo then contador2 += 2 else contador2 -= 2;      if contador2 > Cuenta_max then subiendo:= false;      if contador2 = 0 then subiendo:= true;      end;    end;    end; end.        
somebody can help me?

thanks

MiR:
I have close to no experince with USB, so sorry, cannot help much...

Nevertheless two hints:

https://github.com/hathach/tinyusb

looks very portable and is used by big Projects like MicroPython and Circuitpython, perhaps a good choice for using a C-Stack for USB.

There is however a properly more simple solution, have a look at

https://libopencm3.org/

and

https://github.com/libopencm3/libopencm3-examples/tree/master/examples/stm32/f1/stm32-maple/usb_cdcacm

for an example

they have low level examples for USB and code is usually not that complicated.

From what I know (which is very,very little) you must call some usb specific callbacks from time to time to be able to properly communicate. The example above does this in main loop

diego bertotti:
hi MiR

thanks for reply


--- Quote ---From what I know (which is very,very little) you must call some usb specific callbacks from time to time to be able to properly communicate. The example above does this in main loop

--- End quote ---

this is why i want to "reuse" this code. i know its working!

Laksen:
Shameless plug: https://github.com/laksen/fp-usb ;)

It needs a simpler example than the ACM class device. Maybe USB-DFU would make sense. It's pretty widely supported and a simple HID like EP0 interface

diego bertotti:
thanks laksen ....ill try it

Navigation

[0] Message Index

[#] Next page

Go to full version