您尚未登录。

楼主 #1 2020-05-09 20:47:00

缥缈九哥
会员
注册时间: 2020-05-09
已发帖子: 76
积分: 92

9G-STM32 EWARM开发过程简介--缥缈九哥

9G-STM32 EWARM开发过程简介

一,准备EWARM+JLINK+STM32软件包

1,在http://www.mcu123.com/down/view.asp?id=83
    下载IAR Embedded Workbench for ARM v5.20版本
    EWARM-EV-WEB-520.rar
    http://esoft.mcu123.com/MCU123_temp_0080309@/arm/EWARM-EV-WEB-520.rar
    (注册机自行查找,安装过程略)
2,在http://www.segger.com/download_jlink.html
    下载Software and documentation pack V4.04a软件
Setup_JLinkARM_V404a.zip
http://www.segger.com/pub/jlink/Setup_JLinkARM_V404a.zip
    (JLINK自行购买,安装过程略)
3,在http://www.st.com/mcu/devicedocs-STM32F103T8-110.html
    下载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”和“Project”文件夹复制到“D:\works\lccd-1.0.0\”,
在“D:\works\lccd-1.0.0\”下建立“Drivers”、“Linker”、“Include”和“Source”空文件夹,在“D:\works\lccd-1.0.0\Project”
下建立“Stm32f103”空文件夹,把“Project\Template”下的C文件复制到“Source”和H文件复制到“Include”,把“Project\Template\
EWARMv5”下的所有ICF文件复制到“Linker”;
2,在EWARM菜单中“Project”->“Create New Project”打开“Create New Project”窗口,点击“OK”打开“另存为”窗口,
选择项目工程存储路径“D:\works\lccd-1.0.0\Project\Stm32f103\”填写项目文件名“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:\works\lccd-1.0.0\Libraries\CMSIS\Core\CM3”文件夹下的“core_cm3.c”和“system_stm32f10x.c”文件;
5,在EWARM的左面“Workspace”窗口下面的“BOOT”上右击鼠标,选择“Add”->“Add Files”出现““Add Files - BOOT”窗口,选择
打开“D:\works\lccd-1.0.0\Libraries\CMSIS\Core\CM3\startup\iar”文件夹下的“startup_stm32f10x_md.s”文件;
6,在EWARM的左面“Workspace”窗口下面的“LIB”上右击鼠标,选择“Add”->“Add Files”出现““Add Files - LIB”窗口,选择
打开“D:\works\lccd-1.0.0\Libraries\STM32F10x_StdPeriph_Driver\src”文件夹下的“stm32f10x_gpio.c”等所有C文件;
7,在EWARM的左面“Workspace”窗口下面的“INC”上右击鼠标,选择“Add”->“Add Files”出现““Add Files - INC”窗口,选择
打开“D:\works\lccd-1.0.0\Include”文件夹下的所有H文件;
8,在EWARM的左面“Workspace”窗口下面的“USER”上右击鼠标,选择“Add”->“Add Files”出现““Add Files - USER ”窗口,选择
打开“D:\works\lccd-1.0.0\Source”文件夹下的所有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$\..\..\Libraries\CMSIS\Core\CM3
  $PROJ_DIR$\..\..\Libraries\STM32F10x_StdPeriph_Driver\inc
在“Preprocessor”->“Define symbols:”中填上下面几行:
  USE_STDPERIPH_DRIVER
  STM32F10X_MD
  USE_STM3210B_EVAL(我暂时不用)

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$\..\..\Linker\stm32f10x_flash.icf”,在“List”中勾选“Generate linker map file”;

5,在左面“Category:”中选择上“Debugger”,在“Setup”->“Driver”中选择“J-link/J-trace”,在“Download”勾选择“Use flash loader”;

6,在左面“Category:”中选择上“J-link/J-trace”,在“Setup”->“JTAG/SWD speed”中选择“Fixed”并填上“4000”,在“Connection”->“Interface”
中选择“SWD”,点击“Save All”快捷键;

