找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2771|回复: 0
收起左侧

MM32F103 USB应用实例USB IAP通讯例程

[复制链接]
ID:714588 发表于 2020-7-30 16:41 | 显示全部楼层 |阅读模式
基于MM32F103 USB Custom_HID IAP 通讯例程,基于32位 ARM Cortex M3 的MM32F103xBx8的例程,BootLoader+Application两部分

单片机源程序如下:
  1. /* Includes ------------------------------------------------------------------*/
  2. #include "MM32F103.h"
  3. #include "usb_lib.h"
  4. #include "hw_config.h"
  5. #include "usbio.h"
  6. #include "usb_regs.h"
  7. #include "delay.h"
  8. #include "sys.h"

  9. #include "usb_pwr.h"
  10. #include "usb_desc.h"
  11. #include "platform_config.h"

  12. #include "uart.h"
  13. #include "bsp.h"
  14. #include "led.h"
  15. #include "pwm.h"
  16. #include "tim2.h"
  17. #include "usb_desc.h"
  18. #include "string.h"

  19. /* Private typedef -----------------------------------------------------------*/

  20. #define PROTECT 0

  21. /* Private define ------------------------------------------------------------*/
  22. /* Private macro -------------------------------------------------------------*/
  23. /* Private variables ---------------------------------------------------------*/
  24. /* Extern variables ----------------------------------------------------------*/
  25. /* Private function prototypes -----------------------------------------------*/
  26. void Delay(__IO uint32_t nCount);

  27. /* Private functions ---------------------------------------------------------*/

  28. // MM32F103RBT6  Application  0x08002000 -- 0x08020000 120K byte flash

  29. //#define ApplicationAddress  0x08002000   //APP addrress
  30. //#define VECTOR_SIZE  0xC0   //48*4=192 = 0xC0

  31. extern uint8_t Flag_Receive;

  32. extern u32 SystemCoreClock;

  33. extern u32 SystemCoreClock;
  34. extern u8 Flag_over;
  35. extern u8 count;

  36. /*******************************************************************************
  37. * Function Name  : main.
  38. * Description    : main routine.
  39. * Input          : None.
  40. * Output         : None.
  41. * Return         : None.
  42. *******************************************************************************/

  43. int main(void)
  44. {

  45.         u16 data1, data2; //
  46.         u8 t;

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

  48.         __enable_irq();

  49.         NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); // 设置中断优先级分组2
  50.         uart_initwBaudRate(115200);

  51. #if PROTECT //是否开启读保护功能

  52.         data1 = *(u32 *)0x1ffe0000; //地址Address必须是2的整数倍
  53.         data2 = *(u32 *)0x1ffe0002; //地址Address必须是2的整数倍

  54.         printf("\r\n Data1=%x,Data2=%x \r\n", data1, data2);

  55.         if ((data1 != 0x7F80) || (data2 != 0xFF00))
  56.         {

  57.                 printf("Pro1\r\n");
  58.                 FLASH_Unlock();
  59.                 FLASH_EnableReadOutProtection();
  60.                 FLASH_UserOptionByteConfig(OB_IWDG_HW, OB_STOP_NoRST, OB_STDBY_NoRST);
  61.                 FLASH_Lock();
  62.         }

  63. #endif

  64.         delay_init(); //延时函数初始化
  65.         Set_System();
  66.         LED_Init();
  67.         USB_Interrupts_Config();
  68.         Set_USBClock();
  69.         USB_Init();

  70.         TIM1_PWM_Init(1000 - 1, 96 - 1);

  71.         Tim2_UPCount_test(500 - 1, 96 - 1);

  72.         while (1)
  73.         {

  74.                 if (bDeviceState == CONFIGURED) //USB初始化完成
  75.                 {

  76.                         if (Flag_Receive)
  77.                         {
  78.                                 APP_Program();
  79.                                 Flag_Receive = 0;
  80.                         }
  81.                 }

  82.                 if (Flag_over) //将UART1 收到的数据重新发回去
  83.                 {
  84.                         Flag_over = 0;
  85.                         for (t = 0; t < count; t++)
  86.                         {
  87.                                 while ((UART1->CSR & UART_IT_TXIEN) == 0)
  88.                                         ;                                                 //等待发送结束
  89.                                 UART1->TDR = UART_RX_BUF[t]; //TDR=buff[t];//
  90.                         }
  91.                         while ((UART1->CSR & UART_IT_TXIEN) == 0)
  92.                                 ; //等待发送结束
  93.                         count = 0;
  94.                 }
  95.         }
  96. }

  97. /*******************************************************************************
  98. * Function Name  : Delay
  99. * Description    : Inserts a delay time.
  100. * Input          : nCount: specifies the delay time length.
  101. * Output         : None
  102. * Return         : None
  103. *******************************************************************************/
  104. void Delay(__IO uint32_t nCount)
  105. {
  106.         for (; nCount != 0; nCount--)
  107.                 ;
  108. }

  109. #ifdef USE_FULL_ASSERT
  110. /*******************************************************************************
  111. * Function Name  : assert_failed
  112. * Description    : Reports the name of the source file and the source line number
  113. *                  where the assert_param error has occurred.
  114. * Input          : - file: pointer to the source file name
  115. *                  - line: assert_param error line source number
  116. * Output         : None
  117. * Return         : None
  118. *******************************************************************************/
  119. void assert_failed(uint8_t *file, uint32_t line)
  120. {
  121.         /* User can add his own implementation to report the file name and line number,
  122.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  123.         /* Infinite loop */
  124.         while (1)
  125.         {
  126.         }
  127. }
  128. #endif

  129. /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
复制代码

所有资料51hei提供下载:
MM32F103_USB_IAP_Protect.7z (175.46 KB, 下载次数: 55)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表