STM32初始

1.安装软件、驱动

  JLINK驱动、PL2303驱动、MDK4.7(装完破解)   

2.源码编译完要用到的工具

  烧录工具MCUISP、串口调试助手

3.KEIL建工程模板(2种)

   (1)寄存器开发:工程文件夹下建2文件夹命名“USER”“SYSTEM”———新建工程到“USER” 选择‘是’———拷贝例子程序中的“SYSTEM”覆盖———KEIL中右键Target1选Manage Components,Groups下建“USER”“SYSTEM”———为“SYSTEM”添加delay.c sys.c usart.c———Project下Options for Target ‘target1’_C/C++中‘Include Paths’添加3个C文件的头文件———Output下勾选‘Create HEX File’  OK!

        测试代码(STM32F103RB):

int main (void)
{
u8 t=0;
Stm32_Clock_Init(9);
delay_init(72);
uart_init(72,9600);
while(1)
{
printf("t:%d\n",t);
delay_ms(500);
t++;
}

}

(2)库函数开发:

建STM32F10x_FWLib:拷STM32F10x_StdPeriph_Lib_V3.5.0\Libraries\STM32F10x_StdPeriph_Driver下src、inc文件夹

建CORE:拷1.STM32F10x_StdPeriph_Lib_V3.5.0\Libraries\CMSIS\CM3\CoreSupport下core_cm3.c和core_cm3.h

2.STM32F10x_StdPeriph_Lib_V3.5.0\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\arm下所有文件(s..x_md.s中等容量,ls小,hs大) 

建USER:拷1.STM32F10x_StdPeriph_Lib_V3.5.0\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x中stm32f10x.h,system_stm32f10x.c,system_stm32f10x.h

2.STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Template下4个文件main.c,stm32f10x_conf.h,stm32f10x_it.c,stm32f10x_it.h

右键点击Target1选Manage Components将Target名字改掉,Groups栏删掉一个,建USER,CORE,FWLIB,

为1.FWLIB添加STM32F10x_FWLib/src下要用到的外设的库文件

       2. CORE添加core_cm3.c,startup_stm32f10x_md.s

       3. USER添加main.c,stm32f10x_it.c,system_stm32f10x.c

魔术棒c/c++选项.1.Include Paths添加3个目录,注意STM32F10x_FWLib的是定位到inc文件夹

           2.C/C++__Preprocessor Symbols__Define中填上“STM32F10X_MD,USE_STDPERIPH_DRIVER”(不要引号STM32F10X_MD大容量STM32F10X_LD小容量

           3.Output勾选HEX选项

覆盖掉main.c中代码

#include "stm32f10x.h"
GPIO_InitTypeDef GPIO_InitStructure;

int main(void)
{
SystemInit();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_2;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOD, &GPIO_InitStructure);
while (1)
{
/* Set PD0 and PD2 */
GPIOD->BSRR = 0x00000005;
/* Reset PD0 and PD2 */
GPIOD->BRR = 0x00000005;
}
}

#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t* file, uint32_t line)
{
while (1)
{
}
}
#endif

OK!

 

 

 

posted @ 2013-10-25 21:57  Ray*  阅读(234)  评论(0编辑  收藏  举报