標(biāo)題:
MM32F103 USB應(yīng)用實(shí)例USB IAP通訊例程
[打印本頁]
作者:
ben.young
時(shí)間:
2020-7-30 16:41
標(biāo)題:
MM32F103 USB應(yīng)用實(shí)例USB IAP通訊例程
基于MM32F103 USB Custom_HID IAP 通訊例程,基于32位 ARM Cortex M3 的MM32F103xBx8的例程,BootLoader+Application兩部分
單片機(jī)源程序如下:
/* Includes ------------------------------------------------------------------*/
#include "MM32F103.h"
#include "usb_lib.h"
#include "hw_config.h"
#include "usbio.h"
#include "usb_regs.h"
#include "delay.h"
#include "sys.h"
#include "usb_pwr.h"
#include "usb_desc.h"
#include "platform_config.h"
#include "uart.h"
#include "bsp.h"
#include "led.h"
#include "pwm.h"
#include "tim2.h"
#include "usb_desc.h"
#include "string.h"
/* Private typedef -----------------------------------------------------------*/
#define PROTECT 0
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Extern variables ----------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
void Delay(__IO uint32_t nCount);
/* Private functions ---------------------------------------------------------*/
// MM32F103RBT6 Application 0x08002000 -- 0x08020000 120K byte flash
//#define ApplicationAddress 0x08002000 //APP addrress
//#define VECTOR_SIZE 0xC0 //48*4=192 = 0xC0
extern uint8_t Flag_Receive;
extern u32 SystemCoreClock;
extern u32 SystemCoreClock;
extern u8 Flag_over;
extern u8 count;
/*******************************************************************************
* Function Name : main.
* Description : main routine.
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
int main(void)
{
u16 data1, data2; //
u8 t;
SCB->VTOR = FLASH_BASE | FLASH_VTOR_OFFSET; /* Vector Table Relocation in Internal FLASH.*/
__enable_irq();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); // 設(shè)置中斷優(yōu)先級分組2
uart_initwBaudRate(115200);
#if PROTECT //是否開啟讀保護(hù)功能
data1 = *(u32 *)0x1ffe0000; //地址Address必須是2的整數(shù)倍
data2 = *(u32 *)0x1ffe0002; //地址Address必須是2的整數(shù)倍
printf("\r\n Data1=%x,Data2=%x \r\n", data1, data2);
if ((data1 != 0x7F80) || (data2 != 0xFF00))
{
printf("Pro1\r\n");
FLASH_Unlock();
FLASH_EnableReadOutProtection();
FLASH_UserOptionByteConfig(OB_IWDG_HW, OB_STOP_NoRST, OB_STDBY_NoRST);
FLASH_Lock();
}
#endif
delay_init(); //延時(shí)函數(shù)初始化
Set_System();
LED_Init();
USB_Interrupts_Config();
Set_USBClock();
USB_Init();
TIM1_PWM_Init(1000 - 1, 96 - 1);
Tim2_UPCount_test(500 - 1, 96 - 1);
while (1)
{
if (bDeviceState == CONFIGURED) //USB初始化完成
{
if (Flag_Receive)
{
APP_Program();
Flag_Receive = 0;
}
}
if (Flag_over) //將UART1 收到的數(shù)據(jù)重新發(fā)回去
{
Flag_over = 0;
for (t = 0; t < count; t++)
{
while ((UART1->CSR & UART_IT_TXIEN) == 0)
; //等待發(fā)送結(jié)束
UART1->TDR = UART_RX_BUF[t]; //TDR=buff[t];//
}
while ((UART1->CSR & UART_IT_TXIEN) == 0)
; //等待發(fā)送結(jié)束
count = 0;
}
}
}
/*******************************************************************************
* Function Name : Delay
* Description : Inserts a delay time.
* Input : nCount: specifies the delay time length.
* Output : None
* Return : None
*******************************************************************************/
void Delay(__IO uint32_t nCount)
{
for (; nCount != 0; nCount--)
;
}
#ifdef USE_FULL_ASSERT
/*******************************************************************************
* Function Name : assert_failed
* Description : Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* Input : - file: pointer to the source file name
* - line: assert_param error line source number
* Output : None
* Return : None
*******************************************************************************/
void assert_failed(uint8_t *file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
復(fù)制代碼
所有資料51hei提供下載:
MM32F103_USB_IAP_Protect.7z
(175.46 KB, 下載次數(shù): 55)
2020-7-30 16:41 上傳
點(diǎn)擊文件名下載附件
USB IAP
下載積分: 黑幣 -5
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1