Daha önce STM32F10X de USB HID çalıştıran oldumu.
Şuradaki ST'nin UM0424 kodlu kütüphanesini indiriyorum.
http://www.st.com/web/en/catalog/tools/PF258157# (http://www.st.com/web/en/catalog/tools/PF258157#)
Ama kütüphaneyi ekleyemedim bir türlü kendi projeme. bir sürü hata alıyorum. Kütüphaneyi eklemek için izleyebileceğim bir klavuz varmı? Veya STM32F103 için yazılmış bir örnek program olsa çok güzel olacak.
MikroC altinda hid kullandim stm32f103c8 ile.
MikroC olmaz hocam keil kullanıyorum.
32f407 discovery kitinde usb hid örnekleri var indirip inceleyebilirisiniz.
Hocam benzer örnekler stm32f10x icinde var. Aslinda Stm32f10x için indirdiğim usb kutuphanesinin içindeki örneklere bakıyorum. Bu örnekleri benim projeye dahil etmeye çalışıyorum. Fakat bu kodlar stnin eval boardlari için hazırlanmış. Farklı model işlemciler için hazirlandigindan benim stm32f103ve de zilyon tane hata alıyorum. Şöyle herhangi bir board için özel olarak hazırlanmamış örnek varmı. USB HID uygulaması yapacam
ST'nin USB library'si içerisindeki USB Joystick Mouse örneğinden yola çıkarak kütüphaneyi kendime göre sadeleştirmeye çalıştım. Orjinal uygulamada ST'nin kendi EVALboardları için tanımlamalar vardı. Hatalarınbüyük bir kısmı bunlardanmış. Bunları kendi programıma göre düzenledim. En son bir hata veriyor çözemedim. Hata metni budur.
Alıntı Yaplinking...
.\Objects\USB_Test.axf: Error: L6200E: Symbol NOP_Process multiply defined (by usb_endp.o and usb_core.o).
Not enough information to list image symbols.
Not enough information to list the image map.
Finished: 2 information, 0 warning and 1 error messages.
".\Objects\USB_Test.axf" - 1 Error(s), 0 Warning(s).
Target not created.
Buradaki hatayı çözemedim bir türlü. usb_core.c içerisinde NOP_Process adında bir fonksiyon var. Ama fonksiyon tanımlamasında vs bir hata yok. Dün bayağı uğraştım ama bir türlü hatayı gideremedim. Yeterli bilgi yok diyor? Nereyi bilgilendireceğim anlamadım. Fikri olan varmı?
Hatada yazdığı gibi, bir tane de usb_endp.c içinde varmış. O dosyayı bir inceleyin.
bir header dosyasını iki kez include yapmaktan olabilirmi o hata?
mesaj birleştirme:: 08 Temmuz 2015, 11:14:31
usb_core.h dosyasında fonksiyon prototipinin başına extern ekleyin bakalım hata gidecekmi?
Evet aslında dolaylı olarak ondanmış.
Aslında usb_endp. içerisine ben kendim EP1_OUT_Callback fonksiyonunu ekledim. Normalde usb_endp.c içerisinde NOP_Process fonksiyonuna yönelik bir tanımlama yokmuş. Herneyse Projenin tümünde NOP_Process kelimesini arattım. Sonunda usb_conf.h aşağıdaki tanımlamaları farkettim.
/* CTR service routines */
/* associated to defined endpoints */
//#define EP1_IN_Callback NOP_Process*/
#define EP2_IN_Callback NOP_Process
#define EP3_IN_Callback NOP_Process
#define EP4_IN_Callback NOP_Process
#define EP5_IN_Callback NOP_Process
#define EP6_IN_Callback NOP_Process
#define EP7_IN_Callback NOP_Process
//#define EP1_OUT_Callback NOP_Process
#define EP2_OUT_Callback NOP_Process
#define EP3_OUT_Callback NOP_Process
#define EP4_OUT_Callback NOP_Process
#define EP5_OUT_Callback NOP_Process
#define EP6_OUT_Callback NOP_Process
#define EP7_OUT_Callback NOP_Process
usb_endp.c içerisinde hangi fonksiyonu tanımlarsan yukarıdaki kodlarda o fonksiyona ait satırı kapatmak gerekiyormuş. Bende EP1_IN_Callback tanımlıydı. EP1_OUT_Callback fonksiyonunuda kendim kapatınca hatasız derlendi.
Şimdi Başka bir problem var. USB kütüphanesinin nasıl kullanılacağını bilmiyorum. usb_prob.c dosyası var. Kütüphaneyi USB_Mouse Joystick programından aldığım için usb_prop.c içerisinde ona mouse için gerekli tanımlamalar var
/**
******************************************************************************
* @file usb_prop.c
* @author MCD Application Team
* @version V4.0.0
* @date 21-January-2013
* @brief All processing related to Joystick Mouse Demo
******************************************************************************
* @attention
*
* <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "usb_lib.h"
#include "usb_conf.h"
#include "usb_prop.h"
#include "usb_desc.h"
#include "usb_pwr.h"
#include "hw_config.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
uint32_t ProtocolValue;
/* -------------------------------------------------------------------------- */
/* Structures initializations */
/* -------------------------------------------------------------------------- */
DEVICE Device_Table =
{
EP_NUM,
1
};
DEVICE_PROP Device_Property =
{
Joystick_init,
Joystick_Reset,
Joystick_Status_In,
Joystick_Status_Out,
Joystick_Data_Setup,
Joystick_NoData_Setup,
Joystick_Get_Interface_Setting,
Joystick_GetDeviceDescriptor,
Joystick_GetConfigDescriptor,
Joystick_GetStringDescriptor,
0,
0x40 /*MAX PACKET SIZE*/
};
USER_STANDARD_REQUESTS User_Standard_Requests =
{
Joystick_GetConfiguration,
Joystick_SetConfiguration,
Joystick_GetInterface,
Joystick_SetInterface,
Joystick_GetStatus,
Joystick_ClearFeature,
Joystick_SetEndPointFeature,
Joystick_SetDeviceFeature,
Joystick_SetDeviceAddress
};
ONE_DESCRIPTOR Device_Descriptor =
{
(uint8_t*)Joystick_DeviceDescriptor,
JOYSTICK_SIZ_DEVICE_DESC
};
ONE_DESCRIPTOR Config_Descriptor =
{
(uint8_t*)Joystick_ConfigDescriptor,
JOYSTICK_SIZ_CONFIG_DESC
};
ONE_DESCRIPTOR Joystick_Report_Descriptor =
{
(uint8_t *)Joystick_ReportDescriptor,
JOYSTICK_SIZ_REPORT_DESC
};
ONE_DESCRIPTOR Mouse_Hid_Descriptor =
{
(uint8_t*)Joystick_ConfigDescriptor + JOYSTICK_OFF_HID_DESC,
JOYSTICK_SIZ_HID_DESC
};
ONE_DESCRIPTOR String_Descriptor[4] =
{
{(uint8_t*)Joystick_StringLangID, JOYSTICK_SIZ_STRING_LANGID},
{(uint8_t*)Joystick_StringVendor, JOYSTICK_SIZ_STRING_VENDOR},
{(uint8_t*)Joystick_StringProduct, JOYSTICK_SIZ_STRING_PRODUCT},
{(uint8_t*)Joystick_StringSerial, JOYSTICK_SIZ_STRING_SERIAL}
};
/* Extern variables ----------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Extern function prototypes ------------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name : Joystick_init.
* Description : Joystick Mouse init routine.
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
void Joystick_init(void)
{
/* Update the serial number string descriptor with the data from the unique
ID*/
// Get_SerialNum();
pInformation->Current_Configuration = 0;
/* Connect the device */
PowerOn();
/* Perform basic device initialization operations */
USB_SIL_Init();
bDeviceState = UNCONNECTED;
}
/*******************************************************************************
* Function Name : Joystick_Reset.
* Description : Joystick Mouse reset routine.
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
void Joystick_Reset(void)
{
/* Set Joystick_DEVICE as not configured */
pInformation->Current_Configuration = 0;
pInformation->Current_Interface = 0;/*the default Interface*/
/* Current Feature initialization */
pInformation->Current_Feature = Joystick_ConfigDescriptor[7];
SetBTABLE(BTABLE_ADDRESS);
/* Initialize Endpoint 0 */
SetEPType(ENDP0, EP_CONTROL);
SetEPTxStatus(ENDP0, EP_TX_STALL);
SetEPRxAddr(ENDP0, ENDP0_RXADDR);
SetEPTxAddr(ENDP0, ENDP0_TXADDR);
Clear_Status_Out(ENDP0);
SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
SetEPRxValid(ENDP0);
/* Initialize Endpoint 1 */
SetEPType(ENDP1, EP_INTERRUPT);
SetEPTxAddr(ENDP1, ENDP1_TXADDR);
SetEPTxCount(ENDP1, 4);
SetEPRxStatus(ENDP1, EP_RX_DIS);
SetEPTxStatus(ENDP1, EP_TX_NAK);
/* Set this device to response on default address */
SetDeviceAddress(0);
bDeviceState = ATTACHED;
}
/*******************************************************************************
* Function Name : Joystick_SetConfiguration.
* Description : Update the device state to configured.
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
void Joystick_SetConfiguration(void)
{
DEVICE_INFO *pInfo = &Device_Info;
if (pInfo->Current_Configuration != 0)
{
/* Device configured */
bDeviceState = CONFIGURED;
}
}
/*******************************************************************************
* Function Name : Joystick_SetConfiguration.
* Description : Update the device state to addressed.
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
void Joystick_SetDeviceAddress (void)
{
bDeviceState = ADDRESSED;
}
/*******************************************************************************
* Function Name : Joystick_Status_In.
* Description : Joystick status IN routine.
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
void Joystick_Status_In(void)
{}
/*******************************************************************************
* Function Name : Joystick_Status_Out
* Description : Joystick status OUT routine.
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
void Joystick_Status_Out (void)
{}
/*******************************************************************************
* Function Name : Joystick_Data_Setup
* Description : Handle the data class specific requests.
* Input : Request Nb.
* Output : None.
* Return : USB_UNSUPPORT or USB_SUCCESS.
*******************************************************************************/
RESULT Joystick_Data_Setup(uint8_t RequestNo)
{
uint8_t *(*CopyRoutine)(uint16_t);
CopyRoutine = NULL;
if ((RequestNo == GET_DESCRIPTOR)
&& (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))
&& (pInformation->USBwIndex0 == 0))
{
if (pInformation->USBwValue1 == REPORT_DESCRIPTOR)
{
CopyRoutine = Joystick_GetReportDescriptor;
}
else if (pInformation->USBwValue1 == HID_DESCRIPTOR_TYPE)
{
CopyRoutine = Joystick_GetHIDDescriptor;
}
} /* End of GET_DESCRIPTOR */
/*** GET_PROTOCOL ***/
else if ((Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT))
&& RequestNo == GET_PROTOCOL)
{
CopyRoutine = Joystick_GetProtocolValue;
}
if (CopyRoutine == NULL)
{
return USB_UNSUPPORT;
}
pInformation->Ctrl_Info.CopyData = CopyRoutine;
pInformation->Ctrl_Info.Usb_wOffset = 0;
(*CopyRoutine)(0);
return USB_SUCCESS;
}
/*******************************************************************************
* Function Name : Joystick_NoData_Setup
* Description : handle the no data class specific requests
* Input : Request Nb.
* Output : None.
* Return : USB_UNSUPPORT or USB_SUCCESS.
*******************************************************************************/
RESULT Joystick_NoData_Setup(uint8_t RequestNo)
{
if ((Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT))
&& (RequestNo == SET_PROTOCOL))
{
return Joystick_SetProtocol();
}
else
{
return USB_UNSUPPORT;
}
}
/*******************************************************************************
* Function Name : Joystick_GetDeviceDescriptor.
* Description : Gets the device descriptor.
* Input : Length
* Output : None.
* Return : The address of the device descriptor.
*******************************************************************************/
uint8_t *Joystick_GetDeviceDescriptor(uint16_t Length)
{
return Standard_GetDescriptorData(Length, &Device_Descriptor);
}
/*******************************************************************************
* Function Name : Joystick_GetConfigDescriptor.
* Description : Gets the configuration descriptor.
* Input : Length
* Output : None.
* Return : The address of the configuration descriptor.
*******************************************************************************/
uint8_t *Joystick_GetConfigDescriptor(uint16_t Length)
{
return Standard_GetDescriptorData(Length, &Config_Descriptor);
}
/*******************************************************************************
* Function Name : Joystick_GetStringDescriptor
* Description : Gets the string descriptors according to the needed index
* Input : Length
* Output : None.
* Return : The address of the string descriptors.
*******************************************************************************/
uint8_t *Joystick_GetStringDescriptor(uint16_t Length)
{
uint8_t wValue0 = pInformation->USBwValue0;
if (wValue0 > 4)
{
return NULL;
}
else
{
return Standard_GetDescriptorData(Length, &String_Descriptor[wValue0]);
}
}
/*******************************************************************************
* Function Name : Joystick_GetReportDescriptor.
* Description : Gets the HID report descriptor.
* Input : Length
* Output : None.
* Return : The address of the configuration descriptor.
*******************************************************************************/
uint8_t *Joystick_GetReportDescriptor(uint16_t Length)
{
return Standard_GetDescriptorData(Length, &Joystick_Report_Descriptor);
}
/*******************************************************************************
* Function Name : Joystick_GetHIDDescriptor.
* Description : Gets the HID descriptor.
* Input : Length
* Output : None.
* Return : The address of the configuration descriptor.
*******************************************************************************/
uint8_t *Joystick_GetHIDDescriptor(uint16_t Length)
{
return Standard_GetDescriptorData(Length, &Mouse_Hid_Descriptor);
}
/*******************************************************************************
* Function Name : Joystick_Get_Interface_Setting.
* Description : tests the interface and the alternate setting according to the
* supported one.
* Input : - Interface : interface number.
* - AlternateSetting : Alternate Setting number.
* Output : None.
* Return : USB_SUCCESS or USB_UNSUPPORT.
*******************************************************************************/
RESULT Joystick_Get_Interface_Setting(uint8_t Interface, uint8_t AlternateSetting)
{
if (AlternateSetting > 0)
{
return USB_UNSUPPORT;
}
else if (Interface > 0)
{
return USB_UNSUPPORT;
}
return USB_SUCCESS;
}
/*******************************************************************************
* Function Name : Joystick_SetProtocol
* Description : Joystick Set Protocol request routine.
* Input : None.
* Output : None.
* Return : USB SUCCESS.
*******************************************************************************/
RESULT Joystick_SetProtocol(void)
{
uint8_t wValue0 = pInformation->USBwValue0;
ProtocolValue = wValue0;
return USB_SUCCESS;
}
/*******************************************************************************
* Function Name : Joystick_GetProtocolValue
* Description : get the protocol value
* Input : Length.
* Output : None.
* Return : address of the protocol value.
*******************************************************************************/
uint8_t *Joystick_GetProtocolValue(uint16_t Length)
{
if (Length == 0)
{
pInformation->Ctrl_Info.Usb_wLength = 1;
return NULL;
}
else
{
return (uint8_t *)(&ProtocolValue);
}
}
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Bu kodlara ihtiyacım yok. Benim için paket veri gönderme ve Paket veri almak için iki adet fonksiyon olması yeterli şimdilik. Bu kısmı nasıl yapacam anlamadım.
Etraftaki örnek projelere bakıyorum. Hep sağlam projeler var. Mesela bir tanesi SD kartı hafıza olarak kullanıp USB flash disk programı yazmış. Başka bir tanesi işlemcinin program hafızasında aynı işlemi yapmış!! Diğeri USB-RS232 dönüştürücü yapmış. Bunların hepsi USB kütüphanesinin içerisindeki örneklerde var. Bu projelerin hepsinde usb_prob.c dosyası yapılan işe göre yeniden düzenlenmiş. Ben ise Haliyle bu kadar kod kalabalığı içerisinde istediğimi yapmakta zorlanıyorum. Daha önce ST'nin USB kütüphanesini kullanan varmı? USB_HID bağlantısı kurup en basit şekilde PC ye paket gönderip almak için bundan sonra ne yapmam gerekiyor?
uint32_t USB_SIL_Init(void);
uint32_t USB_SIL_Write(uint8_t bEpAddr, uint8_t* pBufferPointer, uint32_t wBufferSize);
uint32_t USB_SIL_Read(uint8_t bEpAddr, uint8_t* pBufferPointer);
mesaj birleştirme:: 08 Temmuz 2015, 11:44:54
bu örneği denedin mi ?
http://www.keil.com/download/files/stm32_usbhid.zip (http://www.keil.com/download/files/stm32_usbhid.zip)
mesaj birleştirme:: 08 Temmuz 2015, 11:59:57
...\STM32_USB-FS-Device_Lib_V4.0.0\Projects\Custom_HID\src\stm32_it.c
void DMA1_Channel1_IRQHandler(void)
{
Send_Buffer[0] = 0x07;
if((ADC_ConvertedValueX >>4) - (ADC_ConvertedValueX_1 >>4) > 4)
{
if ((PrevXferComplete) && (bDeviceState == CONFIGURED))
{
Send_Buffer[1] = (uint8_t)(ADC_ConvertedValueX >>4);
/* Write the descriptor through the endpoint */
USB_SIL_Write(EP1_IN, (uint8_t*) Send_Buffer, 2);
SetEPTxValid(ENDP1);
ADC_ConvertedValueX_1 = ADC_ConvertedValueX;
PrevXferComplete = 0;
}
}
DMA_ClearFlag(DMA1_FLAG_TC1);
}
Bu kodu ilk başta bakmıştım ama derlenmesinde nedense hata aldım. O yüzden pek ilgilenmemiştim. Hocam ben bunun üzerinde biraz çalışayım.
Yukarıda verdiğim kod örneği adc ölçümlerini usbye basıyor hocam sizin kullanmak istediğiniz şekilde?
Evet aynen öyle veri alma ve gönderme fonksiyonlarını sadeleştirmem lazım.
Hocam Custom HID projesini referans alarak kendi projemdeki USB kodlarını düzenledim. Şimdi Proje hatasız bir şekilde derleniyor. Programı işlemciye yüklediğimde iki adet sorun ortaya çıktı.
1. Bilgisayar USB den aygıtı görüyor. Fakat aygıt tanımlanamıyor. Unkown Device diye takılıp kalıyor.
2. Sistemde TFT ekran var. USB yi aktif edince TFT çalışmayı durduruyor. TFT'yi sürmek için herhangi bir donanım kullanılmıyor. Ayrıca DMA kesmesi vs oluşuyor.
Bu sorunların sebebi ne olabilir? Özellikle 1. sorun sebebi hangi dosyadan kaynaklıdır? usb_desc.c dosyasına hiç karışmadım. Descriptor bilgileri Custom_HID Projesi ile aynı.
Fikri olan varmı?
usb için clock ayarını ne yaptın?
Hocam init ayarı için main programında sırayla aşağıdaki fonksiyonları çağırıyorum.
Set_System();
USB_Interrupts_Config();
Set_USBClock();
USB_Init();
Bu fonksiyonların hepsi hw_config.c içerisinde.
/**
******************************************************************************
* @file hw_config.c
* @author MCD Application Team
* @version V4.0.0
* @date 21-January-2013
* @brief Hardware Configuration & Setup
******************************************************************************
* @attention
*
* <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "hw_config.h"
#include "usb_lib.h"
#include "usb_desc.h"
#include "usb_pwr.h"
#include "platform_config.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
ErrorStatus HSEStartUpStatus;
/* Extern variables ----------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len);
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name : Set_System
* Description : Configures Main system clocks & power.
* Input : None.
* Return : None.
*******************************************************************************/
void Set_System(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable the PWR clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
/* Enable USB_DISCONNECT GPIO clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIO_DISCONNECT, ENABLE);
/* USB_DISCONNECT_PIN used as USB pull-up */
GPIO_InitStructure.GPIO_Pin = USB_DISCONNECT_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
GPIO_Init(USB_DISCONNECT, &GPIO_InitStructure);
}
/*******************************************************************************
* Function Name : Set_USBClock
* Description : Configures USB Clock input (48MHz).
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
void Set_USBClock(void)
{
/* USBCLK = PLLCLK */
RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5);
/* Enable USB clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE);
}
/*******************************************************************************
* Function Name : Enter_LowPowerMode.
* Description : Power-off system clocks and power while entering suspend mode.
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
void Enter_LowPowerMode(void)
{
/* Set the device state to suspend */
bDeviceState = SUSPENDED;
/* Request to enter STOP mode with regulator in low power mode */
PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
}
/*******************************************************************************
* Function Name : Leave_LowPowerMode.
* Description : Restores system clocks and power while exiting suspend mode.
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
void Leave_LowPowerMode(void)
{
DEVICE_INFO *pInfo = &Device_Info;
/* Set the device state to the correct state */
if (pInfo->Current_Configuration != 0)
{
/* Device configured */
bDeviceState = CONFIGURED;
}
else
{
bDeviceState = ATTACHED;
}
/*Enable SystemCoreClock*/
SystemInit();
}
/*******************************************************************************
* Function Name : USB_Interrupts_Config.
* Description : Configures the USB interrupts.
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
void USB_Interrupts_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = USB_HP_CAN1_TX_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/*******************************************************************************
* Function Name : USB_Cable_Config.
* Description : Software Connection/Disconnection of USB Cable.
* Input : NewState: new state.
* Output : None.
* Return : None
*******************************************************************************/
void USB_Cable_Config (FunctionalState NewState)
{
if (NewState != DISABLE)
{
GPIO_ResetBits(USB_DISCONNECT, USB_DISCONNECT_PIN);
}
else
{
GPIO_SetBits(USB_DISCONNECT, USB_DISCONNECT_PIN);
}
}
/*******************************************************************************
* Function Name : Get_SerialNum.
* Description : Create the serial number string descriptor.
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
void Get_SerialNum(void)
{
uint32_t Device_Serial0, Device_Serial1, Device_Serial2;
Device_Serial0 = *(uint32_t*)ID1;
Device_Serial1 = *(uint32_t*)ID2;
Device_Serial2 = *(uint32_t*)ID3;
Device_Serial0 += Device_Serial2;
if (Device_Serial0 != 0)
{
IntToUnicode (Device_Serial0, &CustomHID_StringSerial[2] , 8);
IntToUnicode (Device_Serial1, &CustomHID_StringSerial[18], 4);
}
}
/*******************************************************************************
* Function Name : HexToChar.
* Description : Convert Hex 32Bits value into char.
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len)
{
uint8_t idx = 0;
for( idx = 0 ; idx < len ; idx ++)
{
if( ((value >> 28)) < 0xA )
{
pbuf[ 2* idx] = (value >> 28) + '0';
}
else
{
pbuf[2* idx] = (value >> 28) + 'A' - 10;
}
value = value << 4;
pbuf[ 2* idx + 1] = 0;
}
}
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
USB clock ayarlarım aşağıdaki gibi yapılmış durumda.
/* USBCLK = PLLCLK */
RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5);
/* Enable USB clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE);
Yalnız dikkatimi çeken birşey daha var. DM ve DP pinleri için extra bir tanımlama yapmadık. Biz USB modülünü aktif edince bu pinler otomatikmen USB donanımına bağlanmış mı oluyor?
USB donanım frekansı yanlışım yoksa 48MHZ olması gerekiyor. Benim İşlemcim 72Mhz de çalışıyor. Bölücü ayarları felan doğru olması lazım.
TFT duruyorsa program biyerde kilitleniyordur orasını bulmak lazım .Hangi kart ile deniyosun? USB pinleri Registerlerinde aktif ediliyor yalnış bilmiyorsam. Clock ayarın doğru 72 Mhz / 1.5 =48 Mhz.
Hocam işlemci interruptları aktif edince donuyor.
Mainde aşağıdaki interruptları aktif etmek için USB_Interrupts_Config(); fonksiyonunu çağırıyorum. (fonksiyon bir önceki mesajımda hw_configçc içerisinde)
İnterruptlar aktif olunca işlemci USB_Init(); fonksiyonunda takılıp kalıyor.
Kart hangisiydi hocam yada sizmi yaptınız kartı?
Yok hocam ya hazır bir kart
http://propix.com.pl/pl/p/Modul-STM32-Firebull/54 (http://propix.com.pl/pl/p/Modul-STM32-Firebull/54)
Ne yapacam bilmiyorum. Herşey iyi güzel görünüyor. Başka ne hata yapıyor olabilir
JP9 jumper i bağlımı hocam?
mesaj birleştirme:: 09 Temmuz 2015, 13:50:55
/**
******************************************************************************
* @file platform_config.h
* @author MCD Application Team
* @version V4.0.0
* @date 21-January-2013
* @brief Evaluation board specific configuration file.
******************************************************************************
* @attention
*
* <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __PLATFORM_CONFIG_H
#define __PLATFORM_CONFIG_H
/* Includes ------------------------------------------------------------------*/
#if defined(STM32L1XX_MD) || defined(STM32L1XX_HD)|| defined(STM32L1XX_MD_PLUS)
#include "stm32l1xx.h"
#if defined (USE_STM32L152_EVAL)
#include "stm32l152_eval.h"
#elif defined (USE_STM32L152D_EVAL)
#include "stm32l152d_eval.h"
#else
#error "Missing define: USE_STM32L152_EVAL or USE_STM32L152D_EVAL"
#endif /* USE_STM32L152_EVAL */
#elif defined (STM32F10X_MD) || defined (STM32F10X_HD) || defined (STM32F10X_XL)
#include "stm32f10x.h"
#if defined (USE_STM3210B_EVAL)
#include "stm3210b_eval.h"
#elif defined (USE_STM3210E_EVAL)
#include "stm3210e_eval.h"
#else
#error "Missing define: USE_STM3210B_EVAL or USE_STM3210E_EVAL"
#endif /* USE_STM3210B_EVAL */
#elif defined (USE_STM32373C_EVAL)
#include "stm32f37x.h"
#include "stm32373c_eval.h"
#elif defined (USE_STM32303C_EVAL)
#include "stm32f30x.h"
#include "stm32303c_eval.h"
#endif
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Uncomment the line corresponding to the STMicroelectronics evaluation board
used to run the example */
#if !defined (USE_STM3210B_EVAL) && !defined (USE_STM3210E_EVAL) && !defined (USE_STM32L152_EVAL) && !defined (USE_STM32L152D_EVAL)&& !defined (USE_STM32373C_EVAL) && !defined (USE_STM32303C_EVAL)
//#define USE_STM3210B_EVAL
//#define USE_STM3210E_EVAL
//#define USE_STM32L152_EVAL
//#define USE_STM32L152D_EVAL
//#define USE_STM32373C_EVAL
#define USE_STM32303C_EVAL
#endif
/*Unique Devices IDs register set*/
#if defined(STM32L1XX_MD) || defined(STM32L1XX_HD) || defined(STM32L1XX_MD_PLUS)
#define ID1 (0x1FF80050)
#define ID2 (0x1FF80054)
#define ID3 (0x1FF80064)
#elif defined (STM32F37X) || defined(STM32F30X)
#define ID1 (0x1FFFF7AC)
#define ID2 (0x1FFFF7B0)
#define ID3 (0x1FFFF7B4)
#else /*STM32F1x*/
#define ID1 (0x1FFFF7E8)
#define ID2 (0x1FFFF7EC)
#define ID3 (0x1FFFF7F0)
#endif
/* Define the STM32F10x hardware depending on the used evaluation board */
#ifdef USE_STM3210B_EVAL
#define USB_DISCONNECT GPIOD
#define USB_DISCONNECT_PIN GPIO_Pin_9
#define RCC_APB2Periph_GPIO_DISCONNECT RCC_APB2Periph_GPIOD
#define ADC1_DR_Address ((uint32_t)0x4001244C)
#elif defined (USE_STM3210E_EVAL)
#define USB_DISCONNECT GPIOB
#define USB_DISCONNECT_PIN GPIO_Pin_14
#define RCC_APB2Periph_GPIO_DISCONNECT RCC_APB2Periph_GPIOB
#define ADC1_DR_Address ((uint32_t)0x4001244C)
#elif defined (USE_STM32L152_EVAL) || defined (USE_STM32L152D_EVAL)
/*
For STM32L15xx devices it is possible to use the internal USB pullup
controlled by register SYSCFG_PMC (refer to RM0038 reference manual for
more details).
It is also possible to use external pullup (and disable the internal pullup)
by setting the define USB_USE_EXTERNAL_PULLUP in file platform_config.h
and configuring the right pin to be used for the external pull up configuration.
To have more details on how to use an external pull up, please refer to
STM3210E-EVAL evaluation board manuals.
*/
/* Uncomment the following define to use an external pull up instead of the
integrated STM32L15xx internal pull up. In this case make sure to set up
correctly the external required hardware and the GPIO defines below.*/
/* #define USB_USE_EXTERNAL_PULLUP */
#if !defined(USB_USE_EXTERNAL_PULLUP)
#define STM32L15_USB_CONNECT SYSCFG_USBPuCmd(ENABLE)
#define STM32L15_USB_DISCONNECT SYSCFG_USBPuCmd(DISABLE)
#define RCC_AHBPeriph_GPIO_DISCONNECT 0
#elif defined(USB_USE_EXTERNAL_PULLUP)
/* PA0 is chosen just as illustrating example, you should modify the defines
below according to your hardware configuration. */
#define USB_DISCONNECT GPIOA
#define USB_DISCONNECT_PIN GPIO_Pin_0
#define RCC_AHBPeriph_GPIO_DISCONNECT RCC_AHBPeriph_GPIOA
#define STM32L15_USB_CONNECT GPIO_ResetBits(USB_DISCONNECT, USB_DISCONNECT_PIN)
#define STM32L15_USB_DISCONNECT GPIO_SetBits(USB_DISCONNECT, USB_DISCONNECT_PIN)
#endif /* USB_USE_EXTERNAL_PULLUP */
#define ADC1_DR_Address ((uint32_t)0x40012458)
#endif /* USE_STM3210B_EVAL */
#if defined (USE_STM32373C_EVAL)
#define USB_DISCONNECT GPIOC
#define USB_DISCONNECT_PIN GPIO_Pin_5
#define RCC_AHBPeriph_GPIO_DISCONNECT RCC_AHBPeriph_GPIOC
#endif
#if defined (USE_STM32303C_EVAL)
#define USB_DISCONNECT GPIOB
#define USB_DISCONNECT_PIN GPIO_Pin_8
#define RCC_AHBPeriph_GPIO_DISCONNECT RCC_AHBPeriph_GPIOB
#define RCC_AHBPeriph_ALLGPIO (RCC_AHBPeriph_GPIOA \
| RCC_AHBPeriph_GPIOB \
| RCC_AHBPeriph_GPIOC \
| RCC_AHBPeriph_GPIOD \
| RCC_AHBPeriph_GPIOE \
| RCC_AHBPeriph_GPIOF )
#endif
#if defined (USE_STM32L152_EVAL)
#define RCC_AHBPeriph_GPIO_IOAIN RCC_AHBPeriph_GPIOB
#define GPIO_IOAIN GPIOB
#define GPIO_IOAIN_PIN GPIO_Pin_12 /* PB.12 */
#define ADC_AIN_CHANNEL ADC_Channel_18
#elif defined (USE_STM32L152D_EVAL)
#define RCC_AHBPeriph_GPIO_IOAIN RCC_AHBPeriph_GPIOF
#define GPIO_IOAIN GPIOF
#define GPIO_IOAIN_PIN GPIO_Pin_10 /* PF.10 */
#define ADC_AIN_CHANNEL ADC_Channel_31
#elif defined (USE_STM32373C_EVAL)
#define ADC1_DR_Address 0x4001244C
#define RCC_AHBPeriph_GPIO_IOAIN RCC_AHBPeriph_GPIOB
#define GPIO_IOAIN GPIOB
#define GPIO_IOAIN_PIN GPIO_Pin_1 /* PB.1 */
#define ADC_AIN_CHANNEL ADC_Channel_9
#define GPIO_Mode_AIN GPIO_Mode_AN
#elif defined (USE_STM32303C_EVAL)
#define ADC1_DR_Address 0x5000030C
#define RCC_AHBPeriph_GPIO_IOAIN RCC_AHBPeriph_GPIOC
#define GPIO_IOAIN GPIOC
#define GPIO_IOAIN_PIN GPIO_Pin_1 /* PC.1 */
#define ADC_AIN_CHANNEL ADC_Channel_7
#define GPIO_Mode_AIN GPIO_Mode_AN
#else
#define RCC_APB2Periph_GPIO_IOAIN RCC_APB2Periph_GPIOC
#define GPIO_IOAIN GPIOC
#define GPIO_IOAIN_PIN GPIO_Pin_4 /* PC.04 */
#define ADC_AIN_CHANNEL ADC_Channel_14
#endif /* USE_STM32L152_EVAL */
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
#endif /* __PLATFORM_CONFIG_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
bu kodu kullanıyomusunuz hocam ?
mesaj birleştirme:: 09 Temmuz 2015, 13:55:04
hw_config.c içinde
void Set_System(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable the PWR clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
/* Enable USB_DISCONNECT GPIO clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
/* USB_DISCONNECT_PIN used as USB pull-up */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
diye değiştirip denermisinizhocam.
Kullanıyorum. Ama ben o dosyayı bayağı bi düzenledim. STM32F10x ile çalışacak şekilde diğer işlemciler için bulunan tanımlamaları kod kalabalığı olmaması için sildim.
/******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
* File Name : platform_config.h
* Author : MCD Application Team
* Version : V3.2.1
* Date : 07/05/2010
* Description : Evaluation board specific configuration file.
********************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __PLATFORM_CONFIG_H
#define __PLATFORM_CONFIG_H
/* Includes ------------------------------------------------------------------*/
/* Define the STM32F10x hardware depending on the used evaluation board */
#define USB_DISCONNECT GPIOC
#define USB_DISCONNECT_PIN GPIO_Pin_9
#define RCC_APB2Periph_GPIO_DISCONNECT RCC_APB2Periph_GPIOC
#define RCC_APB2Periph_ALLGPIO (RCC_APB2Periph_GPIOA \
| RCC_APB2Periph_GPIOB \
| RCC_APB2Periph_GPIOC \
| RCC_APB2Periph_GPIOD \
| RCC_APB2Periph_GPIOE )
/*STM32F1x*/
#define ID1 (0x1FFFF7E8)
#define ID2 (0x1FFFF7EC)
#define ID3 (0x1FFFF7F0)
#endif /* __PLATFORM_CONFIG_H */
/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
Disconnect Pin ayarlarını vs hepsini kendi boardıma göre yaptım. USB aktif olduğunda LD6 ledi yanıyor.
(http://s3.postimg.cc/on5yynjfj/Ekran_Al_nt_s.jpg) (http://postimg.cc/image/on5yynjfj/)
Bendeki boardda USB_DISCONNECT pini Portc.9'a bağlı. Portc.9 GND de iken Aktif oluyor.
Benim aklıma ordan geliyodu ama onuda yapmışsın baska bise kalmadı yapacak arastırayım bakim biraz.
Hocam çok iyi olur. Ciddi anlamda 2 gündür bu USB işine uğraşıyorum. Ben ST Forumda yazacam birde
http://www.st.com/web/en/catalog/tools/PF257920# (http://www.st.com/web/en/catalog/tools/PF257920#) bunu denedinizmi hocam?
Hocam verdiğiniz likte PC için yazılmış USB hid Test programı gibi birşey var. Bana STM32F103 için yazılmış HID örnekleri lazım.
Ben işyerinde olduğum için yükleyemedim içinden ne olduğunu bilmiyodum ben stm için yazılmış sandım hocam.
bunu deneyin bide isterseniz
https://github.com/RavWin/RHIDDemo/tree/master/tstHID-STM32F103
Hocam ilginiz için teşekkür ederim. Ben o kodlar dahil birçok projeyi indirdim. İnceliyorum ama göze çarpacak bir hata bulamıyorum.
Daha önce stm32f10x ile usb kullanan başka birisi varmı?
http://www.st.com/web/en/catalog/tools/PF259446 (http://www.st.com/web/en/catalog/tools/PF259446)
burdaki usb ornegini denedim hocam stm32f072rb discoda calistirdim.usb lib kullanabilirsiniz sanirim nasil kullanmaniz gerektigide yaziyor zaten.
Hocam saat 12 den beri uğraşıyorum. Deneme amaçlı sizin en son githupdan verdiğiniz RHID programını Hiç değiştirmeden keilde tekrardan derleyip denedim Sonuç birebir aynı. USB clock aktif edilince işlemci USB_init fonksiyonunda takılıp kalıyor. Gerçekten neyi eksik yapıyorum çok merak ediyorum.
Hatta emin olmak icin MCO vasıtasıyla SYSCLK frekansini dışarı verip Osioskop ile Çalışma frekansini ölçüm. Tam olarak 72 Mhz. Oradada sıkıntı yok.
yarin sabahta sizin verdiginiz programı deneyeceğim. Bu gecelik yeter.
Bu arada keske elimde stm32f072rb disco olsaydı ne süper olurdu. En azından elimde çalışan bir sistem olurdu
http://tr.mouser.com/ProductDetail/STMicroelectronics/STM32F072B-DISCO/?qs=sGAEpiMZZMsrChSOYEGTCed25%252bTwgEDrQopEYb4EsFg%3d (http://tr.mouser.com/ProductDetail/STMicroelectronics/STM32F072B-DISCO/?qs=sGAEpiMZZMsrChSOYEGTCed25%252bTwgEDrQopEYb4EsFg%3d)
fiyatıda normal hocam eğer deneme yapacaksanız bendekini gönderebilirim size denemeniz için.
Günaydın. Teşekkürler ilginiz için. O kodları bugün bi deneyeyim. Bakalım belki farklı birşeyler bulurum. Olmadı STM32F4 Disco ile testler yapacağım. Orda USB kütüphanesinin çalışmasını anlarsam STM32F10X deki problemin çözümünde bana faydası olabilir.
Hocam belki usb descriptor uyumları tutmuyor olabilir.Kontrol edin isterseniz.
Hocam ben işlemcinin donmasına anlam veremiyorum. USB modülü çalışmaya başlayınca neden donar? Donmasına neler sebeb olabilir bunları öğrenmem lazım
Birde şu sitede bayağı bir örnek var gibi. İndirmeye çalışıyorum.
http://s.pudn.com/search_hot_en.asp?k=stm32+usb# (http://s.pudn.com/search_hot_en.asp?k=stm32+usb#)
Buna benzer örnek bulunabilecek siteler biliyormusunuz?
Alıntı yapılan: LukeSkywalker - 07 Temmuz 2015, 15:53:24
MikroC altinda hid kullandim stm32f103c8 ile.
Alıntı yapılan: Mucit23 - 07 Temmuz 2015, 15:54:55
MikroC olmaz hocam keil kullanıyorum.
MikroC ile hazır kod dene. Eğer çalışmazsa sıkıntı kodlamada olmayabilir.
MikroC yi yüklemem lazım. Aslında evet deneyebilirim. STM32F103VE için hazır bir projeyi kendi kartımda çalıştırabilirsem Gerekirse tüm kodumu mikroC ye bile taşırım. Platfomun önemi yok şuanda. İş görülsün.
Bu arada son verdiğim Sitede STM32F103 için bir sürü örnek uygulama buldum. STM32 USB diye aratınca onlarca döküman proje vs çıktı. Sağlam arşivmiş.
Galiba sorunu çözdüm. Pc cihazı gördü driverini kurdu. Şuan internetim sınırlı. Detaylı açıklamayı kısa bir zamanda yapacağım.
Sorunu çözdüm arkadaşlar. Çok şükür şuanda gördüğüm kadarıyla bir problem kalmadı. Startup dosyasında problem varmış. STM32F10x de STD Library'nin 3.1 sürümünü kullanıyorum. Kullandığım statup dosyası ise yine en son yayınlanan startup_stm32f10x_hd.s dosyasıydı. Bunun sürümüne 3.5. Fakat USB_FS_Device kütüphanesi bu startup dosyası ile çalışmıyor. Startup olarak stm32f10x_vector.s dosyasını kullanınca düzeldi. Fakat anlamadığım nokta USB_FS_Device kütüphanesindede ST nin yayınladığı en son sürümü yanı V4.0.0'ı kullanıyorum. Kendi yayınladığı örneklerde startup_stm32f10x_hd.s dosyası gibi startup dosyaları kullanılmış.
Şuan bir sıkıntı yok ama yine araştıracağım bunu.
Cumartesi Aygıt PC tarafından görüldükten sonra hemen PC de ufak bir veri gönderip alan bir program hazırladım. İki taraflı iletişimde de problem yok.
derleyici olarak ne kullandınız?
Keil Kullanıyorum
*.s dosyları ile ilgili başıma gelen bir olay:
ben her zaman orjinal kütüphanedeki *.s dosyasını projeye koyuyorum. ancak stack ve heap bazı uygulamalar için yetmeyebiliyor ve sizin dediğiniz donma oluşuyor. muhtemelen debug'da hard faulta gittiğini göreceksiniz. daha sonra örnek verilen projedeki *.s dosyasının kütüphanedeki dosyadan farklı olduğunu farkediyorum.
belki sizin başınıza da böyle bir olay gelmiş olabilir.
Aynen hocam muhtemelen öyle bir durum oldu.
Arkadaşlar selamlar
Aradan epeyce bir zaman geçmiş Benzer bir sorunla karşı karşıyayım. Şu minik STM32F103C8 board larından görmüşsünüzdür.
(https://s1.postimg.cc/mi1ld6yxr/STM32_Mini-700x400.jpg)
USB üzerinden STM32F103'e veri göndermem gerekiyor bir proje için. Daha önce bu konu üzerinde STM32F103VET6 için çalışma yapıp USB haberleşmesini sağlamıştım.
Şuanda ise STM32F103C8 ile aynı işi yapmaya çalışıyorum. Geçen seneden uğraştığım USB kütüphanelerimi vs aynı şekilde derleyip karta yüklüyorum fakat aynı şekilde USB aygıt Tanınmadı hatası alıyorum. Çözemedim bir türlü.
Vektör dosyası olarak yine stm32f10x_vector.s dosyasını kullandım. Bu şekilde program çalışıyor yani USB init rutinleri tamamlanıp işlemci main içerisinde devam edebiliyor. Fakat usb nedense bilgisayar tarafından görülmüyor. USB Aygıt Tanınmadı hatası alıyorum. PC cihazımı arızalı olarak görüyor. Halbuki STM32F103VE ile aynı yazılım çalışıyordu.
Kart üzerindeki USB bağlantısı aşağıdaki gibi yapılmış
(https://s22.postimg.cc/s451dfwox/image.jpg)
Bağlantıda sıkıntı yok görünüyor. USB-DP 4.7K ile pull up yapılmış. Bu konuda fikriniz varmı? Proje dosyam ekte. İncelemeniz mümkünmüdür? Hatta elinde aynı karttan olan programı yükleyip deneyebilir. Benim çipmi bozuk anlamıyorumç
Proje Dosyaları: https://yadi.sk/d/5JDBQuEd3LTk6A (https://yadi.sk/d/5JDBQuEd3LTk6A)
@Mucit23 Hocam;
Kodu derleyip yükledim.
duzgun olarak USB yukledi mikroC nin HID terminal goruntusu:
En alttaki stm32f103 un
(https://i.hizliresim.com/OL8m0n.png) (https://hizliresim.com/OL8m0n)
Aynı kart değilmi nasıl olur anlamıyorum???
Acaba board uzerinde diger ekipmanlardanmı etkileniyor çok ilginç
Elimde bir tane daha aynısından olacak birde onunla deneyeyim. Isletim sistemi ile farketmez değilmi?
Hocam aynı kart
işletim sistemim ise win7 Enterprise 64Bit.
İşletim sistemi ile alakalı değil. Şuanda bazen görüyor bazen görmüyor. Elimde iki tane aynı karttan var. İkisindede aynı durum geçerli.
Ben şu USB-DP hattındaki R10 direncinden şüpheleniyorum
(https://s22.postimg.cc/s451dfwox/image.jpg)
Eğer şema doğru ise R10 benim kartta 10K kullanılmış. Normalde ise 1K5 kullanılıyor. 10K yüksek olabilir diye düşünüyorum. Eğer USB bağlantısını yapınca hemen bağlantı sesi gelirse problem olmuyor ama eğer bağlantı yaptıktan sonra yaklaşık 3-4 sn kadar bekleyip bağlantı sesi gelirse usb aygıt tanınmadı diyor.
@Zoroaster Bu konuda bir tavsiyen olabilirmi? USB neden bu şekilde dengesiz çalışıyor?
İlginç bir şekilde R10 direncini 1K5 Yapınca bilgisayar hiç görmüyor. Yani hiç tepki vermiyor. Tekrar eski 10K direnci taktım böyle arada bir görüyordu yine
@M_B Sizde böyle arada görmeme oluyormu? Yada programa başka eklentiler yapınca görmeme gibi durumlar oluşuyormu? Bu durum diğer program parcacıklarını ekleyince daha çok artıyor. Örneğin P10 Panel sürüyorum. Arka planda sürekli timer çalışıp kesme oluşturuyor. Eğer bu kısımlar aktif ise çok fazla problem oluyor. 10 kez usb bağlantısı yapsam 2 defa ya görür yada görmez. Ama P10 Panel kütüphanelerini devre dışı bırakınca 10 kez usb bağlantısı yapsam 8 defa felan problemsiz görüyor. Çözümü bulamadım bir türlü. ???
@Mucit23 Hocam R10 direnci bende de 10K
Hocam bende arada görmeme yapmadı. Cıkarıp taktım hep gördü.
Hocam isterseniz toplam kodu verin. Yani derlenmiş olarak module yukleyim o zaman dediğiniz gibi yapacak mı bakalım.
@Mucit23 ne yaptınız sorunu bulabildiniz m i ?
Beslemeyle ilgili olabileceğini düşünüyorum. Ben karti harici bir 3.3v regülatör ile besliyorum. Fakat usb taktığım zaman kartin üzerindeki regülatör devreye girip islemciyi besliyor. Iki besleme ayni anda devrede oldugu zaman genellikle görmüyor. Fakat harici beslemeyi devre dışı bıraktığımda büyük bir çoğunlukla problemsiz görüyor. Bir sekilde usb beslemesini devre dışı bırakmam lazim.
Pazartesi tekrar deneyeceğim.
Dirençleri sökün kisa devre yapın
Islemcie enerji verdiginizde reset rutinleri init rutinleri varsa abuk subuk bir suru kod calisir nihatetinde usb init rutinine sira gelir. Halbuki kodlarinizin yazilisina bagli olarak power on asamasindan bu yana yuzlerce mili saniye gecmis olacaktir.
Power on asamasinda usb hat 1K5 ile pull up yapildigi icin PC islerim sistemi derhal usb sorgulamalara baslar. Halbuki MCU tarafinda daha usb init islemi bile yapilmamistir.
Peki ne yapacaksiniz?
1K5 i dogrudan 3V3 e degil bir porta baglayacak ve bu pini reset rutininde low yapacaksiniz. USB init rutininde ise portu high yapacaksiniz.
Boylece power on asamasindan PCnin haberi olmayacak ve sorgulama yapmayacak. Ne zaman usb init yaptiniz iste o an 1K5 pull up olacak ve PC nin dikkati cekilecek.
@Okan AKÇAR9 ve R11 den bahsediyorsun değilmi?
@ZoroasterNormalde system_init den sonra hemen usb init rutinleri başlatıyorum. Ama yeterli gelmiyor sanırım. Dediğini pazartesi bi uygulayayım
1k5 ile 10k uygulamada cok farkedermi? Şu haliyle 10k yi söküp 1k5 taktığımda hiç çalışmıyor.
Evet Dirençlerden kaynaklanabilir
@OkanAkça Dirençleri söktüm ama değişen birşey olmadı.
@Zoroaster Pull-up Beslemesini GPIO ile kontrol etmek için harici bir devre yaptım. Ama değişen birşey yok. Durum aynı gibi.
Ayrıca anlamadığım bir nokta var. Senin dediğin gibi USB init aşamasında PC sorgulama yapıyorsa neden sonradan usb bağlantısı yaptığımda problem olsun ki?
İşlemci init aşamasından Hat pull-up yapılsa bile ben USB kablosunu takmadığım için sorun yok. İşlemci çalışıyor usb init rutinleri felan bitti ana programda çalışıyorken USB bağlantısını yaptığımda zaten usb modülü init edilmiş çalışıyor olacaktır. Bu durumdayken sıkıntı oluyor. Gerçi sorunu büyük bir oranda çözdüm gibi. Şuan daha az yapıyor ama bazen tuttumu tuyor inadı.
Son olarak USB den gelen 5V beslemeyi ayıracağım. Kart sadece benim verdiğim 3.3V ile çalışsın istiyorum. USB den enerji çekmesin.
Birde 1K5 kesinlikle olmuyor. PC hiç tepki vermiyor. R10 direnci en az 10K olmalı.
Sorun aynı şekilde devam ediyor arkadaşlar.
Kullandığım logitech kablosuz fareden şüphelenmeye başladım. Çünkü Yazdığım C# yazılımı kablosuz farenin alıcısını bilgisayara taktığımda aygıt bağlandı, çıkardığımda ise aygıt çıkarıldı eventlerini oluşturuyor. Halbuki VID ve PID ler farklı. Bu neden oluyor anlamış değilim. Farklı bir PC ile denedim. Ne fare nede benim STM daha önce o pcye takılmadı. Ama ondada Aygıt tanınmadı hatası alıyorum. Bazen diyorum tamam oldu daha artık o hatayı vermiyor ama sürekli aynı sorun... Kafayı yememek elde değil.
Sorum şu? Descriptor dosyasını nasıl düzenlerim?. Bildiğim kadarıyla VID ve PID değiştirmek yetmiyor. Bilgisayar STM kitimi tamamen farklı bir kimlikle tanısın istiyorum.
/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
* File Name : usb_desc.c
* Author : MCD Application Team
* Version : V2.2.1
* Date : 09/22/2008
* Description : Descriptors for Custom HID Demo
********************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "usb_lib.h"
#include "usb_desc.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Extern variables ----------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/* USB Standard Device Descriptor */
const u8 CustomHID_DeviceDescriptor[CUSTOMHID_SIZ_DEVICE_DESC] =
{
0x12, /*bLength */
USB_DEVICE_DESCRIPTOR_TYPE, /*bDescriptorType*/
0x00, /*bcdUSB */
0x02,
0x00, /*bDeviceClass*/
0x00, /*bDeviceSubClass*/
0x00, /*bDeviceProtocol*/
0x40, /*bMaxPacketSize40*/
0x83, /*idVendor (0x0483)*/
0x04,
0x50, /*idProduct = 0x5750*/
0x57,
0x00, /*bcdDevice rel. 2.00*/
0x02,
1, /*Index of string descriptor describing
manufacturer */
2, /*Index of string descriptor describing
product*/
3, /*Index of string descriptor describing the
device serial number */
0x01 /*bNumConfigurations*/
}
; /* CustomHID_DeviceDescriptor */
/* USB Configuration Descriptor */
/* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */
const u8 CustomHID_ConfigDescriptor[CUSTOMHID_SIZ_CONFIG_DESC] =
{
0x09, /* bLength: Configuation Descriptor size */
USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */
CUSTOMHID_SIZ_CONFIG_DESC,
/* wTotalLength: Bytes returned */
0x00,
0x01, /* bNumInterfaces: 1 interface */
0x01, /* bConfigurationValue: Configuration value */
0x00, /* iConfiguration: Index of string descriptor describing
the configuration*/
0xC0, /* bmAttributes: Bus powered */
/*Bus powered: 7th bit, Self Powered: 6th bit, Remote wakeup: 5th bit, reserved: 4..0 bits */
0x32, /* MaxPower 100 mA: this current is used for detecting Vbus */
// 0x96, /* MaxPower 300 mA: this current is used for detecting Vbus */
/************** Descriptor of Custom HID interface ****************/
/* 09 */
0x09, /* bLength: Interface Descriptor size */
USB_INTERFACE_DESCRIPTOR_TYPE,/* bDescriptorType: Interface descriptor type */
0x00, /* bInterfaceNumber: Number of Interface */
0x00, /* bAlternateSetting: Alternate setting */
0x02, /* bNumEndpoints */
0x03, /* bInterfaceClass: HID */
0x00, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
0x00, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
0, /* iInterface: Index of string descriptor */
/******************** Descriptor of Custom HID HID ********************/
/* 18 */
0x09, /* bLength: HID Descriptor size */
HID_DESCRIPTOR_TYPE, /* bDescriptorType: HID */
0x10, /* bcdHID: HID Class Spec release number */
0x01,
0x00, /* bCountryCode: Hardware target country */
0x01, /* bNumDescriptors: Number of HID class descriptors to follow */
0x22, /* bDescriptorType */
CUSTOMHID_SIZ_REPORT_DESC,/* wItemLength: Total length of Report descriptor */
0x00,
/******************** Descriptor of Custom HID endpoints ******************/
/* 27 */
0x07, /* bLength: Endpoint Descriptor size */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: */
0x82, /* bEndpointAddress: Endpoint Address (IN) */
// bit 3...0 : the endpoint number
// bit 6...4 : reserved
// bit 7 : 0(OUT), 1(IN)
0x03, /* bmAttributes: Interrupt endpoint */
0x40,//0x02, /* wMaxPacketSize: 20 Bytes max */
0x00,
0x20, /* bInterval: Polling Interval (21 ms) */
/* 34 */
0x07, /* bLength: Endpoint Descriptor size */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: */
/* Endpoint descriptor type */
0x01, /* bEndpointAddress: */
/* Endpoint Address (OUT) */
0x03, /* bmAttributes: Interrupt endpoint */
0x40,//0x02, /* wMaxPacketSize: 20 Bytes max */
0x00,
0x10, /* bInterval: Polling Interval (32 ms) */
/* 41 */
}
; /* CustomHID_ConfigDescriptor */
const u8 CustomHID_ReportDescriptor[CUSTOMHID_SIZ_REPORT_DESC] =
{
//#ifdef 0
0x05, 0x8c, /* USAGE_PAGE (ST Page) */
0x09, 0x01, /* USAGE (Demo Kit) */
0xa1, 0x01, /* COLLECTION (Application) */
/* 6 */
// The Input report
0x09,0x03, // USAGE ID - Vendor defined
0x15,0x00, // LOGICAL_MINIMUM (0)
0x26,0x00, 0xFF, // LOGICAL_MAXIMUM (255)
0x75,0x08, // REPORT_SIZE (8)
0x95,0x16, // REPORT_COUNT (20)
0x81,0x02, // INPUT (Data,Var,Abs)
//19
// The Output report
0x09,0x04, // USAGE ID - Vendor defined
0x15,0x00, // LOGICAL_MINIMUM (0)
0x26,0x00,0xFF, // LOGICAL_MAXIMUM (255)
0x75,0x08, // REPORT_SIZE (8)
0x95,0x16, // REPORT_COUNT (20)
0x91,0x02, // OUTPUT (Data,Var,Abs)
//32
// The Feature report
/*
0x09, 0x05, // USAGE ID - Vendor defined
0x15,0x00, // LOGICAL_MINIMUM (0)
0x26,0x00,0xFF, // LOGICAL_MAXIMUM (255)
0x75,0x08, // REPORT_SIZE (8)
0x95,0x02, // REPORT_COUNT (2)
0xB1,0x02,
*/
/* 45 */
0xc0 /* END_COLLECTION */
//#endif
}; /* CustomHID_ReportDescriptor */
/* USB String Descriptors (optional) */
const u8 CustomHID_StringLangID[CUSTOMHID_SIZ_STRING_LANGID] =
{
CUSTOMHID_SIZ_STRING_LANGID,
USB_STRING_DESCRIPTOR_TYPE,
0x09,
0x04
}
; /* LangID = 0x0409: U.S. English */
const u8 CustomHID_StringVendor[CUSTOMHID_SIZ_STRING_VENDOR] =
{
CUSTOMHID_SIZ_STRING_VENDOR, /* Size of Vendor string */
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType*/
// Manufacturer: "STMicroelectronics"
'M', 0, 'y', 0, 'U', 0,'S', 0,'B', 0, '_', 0, 'H', 0,'I',0,'D',0
};
const u8 CustomHID_StringProduct[CUSTOMHID_SIZ_STRING_PRODUCT] =
{
CUSTOMHID_SIZ_STRING_PRODUCT, /* bLength */
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
'B', 0, 'y', 0, ' ', 0, 'D', 0, 'Z', 0, '5', 0,'6',0,'1',0
};
u8 CustomHID_StringSerial[CUSTOMHID_SIZ_STRING_SERIAL] =
{
CUSTOMHID_SIZ_STRING_SERIAL, /* bLength */
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
'x', 0, 'x', 0, 'x', 0,'x', 0,'x', 0, 'x', 0, 'x', 0
};
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
Ekleme: C# yazılımında sıkıntı yokmuş. Kullandığım USB kütüphanesinde bütün HID aygıtlarının takılıp çıkarıldığında oluşan eventlar var. Onlar oluşuyormuş. Fakat asıl sorun devam ediyor.
Hocam siz bu çalışmayı STM32F103 ile mi yapıyorsunuz ?
Eğer donanımdan emin değilseniz ST'nin "CubeMx USB Mouse" örneğini deneyin.
Eğer donanımda problem yok ise kendi örneğinizde descriptor dosyasındaki aygıt stringini ve VID,PID değiştirirseniz tekrar bir driver yüklemesi yaparak farklı cihaz olarak algılayabilir.
Ama bunu denemedim emin değilim.
USBLibrary.dll dosyası her usb cihazı için event oluşturuyor bildiğim kadarıyla
Acaba kendi cihazımızın eventlerini nasıl oluşturabiliriz ?
USB Hid için CubeMX ile proje oluşturdum. Hiçbir sıkıntı olmadı. Doğrudan aygıtımı tanıyıp yazılımını kurdu. Donanımda hiçbir değişiklik olmamasına rağmen tak çıkar aygıt tanınmadı hatası almadım. Bu kadar kolay olması çok hoşuma gitti.
Demekki benim descriptor dosyam ile ilgili sıkıntı var.
HAL kütüphanesine geçmek istemiyorum. STD library ile yazılmış bir çok kütüphanem var. Bunları taşımak zor olur diye düşünüyorum. Birde alışmışlık var aslında.
Descriptor ile ilgili ne problem olabilir. Onu biraz araştırayım.
Alıntı yapılan: baran123 - 31 Temmuz 2017, 22:39:52
USBLibrary.dll dosyası her usb cihazı için event oluşturuyor bildiğim kadarıyla
Acaba kendi cihazımızın eventlerini nasıl oluşturabiliriz ?
@baran123 Yok kendi cihazımız içinde event oluşuyor.
usbHidPort1_OnSpecifiedDeviceArrived kendi cihazımız bağlandığı zaman çalışır.
usbHidPort1_OnSpecifiedDeviceRemoved kendi cihazımız çıkarıldığı zaman çalışır.
Cubemx ile hazırladığım bir kaç usb hid uygulaması mevcut pc tarafına veri gönderme amaçlı
https://www.youtube.com/watch?v=0zoeLBUxpLI ( Mouse )
Şuda media keyleri üzerine https://engineeringvolkan.wordpress.com/2017/06/22/stm32f103xx-usb-media-hid-uygulamasi/
Arkadaşlar şöyle birşey yaptım. CubeMX ile Custom hid projesi oluşturup doğrudan karta yükledim. Sıkıntı yok. PC cihazımı görüyor. Fakat aygıt yöneticisinde cihazıma baktığımda Bu aygıt başlatılamıyor şeklinde bir uyarı alıyorum.
(https://s4.postimg.cc/6urn1v8rh/Ekran_Al_nt_s_1.jpg)
Bu uyarı ne anlama geliyor?
" Aygıtın donanım anahtarı genellikle bir "FailReasonString" değeri içerir ve değer dizesi, donanım üreticisi tarafından tanımlanan bir hata iletisi görüntüler. Donanım anahtarı "FailReasonString" değeri içermiyorsa, yukarıdaki hata iletisi görüntülenir." diyor şurada https://support.microsoft.com/tr-tr/help/310123/error-codes-in-device-manager-in-windows daha önce hid uygulaması yapmıştım , akşam tekrar kartı takıp bakayım bende hid olarak görmüş müydü yoksa hata mı vermişti bakıp döneyim.
Sorunu anladım.
CubeMX ile USB Custom HID projesi oluşturduğumda usb_custom_hid_if.c dosyası içerisinde CUSTOM_HID_ReportDesc_FS bir fonksiyon oluşturuluyor. Bu fonksiyon içerisinde anladığım kadarıyla nasıl bir haberleşme yapılacağı bazı parametrelerle USB üzerinden bildiriliyor.
CubeMX ile boş USB Custom HID projesi oluşturduğumda fonksiyonun içi aşağıdaki gibi geliyor
__ALIGN_BEGIN static uint8_t CUSTOM_HID_ReportDesc_FS[USBD_CUSTOM_HID_REPORT_DESC_SIZE] __ALIGN_END =
{
/* USER CODE BEGIN 0 */
0x00,
/* USER CODE END 0 */
0xC0 /* END_COLLECTION */
};
Burada anladığım kadarıyla USB haberleşmesi nasıl yapılacağına dair bilgi göndermem gerekiyor. Yine ST'nin örneklerinden bir Custom HID örneğini açıp bu fonksiyon içerisine baktım.
0x06, 0xFF, 0x00, /* USAGE_PAGE (Vendor Page: 0xFF00) */
0x09, 0x01, /* USAGE (Demo Kit) */
0xa1, 0x01, /* COLLECTION (Application) */
/* 6 */
/* Led 1 */
0x85, LED1_REPORT_ID, /* REPORT_ID (1) */
0x09, 0x01, /* USAGE (LED 1) */
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
0x75, 0x08, /* REPORT_SIZE (8) */
0x95, LED1_REPORT_COUNT, /* REPORT_COUNT (1) */
0xB1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
0x85, LED1_REPORT_ID, /* REPORT_ID (1) */
0x09, 0x01, /* USAGE (LED 1) */
0x91, 0x82, /* OUTPUT (Data,Var,Abs,Vol) */
/* 26 */
/* Led 2 */
0x85, LED2_REPORT_ID, /* REPORT_ID 2 */
0x09, 0x02, /* USAGE (LED 2) */
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
0x75, 0x08, /* REPORT_SIZE (8) */
0x95, LED2_REPORT_COUNT, /* REPORT_COUNT (1) */
0xB1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
0x85, LED2_REPORT_ID, /* REPORT_ID (2) */
0x09, 0x02, /* USAGE (LED 2) */
0x91, 0x82, /* OUTPUT (Data,Var,Abs,Vol) */
/* 46 */
/* Led 3 */
0x85, LED3_REPORT_ID, /* REPORT_ID (3) */
0x09, 0x03, /* USAGE (LED 3) */
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
0x75, 0x08, /* REPORT_SIZE (8) */
0x95, LED3_REPORT_COUNT, /* REPORT_COUNT (1) */
0xB1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
0x85, LED3_REPORT_ID, /* REPORT_ID (3) */
0x09, 0x03, /* USAGE (LED 3) */
0x91, 0x82, /* OUTPUT (Data,Var,Abs,Vol) */
/* 66 */
/* Led 4 */
0x85, LED4_REPORT_ID, /* REPORT_ID 4) */
0x09, 0x04, /* USAGE (LED 4) */
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
0x75, 0x08, /* REPORT_SIZE (8) */
0x95, LED4_REPORT_COUNT, /* REPORT_COUNT (1) */
0xB1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
0x85, LED4_REPORT_ID, /* REPORT_ID (4) */
0x09, 0x04, /* USAGE (LED 4) */
0x91, 0x82, /* OUTPUT (Data,Var,Abs,Vol) */
/* 86 */
/* key Push Button */
0x85, KEY_REPORT_ID, /* REPORT_ID (5) */
0x09, 0x05, /* USAGE (Push Button) */
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
0x75, 0x01, /* REPORT_SIZE (1) */
0x81, 0x82, /* INPUT (Data,Var,Abs,Vol) */
0x09, 0x05, /* USAGE (Push Button) */
0x75, 0x01, /* REPORT_SIZE (1) */
0xb1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
0x75, 0x07, /* REPORT_SIZE (7) */
0x81, 0x83, /* INPUT (Cnst,Var,Abs,Vol) */
0x85, KEY_REPORT_ID, /* REPORT_ID (2) */
0x75, 0x07, /* REPORT_SIZE (7) */
0xb1, 0x83, /* FEATURE (Cnst,Var,Abs,Vol) */
/* 114 */
/* Tamper Push Button */
0x85, TAMPER_REPORT_ID, /* REPORT_ID (6) */
0x09, 0x06, /* USAGE (Tamper Push Button) */
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
0x75, 0x01, /* REPORT_SIZE (1) */
0x81, 0x82, /* INPUT (Data,Var,Abs,Vol) */
0x09, 0x06, /* USAGE (Tamper Push Button) */
0x75, 0x01, /* REPORT_SIZE (1) */
0xb1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
0x75, 0x07, /* REPORT_SIZE (7) */
0x81, 0x83, /* INPUT (Cnst,Var,Abs,Vol) */
0x85, TAMPER_REPORT_ID, /* REPORT_ID (6) */
0x75, 0x07, /* REPORT_SIZE (7) */
0xb1, 0x83, /* FEATURE (Cnst,Var,Abs,Vol) */
/* 142 */
/* ADC IN */
0x85, ADC_REPORT_ID, /* REPORT_ID */
0x09, 0x07, /* USAGE (ADC IN) */
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
0x26, 0xff, 0x00, /* LOGICAL_MAXIMUM (255) */
0x75, 0x08, /* REPORT_SIZE (8) */
0x81, 0x82, /* INPUT (Data,Var,Abs,Vol) */
0x85, ADC_REPORT_ID, /* REPORT_ID (7) */
0x09, 0x07, /* USAGE (ADC in) */
0xb1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
/* 161 */
Bu şekilde bir yapı gördüm. Bu yapıyı hiç bozmadan Benim kendi oluşturduğum projedeki fonksiyon içerisine kopyalayıp derledim. Ve bingo!!. Aygıtım Problemsiz bir şekilde PC tarafından tanınıp çalıştı.
Şimdi ben kendi oluşturduğum projede de bu fonksiyonu kendime göre düzenlemem lazım ama nasıl olacak bilmiyorum. Bu kodlar ne anlama geliyor? Report Description nasıl oluşturulur hiç bir bilgim yok.
Bunları nasıl öğrenebilirim?
@Zoroaster bilgin var mı bu konularda.
Benim amacım Düz mantık PC den 64 bytelık bir paket göndereyim STM kitimden alayım. Bu kadar.. Report Description bu iş için nasıl düzenlenir?
@muhittin_kaplan hocam bir çalışma yapmıştı.
http://www.muhittinkaplan.com/?p=770
Baran Link İçin teşekkürler
@muhittin_kaplan Abi sanada video için teşekkürler. İzledim baya faydalı oldu. Şimdi biraz taşlar yerine oturmaya başladı baya şey öğrendim. HAL library'e de alıştım sayılır.
Videoyu izlemeden önce aslında bir deneme yaptım. CCS sağolsun oradaki USB çalışamlarıma bakarak USB Report Descriptor için kullanılan tanımlamaları aynen kullandım ve çalıştı. Şuanda PC'ye aşağıdaki gibi bir yapı ile veri gönderebiliyorum.
USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, SendBuffer, 64);
Fakat veri alma işini henüz çözemedim. Ver geldiği zaman sanırım aşağıdaki fonksiyona evet düşüyor
static int8_t CUSTOM_HID_OutEvent_FS (uint8_t event_idx, uint8_t state)
{
return (0);
}
Fakat event_idx ve state değerlerini çözemedim. Gelen 64 byte'lık paketide alırsam USB işini Şimdilik halletmiş olurum.
Sanırım orası şu şekilde olacak
uint8_t i;
uint8_t dataToReceive[USBD_CUSTOMHID_OUTREPORT_BUF_SIZE];
USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef*)hUsbDeviceHS.pClassData;
for (i = 0; i < USBD_CUSTOMHID_OUTREPORT_BUF_SIZE; i++)
dataToReceive[i] = hhid->Report_buf[i];
if ((dataToReceive[0] == 0) && (dataToReceive[1] == 0))
HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_RESET);
if ((dataToReceive[0] == 0) && (dataToReceive[1] == 1))
HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_SET);
if ((dataToReceive[0] == 1) && (dataToReceive[1] == 0))
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_RESET);
if ((dataToReceive[0] == 1) && (dataToReceive[1] == 1))
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_SET);
Ekleme :
USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef*)hUsbDeviceHS.pClassData;
Burada "HS" yerine "FS" yapman gerekecek.
Anladım sayılır. Bir deneme yaptım ama bir terslik var
PC den aygıtıma 64 bytelık bir paket gönderdiğim zaman CUSTOM_HID_OutEvent_FS fonksiyonu içine bir sürü olay düşüyor. Fonksiyon içerisinde muhittin hocamızın yaptığı gibi gelen paketi alıyorum. İlk gelen paket benim datalar, ama sonraki olaylar ile gelen paketler bana ait değil.