stvd+stm8l051F3(1): stvd builds stm8l project step by step

Publisher:QingfangLatest update time:2021-10-21 Source: eefocusKeywords:stvd  stm8l051F3 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

stvd version information: ST Visual Develop Version 4.3.9
Microcontroller model: stm8l051F3

Steps for establishing stm8l project with stvd:
1. Open stvd, File->New Workspace...

Select Create workspace and project

Enter the project name in Workspace filename, and the project storage path in Workspace location

Enter the project name in Project filename; enter the project storage path in Project location, and select the compiler to be used in Toolchain, here select STM8 Cosmic;
Toolchain root will automatically obtain the path of the compiler according to the selection of Toolchain

Select the IC model, double-click, and then click OK

Click OK, the preliminary project and project have been established, and the compilation is successful.

The stm8l_led project Source Files adds two files, main.c and stm8_interrupt_vector.c.

The led directory automatically adds main.c and stm8_interrupt_vector.c files.

2. Add the STM8L15x_StdPeriph_Driver standard library.
2.1. Copy the three files stm8l15x_conf.h, stm8l15x_it.h, and stm8l15x_it.c to the led directory.

2.2. Copy the STM8L15x_StdPeriph_Driver folder to the led directory.

2.2. Add stm8l15x_conf.h, stm8l15x_it.h, and stm8l15x_it.c to the stm8l_led project, and then add stm8l15x.h from the inc folder under STM8L15x_StdPeriph_Driver to the stm8l_led project.


2.3. Double-click to open stm8l15x.h and remove the comment symbol of the MCU model used.

The compilation project prompts an error:
Running Linker
clnk -m Debugstm8l_led.map -l"C:Program Files (x86)COSMICCXSTM8Lib" -o Debugstm8l_led.sm8 Debugstm8l_led.lkf 
#error clnk Debugstm8l_led.lkf:68 Debugstm8_interrupt_vector.o: symbol f_NonHandledInterrupt multiply defined (Debugstm8l15x_it.o)
 The command: "clnk -m Debugstm8l_led.map -l"C:Program Files (x86)COSMICCXSTM8Lib" -o Debugstm8l_led.sm8 Debugstm8l_led.lkf " has failed, the returned value is: 1
exit code=1.
Comment the @far @interrupt void NonHandledInterrupt (void) function in the stm8_interrupt_vector.c file because it is defined repeatedly. #include the "stm8l15x_it.h" header file and then compile it.

2.4. Select the stm8l_led project in the stvd software Workspace box, right-click and select New Folder... from the pop-up menu, and enter the name of the new folder STM8L15x_StdPeriph_Driver

2.5. In the stm8l_led project in the stvd software Workspace box, right-click STM8L15x_StdPeriph_Driver and select Add Files to Folder..., and select stm8l15x_gpio.c in the STM8L15x_StdPeriph_Driversrc directory.


2.6. Double-click to open the stm8l15x_conf.h file and comment out #define USE_FULL_ASSERT.

2.7. Change the content of main.c to the following code, compile the project, and compile successfully.

  1. //STM8L051/151 and other series shared library functions

  2. #include "stm8l15x.h"


  3. //Define LED port

  4. #define LED_PORT GPIOD

  5. #define LED_PINS GPIO_Pin_0


  6. /***********************************************************************************

  7. ****Entry parameters: None

  8. ****Export parameters: None

  9. ****Function Note: Inaccurate delay function

  10. ***********************************************************************************/

  11. void Delay(__IO uint16_t nCount)

  12. {

  13.     /* Decrement nCount value */

  14.     while (nCount != 0)

  15.     {

  16.         nCount--;

  17.     }

  18. }

  19. /***********************************************************************************

  20. ****Function description: Main function

  21. ****Entry parameters: None

  22. ****Export parameters: None

  23. ****Function Notes: LED flashes at a certain frequency

  24. ************************************************************************************/

  25. void main(void)

  26. {

  27.   GPIO_Init(LED_PORT, LED_PINS, GPIO_Mode_Out_PP_Low_Slow); //Initialize LED port

  28.   while (1)

  29.   {

  30.     GPIO_ToggleBits(LED_PORT,LED_PINS); //Flip LED port

  31.     Delay(50000);

  32.   }

  33. }


At this point, a basic STM8l project has been created. If you need to use other module functions of the microcontroller, add them according to the method of adding stm8l15x_gpio.c. For example, if you want to use spi, add stm8l15x_spi.c to the project.


In addition, the process of establishing a stm8s project is similar to this.


Keywords:stvd  stm8l051F3 Reference address:stvd+stm8l051F3(1): stvd builds stm8l project step by step

Previous article:stvd+stm8l051F3: segment .bss size overflow (293)
Next article:stvd+stm8s: The Flash Memory Read-out protection option must be disabled

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号