银杏科技有限公司旗下技术文档发布平台 | |||
技术支持电话 | 0379-69926675-801 | ||
技术支持邮件 | Gingko@vip.163.com | ||
版本 | 日期 | 作者 | 修改内容 |
---|---|---|---|
V1.0 | 2020-04-17 | gingko | 初次建立 |
1. 新建工程:在主界面选择File–>New Project 或者直接点击ACCEE TO MCU SELECTOR 2. 出现芯片型号选择,搜索自己芯片的型号,双击型号,或者点击Start Project进入配置 在搜索栏的下面,提供的各种查找方式,可以选择芯片内核、型号等等,可以帮助你查找芯片。本实验选取的芯片型号为:STM32F407IGTx。 3. 配置RCC,使用外部时钟源 4. 配置调试引脚 5. 将LED对应的3个引脚(PI5,PI6,PI7)设置为GPIO_Output 6. 引脚模式配置 7. 打开PH15为输入模式 8. 使能RTC时钟 9. 使能USB_Device,将PH4管脚功能选择为USB_OTG_HS_ULPI_NXT 10. 打开USB_Device,选择HID模式 11. 时钟源设置,选择外部高速时钟源,配置为最大主频 12. 工程文件的设置, 这里就是工程的各种配置 我们只用到有限几个,其他的默认即可 IDE我们使用的是 MDK5 13. 点击Code Generator,进行进一步配置
自行选择方式即可
14. 然后点击GENERATE CODE 创建工程 创建成功,打开工程。
int main(void) { /* USER CODE BEGIN 1 */ int i; unsigned char buffer[64]; unsigned char send_buffer[64]; static int counter; RTC_DateTypeDef sDate; RTC_TimeTypeDef sTime; /* USER CODE END 1 */ HAL_Init(); SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_RTC_Init(); MX_USB_DEVICE_Init(); /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ if(systick.second_flag == 1){ systick.second_flag = 0; if(hUsbDeviceHS.dev_state == USBD_STATE_CONFIGURED){ if(counter ++ % 2){ HAL_RTC_GetTime(&hrtc, &sTime, RTC_FORMAT_BIN); HAL_RTC_GetDate(&hrtc, &sDate, RTC_FORMAT_BIN); memset(send_buffer,0,64); sprintf((char *)send_buffer,"time:%02d:%02d:%02d %02d-%02d-%02d",sTime.Hours,sTime.Minutes,sTime.Seconds,sDate.Year,sDate.Month,sDate.Date); USBD_HID_SendReport(&hUsbDeviceHS,send_buffer,64); }else{ memset(send_buffer,0,64); if(ARM_KEY_STATE == KEY_DOWN) sprintf((char *)send_buffer,"key:KEY PRESS"); else sprintf((char *)send_buffer,"key:"); USBD_HID_SendReport(&hUsbDeviceHS,send_buffer,64); } } } //接收命令处理 if(usb_receive_flag == 1){ usb_receive_flag = 0; memcpy(buffer,usb_receive_buffer,usb_receive_counter); memset(usb_receive_buffer,0,usb_receive_counter); for(i = 0;i < 64;i++){ buffer[i] = tolower(buffer[i]); } command_process(buffer); } } }
void HAL_SYSTICK_Callback(void) { //中断时间1ms, static int counter = 0; if((counter ++ % 250) == 0){ systick.second_flag = 1; } }
static uint8_t USBD_HID_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum) { if(epnum == HID_EPOUT_ADDR){ usb_receive_counter = USBD_GetRxCount(pdev,epnum); if(pdev->dev_state == USBD_STATE_CONFIGURED){ usb_receive_flag = 1; USBD_LL_PrepareReceive(pdev,HID_EPOUT_ADDR,usb_receive_buffer,HID_EPOUT_SIZE); } } return USBD_OK; }
/* Open Ep Out */ USBD_LL_OpenEP(pdev, HID_EPOUT_ADDR, USBD_EP_TYPE_INTR, HID_EPOUT_SIZE); /* Prepare Out endpoint to receive next packet */ USBD_LL_PrepareReceive(pdev, HID_EPOUT_ADDR, usb_receive_buffer, HID_EPOUT_SIZE);
#define HID_EPOUT_ADDR 0x01 #define HID_EPOUT_SIZE 0x40
#define USBD_VID 0x483 #define USBD_LANGID_STRING 1033 #define USBD_MANUFACTURER_STRING "Gingko" #define USBD_PID_HS 0x5720 #define USBD_PRODUCT_STRING_HS "iCore3 in HS mode" #define USBD_SERIALNUMBER_STRING_HS "00000000001A" #define USBD_CONFIGURATION_STRING_HS "HID Config" #define USBD_INTERFACE_STRING_HS "HID Interface" #define USB_SIZ_BOS_DESC 0x0C