Linux Environment Development STM32, from environment to debug __linux

Source: Internet
Author: User
Tags jlink gdb debugger
The working environment has migrated from Windows to Linux for some reason recently.     STM32 was originally developed under Windows and is now being developed on Linux instead. First of all, briefly describe the software and hardware development environment.
Host: Operating system: CentOS7 x86_64 (grome Desktop Edition) ide:eclipse Luna Jlink driver: jlink_linux_v434a tool chain: gnu-arm-toolchains-4. 9-2014q4 Gdb:arm-linux-gdb V7.8.1
Hardware platform: CPU:STM32F103C8T6 JLINK:V8 USB serial port: Silicon Labs CP2101
The collocation of the environment is relatively simple, the compilation tool chain is relatively easy to install. Here is no longer introduced.      The download link for the tool chain is attached below. The Https://launchpad.net/gcc-arm-embedded IDE environment Eclipse Luna can be downloaded directly from the official web site.     There is also the CDT, which can also be downloaded on the Eclipse official web site.      There is a more important GNU ARM Eclipse development plugin, with a link attached. Http://sourceforge.net/projects/gnuarmeclipse/also has an Eclipse plug-in for GDB debugging, called the zylin-embedded CDT. Download the URL below: HTTP://OPENSOURCE.ZYLIN.COM/ZYLINCDT In addition, is Jlink drive, which contains gdbserver, I use the version of V434a, is to buy other instructional video when attached. Segger official online seems to have not found this download link, you can Baidu, you can also download the other version of the Segger official online.     (As long as there are genuine jlink version of the fact that there is no problem, but with the D version of the need to pay attention to, do not recommend such a high version, or will not be used) here is not linked. Finally there are arm-linux-gdb, can be downloaded from the following official web. Compile and install just follow the Readme to do it OK.      Very simple. Http://lists.gnu.org/archive/html/info-gnu/2014-10/msg00018.html

Said such a long environment, the beginning of their own groping when the environment is very troublesome, but also installed a lot of unnecessary things, and later found that in fact as long as the above is enough, very simple. Hope to help people less to take a detour. Here is a simple sample program to say how to compile, download, Debug. In the original Windows environment, I was developed with Keil UVision5, but also left some code, so directly took a serial port of the sending program as an example, the code is as follows.

/*===================================== Include headers =====================================*/#include "
Stm32f10x.h "/*===================================== functions definition =====================================*/


