新闻中心

EEPW首页>嵌入式系统>设计应用> STM32F10x在环境下的开发过程

STM32F10x在环境下的开发过程

作者: 时间:2016-11-26 来源:网络 收藏
STM 32F10x在EWARM-EV-WEB-520环境下的开发过程

(利用H-JTAG SERVER)

本文引用地址://m.amcfsurvey.com/article/201611/321596.htm

一、首先下载ARM-based 32-bit MCUSTM32F10xxx standard peripheral library
stm32f10x_stdperiph_lib_v3.0.0.zip
http://www.st.com/stonline/products/support/micro/files/stm32f10x_stdperiph_lib_v3.0.0.zip

二、建立STM32LCCD工程

1.解压stm32f10x_stdperiph_lib_v3.0.0.zip软件包,把其中的“Libraries”和文件夹复制到“D:workslccd-1.0.0”,在“D:workslccd-1.0.0”下建立“Project”、“Drivers”、“Linker”、“Include”和“Source”空文件夹,在“D:workslccd-1.0.0Project”下建立“Stm32f103”空文件夹,把压缩包的“ProjectTemplate”下的C文件复制到“Source”和H文件复制到“Include”,把“ProjectTemplateEWARMv5”下的所有ICF文件复制到“Linker”;

2.在EWARM菜单中“Project”->“Create New Project”打开“Create New Project”窗口,点击“OK”打开“另存为”窗口,选择项目工程存储路径“D:workslccd-1.0.0ProjectStm32f103”填写项目文件名“lccd.ewp",在菜单中“File”->“Save All”打开“Save Workspace As”窗口,填写工作环境文件名“lccd.eww”;
3.在EWARM的左面“Workspace”窗口下面的“Files”空白部分右击鼠标,选择“Add”->“Add Group”出现““Add Group - lccd”窗口,在“Group name”中填上“CMSIS”,同样方法建立“USER”“BOOT”“DRV”“INC”“LIB”等文件组后点击“Save All”快捷键;
4.在EWARM的左面“Workspace”窗口下面的“CMSIS”上右击鼠标,选择“Add”->“Add Files”出现“Add Files - CMSIS”窗口,选择打开“D:workslccd-1.0.0LibrariesCMSISCoreCM3”文件夹下的“core_cm3.c”和“system_stm32f10x.c”文件;
5.在EWARM的左面“Workspace”窗口下面的“BOOT”上右击鼠标,选择“Add”->“Add Files”出现“Add Files - BOOT”窗口,选择打开“D:workslccd-1.0.0LibrariesCMSISCoreCM3startupiar”文件夹下的“startup_stm32f10x_md.s”文件;
6.在EWARM的左面“Workspace”窗口下面的“LIB”上右击鼠标,选择“Add”->“Add Files”出现“Add Files - LIB”窗口,选择打开“D:workslccd-1.0.0LibrariesSTM32F10x_StdPeriph_Driversrc”文件夹下的“stm32f10x_gpio.c”等所有C文件;
7.在EWARM的左面“Workspace”窗口下面的“INC”上右击鼠标,选择“Add”->“Add Files”出现“Add Files - INC”窗口,选择打开“D:workslccd-1.0.0Include”文件夹下的所有H文件;
8.在EWARM的左面“Workspace”窗口下面的“USER”上右击鼠标,选择“Add”->“Add Files”出现“Add Files - USER”窗口,选择打开“D:workslccd-1.0.0Source”文件夹下的所有C文件,点击“Save All”快捷键;

三、配置STM32 LCCD工程

在EWARM的左面“Workspace”窗口下面的“Files”的“lccd - Debug”左击鼠标,选择“Project”->“Options”出现“Options for node "lccd"”窗口;

