新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > STM32F10x在環(huán)境下的開發(fā)過程

STM32F10x在環(huán)境下的開發(fā)過程

作者: 時間:2016-11-26 來源:網(wǎng)絡(luò) 收藏
STM 32F10x在EWARM-EV-WEB-520環(huán)境下的開發(fā)過程

(利用H-JTAG SERVER)

本文引用地址:http://m.butianyuan.cn/article/201611/321596.htm

一、首先下載ARM-based 32-bit MCU STM32F10xxx 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

二、建立STM32 LCCD工程

1.解壓stm32f10x_stdperiph_lib_v3.0.0.zip軟件包,把其中的“Libraries”和文件夾復(fù)制到“D:workslccd-1.0.0”,在“D:workslccd-1.0.0”下建立“Project”、“Drivers”、“Linker”、“Include”和“Source”空文件夾,在“D:workslccd-1.0.0Project”下建立“Stm32f103”空文件夾,把壓縮包的“ProjectTemplate”下的C文件復(fù)制到“Source”和H文件復(fù)制到“Include”,把“ProjectTemplateEWARMv5”下的所有ICF文件復(fù)制到“Linker”;

2.在EWARM菜單中“Project”->“Create New Project”打開“Create New Project”窗口,點擊“OK”打開“另存為”窗口,選擇項目工程存儲路徑“D:workslccd-1.0.0ProjectStm32f103”填寫項目文件名“lccd.ewp",在菜單中“File”->“Save All”打開“Save Workspace As”窗口,填寫工作環(huán)境文件名“lccd.eww”;
3.在EWARM的左面“Workspace”窗口下面的“Files”空白部分右擊鼠標,選擇“Add”->“Add Group”出現(xiàn)““Add Group - lccd”窗口,在“Group name”中填上“CMSIS”,同樣方法建立“USER”“BOOT”“DRV”“INC”“LIB”等文件組后點擊“Save All”快捷鍵;
4.在EWARM的左面“Workspace”窗口下面的“CMSIS”上右擊鼠標,選擇“Add”->“Add Files”出現(xiàn)“Add Files - CMSIS”窗口,選擇打開“D:workslccd-1.0.0LibrariesCMSISCoreCM3”文件夾下的“core_cm3.c”和“system_stm32f10x.c”文件;
5.在EWARM的左面“Workspace”窗口下面的“BOOT”上右擊鼠標,選擇“Add”->“Add Files”出現(xiàn)“Add Files - BOOT”窗口,選擇打開“D:workslccd-1.0.0LibrariesCMSISCoreCM3startupiar”文件夾下的“startup_stm32f10x_md.s”文件;
6.在EWARM的左面“Workspace”窗口下面的“LIB”上右擊鼠標,選擇“Add”->“Add Files”出現(xiàn)“Add Files - LIB”窗口,選擇打開“D:workslccd-1.0.0LibrariesSTM32F10x_StdPeriph_Driversrc”文件夾下的“stm32f10x_gpio.c”等所有C文件;
7.在EWARM的左面“Workspace”窗口下面的“INC”上右擊鼠標,選擇“Add”->“Add Files”出現(xiàn)“Add Files - INC”窗口,選擇打開“D:workslccd-1.0.0Include”文件夾下的所有H文件;
8.在EWARM的左面“Workspace”窗口下面的“USER”上右擊鼠標,選擇“Add”->“Add Files”出現(xiàn)“Add Files - USER”窗口,選擇打開“D:workslccd-1.0.0Source”文件夾下的所有C文件,點擊“Save All”快捷鍵;

三、配置STM32 LCCD工程

在EWARM的左面“Workspace”窗口下面的“Files”的“lccd - Debug”左擊鼠標,選擇“Project”->“Options”出現(xiàn)“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中仿真應(yīng)填“$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”完成設(shè)置,單擊OK。

(若選擇release模式,則在EWARM的左面“Workspace”窗口下選擇“Release”,然后可以對“lccd - Release”左擊鼠標,選擇“Project”->“Options”出現(xiàn)“Options for node "lccd"”窗口,做類似上面“lccd_Debug”的配置,注意不選擇調(diào)試信息及目標友文件名為lccd_release_1.0.0.bin;)

四、調(diào)試STM32 LCCD工程

1.在EWARM菜單中“Project”->“Make”打開編譯工程命令;
2.在EWARM菜單中“Project”->“Download and Debug”打開下載調(diào)試命令;
3.在EWARM菜單中“Debug”->“Go”打開全速運行命令;
4.其它調(diào)試命令請自行嘗試;

五、修改STM32 LCCD工程

1.移植USART的PRINTF應(yīng)用
A.把D:workslccd-1.0.0Includestm32f10x_conf.h的第46行的注釋打開;
B.把D:workslccd-1.0.0ProjectExamplesUSARTPrintfplatform_config.h復(fù)制到D:workslccd-1.0.0Include目錄;
C.把D:workslccd-1.0.0ProjectExamplesUSARTPrintfmain.c復(fù)制到D:workslccd-1.0.0Source;
D.編譯調(diào)試即可以在UART1看到115200 8N1的字符“USART Printf Example: retarget the C library printf function to the USART”
2.整理USART的PRINTF應(yīng)用

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)
{
}
}



評論


技術(shù)專區(qū)

關(guān)閉