void uart_defaultconfiguration (void); /*===================================== implementation of Functions =====================================*//** * @
  Brief * Main program.
 
  * @parameter * None * @returnvalue * None/int main (void) {uart_defaultconfiguration ();
  while (1) {if (Usart_getflagstatus (USART1, usart_flag_tc) = = SET) {usart_senddata (USART1, ' A ');
  }}/** * @brief * Initialize the UART with the default configuration. * @parameter * None * @returnvalue * none/void uart_defaultconfiguration (void) {Gpio_inittypedef Gpio_ini
 Tstruct;
 
 
 Usart_inittypedef usart_initstruct; /* Turn on the Clock for the UART and GPIO. * * Rcc_apb2periphclockcmd (Rcc_apb2periph_gpioa | Rcc_Apb2periph_afio |
 
 
 Rcc_apb2periph_usart1, ENABLE); * * Configure the UART1.
 * * Gpio_initstruct.gpio_mode = GPIO_MODE_AF_PP;	 Gpio_initstruct.gpio_pin = Gpio_pin_9;
 /* TX */gpio_initstruct.gpio_speed = Gpio_speed_2mhz;
 
 Gpio_init (Gpioa, &gpio_initstruct);
 Gpio_initstruct.gpio_mode = Gpio_mode_ipu;	 Gpio_initstruct.gpio_pin = gpio_pin_10;
 
 /* RX/* Gpio_init (Gpioa, &gpio_initstruct);
 Usart_initstruct.usart_baudrate = 115200;
 Usart_initstruct.usart_hardwareflowcontrol = Usart_hardwareflowcontrol_none; Usart_initstruct.usart_mode = Usart_mode_rx |
 Usart_mode_tx;
 usart_initstruct.usart_parity = Usart_parity_no;
 Usart_initstruct.usart_stopbits = Usart_stopbits_1;
 Usart_initstruct.usart_wordlength = usart_wordlength_8b;
 
 Usart_init (USART1, &usart_initstruct);
Usart_cmd (USART1, ENABLE); }

The code is very short, also Balais line. The structure of the whole project is as follows:
Indicates that the entire project can be compiled and passed under Windows. As for the test on the Development Board is not posted, the test results are on the serial port can be seen constantly have the letter ' a ' output.

Here's how the whole project moved to the Linux development platform. First, turn on Eclipse on Linux. Create a new C Project. If the environment has been built successfully, you can see the following options, in executable to select stm32f10x C + + Project, the tool chain to select Cross ARM GCC, fill out the project name TestSTM32 Click Next:

Because my CPU is STM32F103C8T6, so Chip family is selected stm32f10x Medium density,flash size is 20KB. Can be completed according to the actual situation of their own hardware. Others can be configured according to the diagram. Click Next:


In fact, the next two pages can be followed, until the last page, be sure to select a good tool chain is GN tools for ARM Embedded processors (ARM-NONE-EABI-GCC), and fill in the tool chain position. Finally click Finish.


After the project is built, you can see that eclipse has built the project into Project Explorer.


Then the SRC, System, include three folders in the project are removed, leaving only the Ldscripts folder. Copy the code from our sample program. As shown in the following illustration:


Why do you want to delete the previous three folders instead of copying the code directly onto the template? In fact, add the code directly on the template also line, the template is also 3.5 version of the firmware library, but if the firmware library upgrade later or do not want to use the firmware library. The purpose of the deletion is to allow us to build the project more free.     So I chose to direct the original project code to copy over. Next is a more important step, to replace the boot file Startup_stm32f10x_md.s, from the St official online download of the firmware library package, the stm32f10x_stdperiph_lib_v3.5.0/libraries/cmsis/cm3/ The Devicesupport/st/stm32f10x/startup/gcc_ride7/startup_stm32f10x_md.s is copied to the project and the suffix s of the boot file is changed to uppercase S. As shown in the following illustration:

The reason for this substitution is that in Windows, the boot file used is for Keil MDK this IDE environment, and now we want to use the GNU tool chain, so we should use the GNU boot file back. Otherwise the link will have a problem.
Next we're going to start configuring something, right-click the project to open properties. First, locate the target Processor, locate the instruction set on the right, and select thumb in the C + + build->settings->tool Settings tab. Find endianness, choose little Endian. As shown in the following figure.

Then, define two macros in Cross in Cross arm GNU assembler, Cross arm C compiler, and compiler arm + + preprocessor: STM32F10X_MD and Use_stdperiph_ DRIVER. All the others are deleted, this one is very important, related to the subsequent compilation problem. At first eclipse will help you define a lot of macros, but you don't need to, just leave these two on the line.


Then, the Cross in Cross arm GNU assembler, Cross arm C compiler and compiler arm + + includes are modified to include a header file path for you. As shown in the following figure.


Next, in the cross ARM C + + linker and general, the original project in the link script path completion. As shown in the following illustration:


OK, after these settings are ready, can you compile it. Theoretically, but there are some code to be modified. This is due to the firmware library where there are some problems, the reference article is as follows: https://answers.launchpad.net/gcc-arm-embedded/+question/217817 modified as follows: in Core_cm3.c, find uint32_t __strexb (uint8_t value, uint8_t *addr) and uint32_t __strexh (uint16_t value, uint16_t *addr). Change the "=r" in these two functions to "=&r", as shown in the following illustration:

OK, now the compilation can be compiled.


You can see that the compilation succeeded, and the size of the code snippet is smaller compared to the size of the file compiled in Keil MDK.     The efficiency of this compilation is still satisfactory. After compiling the program, how to download to the Board and debug it. Let's start by explaining.

There is a drop-down arrow next to the Debug button, click the arrow and then click Debug Configurations. Then double-click Zylin Embedded Debug (Native). This will generate a debug configuration interface with the same name and project name. As shown in the following figure.


Click the Debugger tab in the interface. Locate the GDB debugger text box, navigate to the arm-linux-gdb mentioned above to install, and click Apply. As shown in the following figure.


Then click on the Commands tab. Enter the initialization command for the Jlink in the ' initalize ' commands. Click Apply. As shown in the following figure.


Well, here's the question, what about this initialization command? Exactly how to write it. Here I first give my own initialization command script. You can make changes according to your actual situation.
Target Remote localhost:2331 Monitor halt monitor interface JTAG monitor Speed 1000 monitor endian little monitor flash CP Uclock = 72000000 Monitor Flash device = stm32f103c8 monitor Flash download = 1 Monitor Flash breakpoints = 1 load debug/t Eststm32.elf Monitor Reg R13 = (0x00000000) Monitor reg PC = (0x00000004)
What does the script do? First define the port of GDB server, then continuously to Stm32 and Jlink to release the command: Let Stm32 downtime, set up to use JTAG interface, speed set to 1000kHz and so on.     Finally download the program and reset the Stm32. At first I didn't know what to write. Initialization scripts and initialization commands. Later on the Segger official website found on the Jlinkgdbserver User manual, its official web page and download the address is as follows: Official page: https://www.segger.com/jlink-gdb-server.html user manual Download Address: Https://www.segger.com/admin/uploads/productDocs/UM08005_JLinkGDBServer.pdf Key Reference 3.4 debugging on Cortex-m    Devices and 3.5 supported remote commands These two sections, scripting Templates and command parsing are all here. After setting up this page, don't rush to turn off, a debugging will start from this page. Plug in the Jlink and connect the hardware to the PC. Now you want to manually start the GDB server. Inside the Jlink driver package, there is an executable file called Jlinkgdbserver. Start it from the command line (it's best to start with the root user). As shown in the following figure. If your hardware is connected and the drivers are connected, you will be prompted to find the CORTEX-M3 device. This is normal. Note that in the process of debugging can not close the jlinkgdbserver, let it open on the OK. Otherwise it will not be able to debug.

Next, on the debug configurations page of Eclipse just now, click Debug. Start Debugging. This jumps to the debug view of Eclipse, and debugging stays in the first line of assembly instructions in the startup file. This means that debugging has been successful, and then how to debug the program as in Eclipse to debug other PC programs. There's not much to say here.


    Well, the entire process of developing STM32 in a Linux environment has been introduced. The purpose of this article is only to record the process, easy to forget the steps of the time to view, but also want to help other people who want to develop stm32 in the Linux environment to take less detours.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.