7,在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:\works\lccd-1.0.0\Include\stm32f10x_conf.h的第46行的注释打开;
B,把D:\works\lccd-1.0.0\Project\Examples\USART\Printf\platform_config.h 复制到D:\works\lccd-1.0.0\Include\目录;
C,把D:\works\lccd-1.0.0\Project\Examples\USART\Printf\main.c 复制到D:\works\lccd-1.0.0\Source;
D,编译调试即可以在 RT1看到115200 8N1的字符“USART Printf Example: retarget the C library printf function to the USART”

2,整理USART的PRINTF应用

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

 /* Includes ------------------------------------------------------------------*/
 #include "stm32f10x.h"
 #include "stdio.h"
 #include "platform_config.h"
 
 /** @addtogroup StdPeriph_Examples
   * @{
   */
 
 /** @addtogroup USART_Printf
   * @{
   */
 
 /* Private typedef -----------------------------------------------------------*/
 /* Private define ------------------------------------------------------------*/
 /* Private macro -------------------------------------------------------------*/
 /* Private variables ---------------------------------------------------------*/
 
 /* Private function prototypes -----------------------------------------------*/
 void RT_Configuration(void);
 
 /* Private functions ---------------------------------------------------------*/
 
 
 /**
   * @brief  Configures the different GPIO ports.
   * @param  None
   * @retval : None
   */
 void RT_Configuration(void)
 {
   GPIO_InitTypeDef GPIO_InitStructure;
   USART_InitTypeDef USART_InitStructure;
 
 #if defined USE_USART2 && defined USE_STM3210B_EVAL
   /* Enable AFIO clock */
   RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
 
   /* Enable the USART2 Pins Software Remapping */
   GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
 #endif
 
   /* Configure USARTx_Tx as alternate function push-pull */
   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);
 
   /* Configure USARTx_Rx as input floating */
   GPIO_InitStructure.GPIO_Pin = GPIO_RxPin;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
   GPIO_Init(GPIOx, &GPIO_InitStructure);
 
   /* USARTx configuration ------------------------------------------------------*/
   /* USARTx configured as follow:
         - BaudRate = 115200 baud 
         - Word Length = 8 Bits
         - One Stop Bit
         - No parity
         - Hardware flow control disabled (RTS and CTS signals)
         - Receive and transmit enabled
   */
   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;
  
   /* Configure the USARTx */
   USART_Init(USARTx, &USART_InitStructure);
   /* Enable the USARTx */
   USART_Cmd(USARTx, ENABLE);
  
 }
 
 /**
   * @brief  Retargets the C library printf function to the USART.
   * @param  None
   * @retval : None
   */
 int fputc(int ch, FILE *f)
 {
   /* Write a character to the USART */
   USART_SendData(USARTx, (uint8_t) ch);
 
   /* Loop until the end of transmission */
   while(USART_GetFlagStatus(USARTx, USART_FLAG_TXE) == RESET)
   {
   }
 
   return ch;
 }
 /*******************************************************************************
 * Function Name  : fgetc
 * Description    : Get a key from the HyperTerminal
 * Input          : None
 * Output         : None
 * Return         : The Key Pressed
 *******************************************************************************/
 int fgetc(FILE *f)
 {
  /* Waiting for user input */
  while ( USART_GetFlagStatus(USARTx, USART_FLAG_RXNE) == RESET);
  return (uint8_t)USARTx->DR;
 }
B,修改D:\works\lccd-1.0.0\Source\main.c的int main(void)如下:
 int main(void)
 {
   /* System Clocks Configuration */
   RCC_Configuration();
 
   /* Configure the GPIO ports */
   RT_Configuration();
 
   /* Output a message on Hyperterminal using printf function */
   printf("\n\r\n\r\n\r\n\r");
   printf("*** LCCD V1.0 Build by y nxih @21cn.com on ("__DATE__ " - " __TIME__ ")\n\r");
   printf("*** LCCD V1.0 Rebooting ...\n\r");
 
   while (1)
   {
   }
 }

并在文件前添加:
extern void RT_Configuration(void);

最近编辑记录 缥缈九哥 (2020-05-09 20:47:49)

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn