第三步:STM32开发工具学习

来源:互联网 发布:大数据算法模型 编辑:程序博客网 时间:2024/05/23 13:15

这一步是难点

就像学习使用筷子一样

用的好差 决定你将来吃的饱不饱


1--------MDK开发实例

http://wenku.baidu.com/view/0fc26329bd64783e09122b65.html   官方固件庫

http://wenku.baidu.com/view/8d3aa300cc175527072208cf.html   官方固件庫

http://wenku.baidu.com/view/5eaa807da26925c52cc5bf10.html   用mdk自帶庫



2--------图片教程

http://bbs.ednchina.com/BLOG_ARTICLE_3000296.HTM




3--------又教程

http://www.eefocus.com/yuanxihua/blog/09-10/178901_ea159.html

9G-STM32 MDK-ARM开发过程简介

一,准备MDK-ARM+JLINK+STM32软件包

1,在http://www.mcu123.com/news/Soft/embsof/arm/200908/505.html
    下载RealView MDK-ARM 3.80a(MDK-ARM V3.80a,MDK3.80a)版本
    mdk380a_mcu123.rar
    http://esoft.mcu123.com/MCU123_temp_0080309@/arm/mdk380a_mcu123.rar
    (注册机自行查找,安装过程略)
2,在http://www.segger.com/cms/jlink-software.html
    下载Software and documentation pack V4.08l软件
 Setup_JLinkARM_V408l.zip
 http://www.segger.com/cms/admin/uploads/userfiles/file/J-Link/Setup_JLinkARM_V408l.zip
    (JLINK自行购买,安装过程略)
3,在http://www.st.com/mcu/familiesdocs-110.html
    下载ARM-based 32-bit MCU STM32F10xxx standard peripheral library
    stm32f10x_stdperiph_lib.zip
 http://www.st.com/stonline/products/support/micro/files/stm32f10x_stdperiph_lib.zip
       
二,建立STM32工程

1,解压stm32f10x_stdperiph_lib.zip软件包,把其中的“Libraries”和“Project”文件夹复制到“D:\works\EK-STM3210E-MDK\”,
 在“D:\works\EK-STM3210E-MDK\”下建立“Drivers”、“Include”和“Source”空文件夹,在“D:\works\lccd-1.0.0\Project”
 下建立“Stm32f103”空文件夹,把“Project\Template”下的C文件复制到“Source”和H文件复制到“Include”;
2,在Keil uVision3菜单中“Project”->“New uVision Project”打开“Create New Project”窗口,选择项目工程存储路径
 “D:\works\EK-STM3210E-MDK\Project\Stm32f103”填写项目文件名“stm32.uv2",选择“保存”后自动打开“Select Device for
 Target "Target 1"”窗口,在左面“CPU”页面下的“Data base”点开“STMicroelectronics”前面的“+”选择上“STM32F103ZD”
 点击“OK”再确定“是”;
3,在Keil uVision3菜单中“Project”->“New Project Workspace”打开“Create New Multi Project Workspace”窗口,选择项目
 工作区存储路径“D:\works\EK-STM3210E-MDK\Project\Stm32f103”填写工作区文件名“stm32.mpw",点击“保存”打开
 “Create New Multi-Project Workspace”窗口,点击插入项目,然后选择到刚才建立的“stm32.uv2"再点“OK”“确定”
 即可建立一个新的 Workspace;
4,在Keil uVision3菜单中“Project”->“Manage”选择“Project "stm32" Components”打开“Components Environment and Books”窗口,
 把“Target 1”改为“EK-STM3210E”把“Source Group 1”以为“BOOT”点击“OK”;并在“Groups”下建立“SRC”,“DRV”,“SRC”,
 “INC”,“SDRV”等 目录;
5,在Keil uVision3的左面“Workspace”窗口下面的“BOOT”上右击鼠标,选择“Add Files to Group "BOOT"”选择上文件
 “D:\works\EK-STM3210E-MDK\Libraries\CMSIS\Core\CM3”文件夹下的“core_cm3.c”和“system_stm32f10x.c”文件,和
 D:\works\EK-STM3210E-MDK\Libraries\CMSIS\Core\CM3\startup\arm文件夹下的“startup_stm32f10x_hd.s”后点击“CLOSE”退出;
6,在Keil uVision3的左面“Workspace”窗口下面的“SDRV”上右击鼠标,选择“Add Files to Group "SDRV"”选择上文件
 “D:\works\EK-STM3210E-MDK\Libraries\STM32F10x_StdPeriph_Driver\src”文件夹下的所有C文件后点击“CLOSE”退出;
7,在Keil uVision3的左面“Workspace”窗口下面的“SRC”上右击鼠标,选择“Add Files to Group "SRC"”选择上文件
 “D:\works\EK-STM3210E-MDK\Source”文件夹下的“main.c”和“stm32f10x_it.c”文件后点击“CLOSE”退出;
