2708 views|4 replies

15

Posts

0

Resources
The OP
 

Port the STM32F407 keil version program to IAR for ARM [Copy link]

  • Development board used: STM32F407ZGTb of Zhengdian Atom - Explorer

  • Use the IAR version, IAR Embedded Workbench for ARM 7.80.4.12495, as shown below

IAR version information
  • Use ST-Link for online program download and debugging

  • Use the source code provided by Zhengdian Atom to port to IAR. Some people say, why port to IAR? It's nothing, there is always a need. The following figure shows the source code of all library functions

The source code of the atom library function
  • The entire transplantation process and ideas use the project files provided by Zhengdian Atom mentioned above, directly create a new IAR project in the project, and then make the entire project support IAR and Keil.

  • IAR software installation——————Omitted, please go to the official download and install it yourself.

The main text begins, using the source code: Experiment 0 Template project template as the basis for transplantation

Create a new IAR project, open IAR→project→Create New Project...

We choose to create an empty project

Create a new IAR folder under the project folder

Save the project to this folder

The next step is to build the entire project. Right-click on the newly created project → Add → Add Group... Those who are familiar with IAR know how to do it, so you can skip this step.

We create the group shown in the figure below, which is used to add source program files. Grouping is for easy management later. Those who are familiar with IAR know how to do it and can skip it.

Save all, save the workspace, and the new empty project will be built.

I also created a description group to store description files

The next step is to import the files of each group

The first thing to deal with is the STM32 startup file. Without this file, the program can be compiled and run, but the interrupt function cannot be entered. Keil uses the startup_stm32f40_41xxx.s file in the CORE folder under the project directory, as shown in the figure below. However, I cannot make this file suitable for IAR for the time being, so we have to find a startup file suitable for IAR.

Open the path where IAR for ARM is installed.

...\IAR Systems\Embedded Workbench 7.5\arm\RTOS\SEGGER\ST\STM32F407\embOS_STM32F4_Discovery\DeviceSupport

Select startup_stm32f40x.s, which is the STM32 startup file suitable for IAR

Copy a copy to the IAR folder created in the project folder

Then, add it to the IAR group. The detailed operation is as shown in the figure below. It is a bit similar to adding a group. Those who are familiar with IAR also know how to do it, so you can skip it.

Right click on the IAR group → Add → Add Files...

Select the startup_stm32f40x.s file you just copied and double-click to add it.

We found that there is only one file that needs to be added in the CORE folder - startup_stm32f40_41xxx.s. As a result, we don't use it yet, so the CORE group we created seems to be useless. We can also remove it. [vomit blood]

Then add the .c source files in each folder in the project folder to the corresponding group, which is the same as adding the startup_stm32f40x.s file above. Those who understand can skip this step.

As shown in the figure below, adding the delay.c file to the SYSTEM group is used as an example.

Right click on the SYSTEM group → Add → Add Files...

Just select the delay.c file in the corresponding folder. If there are many files to be added in this directory, you can add them in batches. It supports mouse area selection, Ctrl + A select all, Ctrl + mouse multiple selection, Shift + mouse area selection and other window-specific functions and shortcut keys. It can also be removed. Keil seems to be able to remove only one file at a time.

Then I created a new folder "Description" in the IAR folder and a new file "Description.txt" in it to explain the function and purpose of this project file, and added the description file README.txt in the README folder under the project file.

At this point, all source files have been added. The following figure is a comparison with Keil. The main difference is the difference in the startup files of the two. FWLIB is the library of peripherals. Generally, the corresponding peripheral library is added according to the peripheral used. You can also add all of them. I only added a few as examples.

Next are some settings. If you compile directly after adding them, there will definitely be a lot of errors.

Right click on the project → Options... to open the project settings

Select General Options → Target → Device → ST ... until you select the MCU model you are using, such as my ST STM32F407ZG. After selecting it, don't rush to click OK.

Generally, we need to support printf serial port output. Select Library Configuration → Library and select Full again to prepare for supporting printf serial port output later. Don't rush to click OK.

Select C/C++Compiler and click the small arrow on the right → find Preprocessor

→In Defined symbols: (one per line), enter two macro definitions:

USE_STDPERIPH_DRIVER

STM32F40_41xxx

Enter the address in Additional include directories: (one per line)

$PROJ_DIR$

$PROJ_DIR$\.

$PROJ_DIR$\..\CORE

$PROJ_DIR$\..\FWLIB\inc

$PROJ_DIR$\..\FWLIB\src

$PROJ_DIR$\..\SYSTEM\delay

$PROJ_DIR$\..\SYSTEM\sys

$PROJ_DIR$\..\SYSTEM\usart

$PROJ_DIR$\..\USER

This is the folder containing all project files. There are header files in it that IAR needs to find here.

You can also add folders manually one by one. Click ... on the right to see the addresses that have been added (relative addresses)

Click to add to add a new address.

For example, I added the README folder and double-clicked it to demonstrate the function, but it was actually useless.

After entering, click Select

As you can see, after you select it, the default is to ask for an absolute address, which is not friendly for transplanting programs or moving. Change it to a relative address.

Click the downward triangle ▽ on the right, select $PROJ_DIR$\..\README, and it's OK

Because it is a demonstration and useless, we are removing it. [I am too stupid], click on the address to be removed and click the red × in front of it.

This is the setup, but don't click OK just yet, we'll also set up the ST-Link.

Select Debugger → Setup → Driver → Select ST-LINK

Select ST-LINK, you can set the connection mode, speed, etc.

OK, it’s finally done, you can click OK

Do you think you are done? If you add usart.c, you will still get errors when compiling. [vomiting blood again]

Believe me, it's only a few billion steps away.

Open usart.c, compile warnings: 1 errors: 1

You can see that he wrote...

Warning not recognized

Error, the declaration has already been defined, that is, duplicate definition

Since there is a mistake, just delete the mistake, [hehehe]

So, warnings: 0 errors: 0

No matter what mistakes we encounter, we should not be afraid. The best way to eliminate mistakes is to remove the wrong parts. As long as we remove them, there will be no mistakes [狗头] [狗头] [狗头] [狗头]

We jump to the definition and find that it has been defined in stdio.h. Why is keil... Well, this question is left to the children who have time and energy to explore. [I won't say that I didn't understand it in depth after trying it]

Online debugging, using printf, the serial port can output

Finally the transplant was successful.

A nation thrives through adversity

God bless China

May the deceased rest in peace

Praise the Immortal Hero

Seniors

This prosperous world is as you wish

future

Just leave it to us.




This content is originally created by EEWORLD forum netizen Jianghu Yeyu Piaolingke. If you want to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source.
————————April 4, 2020 14:22:43

image.png (104.86 KB, downloads: 0)

image.png
This post is from stm32/stm8

Latest reply

No picture   Details Published on 2020-4-4 21:10
 

15

Posts

0

Resources
From 2
 

This picture can't be refreshed, I updated it again.

https://bbs.eeworld.com.cn/forum.php?mod=viewthread&tid=1116620

This post is from stm32/stm8
 
 

7452

Posts

2

Resources
3
 

No picture

This post is from stm32/stm8

Comments

Strange, I thought it was not refreshed, I will repost it.  Details Published on 2020-4-5 12:14
 
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 

15

Posts

0

Resources
4
 

Strange, I thought it was not refreshed, I will repost it.

This post is from stm32/stm8
 
 
 

15

Posts

0

Resources
5
 

You can also go to my B station to link , link, https://www.bilibili.com/read/cv5453266

This post is from stm32/stm8
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list