二、连接ST-LINK V2
ST-LINK V2 STM32
3.3V 3V3
SWDIO SWIO
SWCLK SWCLK
GND GND
三、下载好keil5 MDK 版
计算机的,下载的软件应该很简单吧
四、安装驱动
先下载驱动
插上你的调试器,下载好打开下图这个,一直next就好,然后打开设备管理器
五、打开一个现成的工程昌弯塌
出现什么乱七八糟的先不要理他,后面我们慢慢调
六、配置
点击小魔术棒,找到debug,先找flash downlode
也可以去官网下载。
下载好后
file------------>import-------------------->找到刚刚下载的东西
一直next就好,前提你得安装好MDK版的keil5
Flash文件夹下就会多了很多东西
重新打开keil5,小魔术棒找到debug,进入setting,再选择debug,跟着选择这几个,闹宏点确定和OK,之后,如耐圆果出现,这是因为目标板的芯片处于休眠的状态,按复位键(板子上的小红色按键),再重新编译和下载就好,这样就是成功了的,现在可以看到板子一闪一闪的了。
1、 首先安装ST官方串口下丛斗载软件,Flash_Loader_Demonstrator_v2.2.0_Setup.exe
2、 用交叉串口渗含磨线连接开发板和电脑,
BOOT0选择为1,BOOT1选择为0,
接老此上开发板电源,SW1切换到ON打开电源开关。
3、 从开始程序菜单打开Flash Loader Demo程序,所有程序->STMicroelectronics->Flash
Loader Demonstrator->Flash Loader Demo
ain() { unsigned int aRCC_Configuration()/*初肆缺如始化扮烂 GPIOC时钟*/ // RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE)USART_Configuration()Delay(10)CAN_configure()// LedInit()while(1) { //CAN_ClearFlag(CAN_FLAG_BOF)GPIO_SetBits(GPIOB,GPIO_Pin_7)Delay(10)GPIO_ResetBits(GPIOB,GPIO_Pin_7)Delay(10)GPIO_SetBits(GPIOB,GPIO_Pin_7)Delay(10)GPIO_ResetBits(GPIOB,GPIO_Pin_7)Delay(10)can_send(0x57)a=can_rev()USART1_Putc(a)} } -------------------------------------------------------------------------------------------------- #include"stm32f10x_lib.h" void CAN_configure(void) { u8 wrongCAN_InitTypeDef CAN_InitStructureCAN_FilterInitTypeDef CAN_FilterInitStructureGPIO_InitTypeDef GPIO_InitStructure// RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO , ENABLE)/裂启/ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE)// RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN, ENABLE)/* Configure CAN pin: RX */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHzGPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPUGPIO_Init(GPIOA, &GPIO_InitStructure)/* Configure CAN pin: TX */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PPGPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHzGPIO_Init(GPIOA, &GPIO_InitStructure)/*can register int*/ CAN_DeInit()CAN_StructInit(&CAN_InitStructure)/*can cell init*/ CAN_InitStructure.CAN_TTCM=DISABLECAN_InitStructure.CAN_ABOM=DISABLECAN_InitStructure.CAN_AWUM=DISABLECAN_InitStructure.CAN_NART=DISABLECAN_InitStructure.CAN_RFLM=DISABLECAN_InitStructure.CAN_TXFP=DISABLECAN_InitStructure.CAN_Mode=CAN_Mode_LoopBackCAN_InitStructure.CAN_SJW=CAN_SJW_1tqCAN_InitStructure.CAN_BS1=CAN_BS1_8tqCAN_InitStructure.CAN_BS2=CAN_BS2_7tqCAN_InitStructure.CAN_Prescaler=5wrong=CAN_Init(&CAN_InitStructure)while(wrong==CANINITFAILED){} /* CAN filter init */ CAN_FilterInitStructure.CAN_FilterNumber=0CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMaskCAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bitCAN_FilterInitStructure.CAN_FilterIdHigh=0x0000//((u32)0x0020<<21)>>16//标识符 CAN_FilterInitStructure.CAN_FilterIdLow=0x0000//(((u32)0x0020<<21)|CAN_ID_STD|CAN_RTR_DATA)// CAN_FilterInitStructure.CAN_FilterMaskIdHigh=0x0000CAN_FilterInitStructure.CAN_FilterMaskIdLow=0x0000CAN_FilterInitStructure.CAN_FilterFIFOAssignment=0CAN_FilterInitStructure.CAN_FilterActivation=ENABLECAN_FilterInit(&CAN_FilterInitStructure)// CAN_ITConfig(CAN_IT_FMP0, ENABLE)} void can_send(unsigned char data) { CanTxMsg TxMessageu8 TransmitMailbox = 0TxMessage.StdId=0x0020//标识符 TxMessage.RTR=CAN_RTR_DATATxMessage.IDE=CAN_ID_STDTxMessage.DLC=2TxMessage.Data[0]=dataTxMessage.Data[1]=0xFETransmitMailbox=CAN_Transmit(&TxMessage)while(CAN_TransmitStatus(TransmitMailbox) != CANTXOK){}//等待发送 } unsigned char can_rev(void) { CanRxMsg RxMessageRxMessage.StdId=0x11//不需要设置 RxMessage.IDE=CAN_ID_STDRxMessage.DLC=2RxMessage.Data[0]=0x00RxMessage.Data[1]=0x00while (CAN_MessagePending(CAN_FIFO0)==0)//等到接收 CAN_Receive(CAN_FIFO0, &RxMessage)CAN_FIFORelease(CAN_FIFO0)return RxMessage.Data[0]} ------------------------------------------------------------------------------------------------- void RCC_Configuration(void) { //*** ErrorStatus HSEStartUpStatus//*** //* system clocks configuration -----------------系统时钟配置-------------------/// //* RCC system reset(for debug purpose) // RCC_DeInit()//将外设RCC寄存器重设为缺省值 //* Enable HSE * RCC_HSEConfig(RCC_HSE_ON)//开启外部高速晶振(HSE) //* Wait till HSE is ready / HSEStartUpStatus = RCC_WaitForHSEStartUp()//等待HSE起振 if(HSEStartUpStatus == SUCCESS) //若成功起振,(下面为系统总线时钟设置) { //* Enable Prefetch Buffer / FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable)//使能FLASH预取指缓存 //* Flash 2 wait state / FLASH_SetLatency(FLASH_Latency_2)//设置FLASH存储器延时时钟周期数(根据不同的系统时钟选取不同的值) //* HCLK = SYSCLK / RCC_HCLKConfig(RCC_SYSCLK_Div1)//设置AHB时钟=72 MHz //* PCLK2 = HCLK/2 / RCC_PCLK2Config(RCC_HCLK_Div2)//设置APB1时钟=36 MHz(APB1时钟最大值) //* PCLK1 = HCLK/2 / RCC_PCLK1Config(RCC_HCLK_Div2)//设置APB2时钟=72 MHz //* Configure ADCCLK such as ADCCLK = PCLK2/2 / // RCC_ADCCLKConfig(RCC_PCLK2_Div2)//RCC_PCLK2_Div2,4,6,8 //* PLLCLK = 8MHz * 9 = 72 MHz / RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9)//PLL必须在其激活前完成配置(设置PLL时钟源及倍频系数) //* Enable PLL / RCC_PLLCmd(ENABLE)//* Wait till PLL is ready / while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) { } //* Select PLL as system clock source / RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK)//* Wait till PLL is used as system clock source / while(RCC_GetSYSCLKSource() != 0x08) { } } //***** RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE)RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN, ENABLE)//***/ }欢迎分享,转载请注明来源:内存溢出
评论列表(0条)