8,在Keil uVision3的左面“Workspace”窗口下面的“DRV”上右击鼠标,选择“Add Files to Group "DRV"”选择上文件
 “D:\works\EK-STM3210E-MDK\Source”文件夹下的“serial.c”文件后点击“CLOSE”退出;

三,配置STM32工程

在Keil uVision3的左面“Workspace”窗口下面的“EK-STM3210E”右击鼠标,选择“Options for Target "EK-STM3210E"”窗口;

1,在页面“Device”中选择上“STMicroelectronics”下面的STM32F103ZD”,
 在页面“TarGet”中选择上“USE microLIB”;
2,在页面“Output”中选择上“Select Folder for Objects...”,在文件夹选择框中指定到路径:
 D:\works\EK-STM3210E-MDK\Project\Stm32f103\obj 后点击“OK”;并勾选上Create HEX File,
 产生“Debug information”浏览“Browse information”;
3,在页面“Listing”中选择上“Select Folder for Listing...”,在文件夹选择框中指定到路径:
 D:\works\EK-STM3210E-MDK\Project\Stm32f103\lst 后点击“OK”;并勾选上C Compiler Listing
 和 C Preprocessor Listing (看看自己是否需要);
 
4,在页面“C/C++”中的“Include Paths ”,中添加:
 ..\..\Libraries\STM32F10x_StdPeriph_Driver\inc
 ..\..\Libraries\CMSIS\Core\CM3
 ..\..\Include
 在页面“C/C++”中的“Preprocessor Symbols”,中添加:
 USE_STDPERIPH_DRIVER, USE_FULL_ASSERT, STM32F10X_HD,USE_STM3210C_EVAL
5,在页面“ASM”中的“Include Paths ”,中添加:
 ..\..\Libraries\STM32F10x_StdPeriph_Driver\inc
 ..\..\Libraries\CMSIS\Core\CM3
 ..\..\Include
 在页面“ASM”中的“Preprocessor Symbols”,中添加:
 USE_STDPERIPH_DRIVER, USE_FULL_ASSERT, STM32F10X_HD,USE_STM3210C_EVAL6,在页面“Debug”中选择右边的硬件仿真功能的“Cortex-M3 J-LINK”,并点开右面的“Settings”配置页面,选择SW接口并把速度改成2M;
 在“Flash Download”的编程算法选择上“STM32F10x High-density Flash”;

7,在页面“Utlites”中硬件FLASH编程工具“Cortex-M3 J-LINK”,并点开右面的“Settings”配置页面,选择SW接口并把速度改成2M;
 在“Flash Download”的编程算法选择上“STM32F10x High-density Flash”;
 
四,修改STM32工程
(待续)


附件:
1,serial.c 文件
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "stm32f10x_conf.h"
#include
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
 USART_InitTypeDef USART_InitStructure;
 GPIO_InitTypeDef GPIO_InitStructure;

/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
void UART_Configuration(void)
{
/* Enable USART1 clocks */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_USART1, ENABLE);

  /* Configure USART1_Tx as alternate function push-pull */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  /* Configure USART1_Rx as input floating */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
  /* 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;

//  STM_EVAL_COMInit(COM1, &USART_InitStructure);
  /* Configure the USARTx */
  USART_Init(USART1, &USART_InitStructure);
  /* Enable the USARTx */
  USART_Cmd(USART1, ENABLE);
}

/**
  * @brief  Retargets the C library printf function to the USART.
  * @param  None
  * @retval None
  */
int fputc(int ch, FILE *f)
{
  /* Place your implementation of fputc here */
  /* e.g. write a character to the USART */
  USART_SendData(USART1, (uint8_t) ch);

  /* Loop until the end of transmission */
  while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET)
  {}

  return ch;
}

#ifdef  USE_FULL_ASSERT

/**
  * @brief  Reports the name of the source file and the source line number
  *   where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t* file, uint32_t line)
{
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  printf("Wrong parameters value: file %s on line %d\r\n", file, line);
  /* Infinite loop */
  while (1)
  {
  }
}
#endif
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/

2,main.c文件

/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "stm32f10x_conf.h"
#include
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
extern void UART_Configuration(void);
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
 /* Setup STM32 system (clock, PLL and Flash configuration) */
  SystemInit();

  UART_Configuration();

  /* Output a message on Hyperterminal using printf function */
  printf("\n\r\n\r\n\r\n\r");
  printf("*** STM32-MDK V1.0 Build by yuanxihua@21cn.com on ("__DATE__ " - " __TIME__ ")\n\r");
  printf("*** STM32-MDK V1.0 Rebooting ...\n\r");

  /* Add your application code here
     */

  /* Infinite loop */
  while (1)
  {
  }
}
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/


原创粉丝点击