1.在左面“Category:”中选择上“General Options”,在“Target”->“Processor Variant”->“Device”中选择“ST STM32F10xx8”,
在“Library Configuration”->“Library”中选择“FULL”;
2.在左面“Category:”中选择上“C/C Complier”,在“Preprocessor”->“Additional include directories:”中填上下面几行:
$PROJ_DIR$....Include
$PROJ_DIR$....LibrariesCMSISCoreCM3
$PROJ_DIR$....LibrariesSTM32F10x_StdPeriph_Driverinc在“Preprocessor”->“Definesymbols:”中填上下面几行:
USE_STDPERIPH_DRIVER
STM32F10X_MD
USE_STM3210B_
3.在左面“Category:”中选择上“Output Converter”,在“Output”中勾选“Generate addition output”并在“Output format:”中选择“binary”,在“Output”->“Output file”中勾选“override default”并填写上目标码文件名:lccd_debug_1.0.0.bin;

4.在左面“Category:”中选择上“Linker”,在“Config”->“Linker configuration file”中勾选“override default”,在下面填上:“$PROJ_DIR$....Linkerstm32f10x_flash.icf”(如果要在sram中仿真应填“$PROJ_DIR$....Linkerstm32f10x_sram.icf”),在“List”中勾选“Generate linker map file”;

5.在左面“Category:”中选择上“Debugger”,在“Setup”->“Driver”中选择“RDI”,在“Download”勾选择“Use flash loader”;(如果要在sram中仿真,则不勾选“Use flash loader”)

6.在左面“Category:”中选择上“RDI”,在“Manufacturer RDI driver”中选择“C:Program FilesH-JTAGH-JTAG.dll”完成设置,单击OK。

(若选择release模式,则在EWARM的左面“Workspace”窗口下选择“Release”,然后可以对“lccd - Release”左击鼠标,选择“Project”->“Options”出现“Options for node "lccd"”窗口,做类似上面“lccd_Debug”的配置,注意不选择调试信息及目标友文件名为lccd_release_1.0.0.bin;)

四、调试STM32 LCCD工程

1.在EWARM菜单中“Project”->“Make”打开编译工程命令;
2.在EWARM菜单中“Project”->“Download and Debug”打开下载调试命令;
3.在EWARM菜单中“Debug”->“Go”打开全速运行命令;
4.其它调试命令请自行尝试;

五、修改STM32 LCCD工程

1.移植USART的PRINTF应用
A.把D:workslccd-1.0.0Includestm32f10x_conf.h的第46行的注释打开;
B.把D:workslccd-1.0.0ProjectExamplesUSARTPrintfplatform_config.h复制到D:workslccd-1.0.0Include目录;
C.把D:workslccd-1.0.0ProjectExamplesUSARTPrintfmain.c复制到D:workslccd-1.0.0Source;
D.编译调试即可以在UART1看到115200 8N1的字符“USART Printf Example: retarget the C library printf function to the USART”
2.整理USART的PRINTF应用

A.选择Workspace”窗口下的“DRV”用“Project”->“Add Files”把“D:workslccd-1.0.0Driversuart.c”添加到工程;
D:workslccd-1.0.0Driversuart.c的源码如下:

#include "stm32f10x.h"
#include "stdio.h"
#include "platform_config.h"

void UART_Configuration(void);

void UART_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;

#if defined USE_USART2 && defined USE_STM3210B_

RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);

GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
#endif
GPIO_InitStructure.GPIO_Pin = GPIO_TxPin;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOx, &GPIO_InitStructure);


GPIO_InitStructure.GPIO_Pin = GPIO_RxPin;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOx, &GPIO_InitStructure);

USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No ;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

USART_Init(USARTx, &USART_InitStructure);

USART_Cmd(USARTx, ENABLE);

}


int fputc(int ch, FILE *f)
{

USART_SendData(USARTx, (uint8_t) ch);


while(USART_GetFlagStatus(USARTx, USART_FLAG_TXE) == RESET)
{
}

return ch;
}

int fgetc(FILE *f)
{

while ( USART_GetFlagStatus(USARTx, USART_FLAG_RXNE) == RESET);
return (uint8_t)USARTx->DR;
}
B,修改D:workslccd-1.0.0Sourcemain.c的int main(void)如下:
int main(void)
{

RCC_Configuration();


UART_Configuration();


printf("");
printf("*** LCCD V1.0 Build byyuanxihua@21cn.comon ("__DATE__ " - " __TIME__ ")");
printf("*** LCCD V1.0 Rebooting ...");

while (1)
{
}
}



评论


技术专区

关闭