KEIL的使用技巧

一 CMSIS-Driver RTE开发:安富莱串口DMA用RTE开发视频,支持Keil/IAR,裸机和RTOS都支持。

二 头文件的configuration wizardkeil 中的配置向导Configuration Wizard的使用

头文件在写注释的时候加上一些特定标签就可以将普通的.h置文件转化成可视化配置如下图。详情参看user's guide->utilities->Configuration Wizard

用途:可对STM32烧写时的opt选项字节进行设置同程序一起烧录,避免在量产时用烧写软件逐个配置选项字节的问题。但需要:KEIL安装目录下的STM32F4xx_OPT.s(没有的话自己造)加入到自己的工程中;在KEIL选择烧写算法时另外加入对应的OPT烧写算法。

技巧:

  • 适合于汇编,头文件和C/C++中进行配置;
  • 注释最好用“;//”开头,这样汇编直接用,C/c++/头文件中直接用列编辑或者查找删除方法去掉前面的分号;

2.1 头文件的的开始和结尾:

1 // <<< Use Configuration Wizard in Context Menu >>>
2 
3 
4 
5 // <<< end of configuration section >>>
View Code

2.2对标签按要求进行组合使用,便可达到可视化配置的效果。

ItemTextDescription
<c> yes Code enable: creates a checkbox to uncomment or comment code. All lines, including those with white spaces, get commented with double slashes (//) at the first found character when you disable the checkbox. Red text in the Configuration Wizard indicates an inconsistency. Do not nest this item.
<!c> yes Code disable: creates a checkbox to comment or uncomment code. All lines, including those with white spaces, get commented with double slashes (//) at the first found character when you enable the checkbox. Red text in the Configuration Wizard indicates an inconsistency. Do not nest this item.
</c> no End of code enable/disable block started with <c> or <!c>.
<h> yes Heading: the following options belong to a group.
<e> yes Heading with Enable: the following options belong to a group, which can be enabled via a checkbox.
<e.4> yes Heading with Enable: modifies a specific bit (bit 4, in this example).
</h> or </e> no Heading or Enable end.
<i> yes Tool-tip help for previous item.
<q> yes Option for bit values which can be set via a checkbox.
<o> yes Option with selection or number entry.
<o.4..5> yes Modify a range of bits (example: bit 4 to 5).
<o.4> yes Modify a single bit (example: bit 4).
<s> yes Option with ASCII string entry.
<s.10> yes Option with ASCII string entry and a size limit of 10 characters.
ModifierTextDescription
<0-31> no Value range for option fields.
<0-100:10> no Value range for option fields with step 10.
<0x40-0x1000:0x10> no Value range in hex format and step 10.
<0=> yes Value and text for selection.
<#+1> <#-1>
<#*8> <#/3>
no Value modification (add, sub, mul, div) before number is merged into field.
ItemTextDescription
<c> yes ‎代码启用:创建一个复选框以取消注释或注释代码。所有行(包括带有空格的行)在禁用复选框时,在第一个找到的字符处都会用双斜杠 (//) 进行注释。配置向导中的红色文本表示不一致。不要嵌套此项目‎.
<!c> yes ‎代码禁用:创建一个复选框来注释或取消注释代码。启用复选框时,所有行(包括带有空格的行)都会在第一个找到的字符处用双斜杠 (//) 进行注释。配置向导中的红色文本表示不一致。不要嵌套此项目。‎
</c> no ‎以 <c> 或 <!c 开头的代码启用/禁用块结束>‎.
<h> yes ‎标题:以下选项属于一个组。‎
<e> yes ‎带有“启用”的标题:以下选项属于一个组,可以通过复选框启用。‎
<e.4> yes ‎带启用的标题:修改特定位(本例中为位 4)。‎
</h> or </e> no ‎标题或启用结束。‎
<i> yes ‎上一项的工具提示帮助。‎
<q> yes ‎可通过复选框设置的位值选项。‎
<o> yes ‎带有选择或数字输入的选项。‎
<o.4..5> yes ‎修改位范围(例如:位 4 到 5)。‎
<o.4> yes ‎修改单个位(例如:位 4)。‎
<s> yes ‎带有 ASCII 字符串条目的选项。‎
<s.10> yes ‎具有 ASCII 字符串条目且大小限制为 10 个字符的选项。‎
ModifierTextDescription
<0-31> no ‎选项字段的值范围。‎
<0-100:10> no ‎步骤 10 的选项字段的值范围。‎
<0x40-0x1000:0x10> no ‎十六进制格式和步骤 10 的值范围。‎
<0=> yes ‎供选择的值和文本‎.
<#+1> <#-1>
<#*8> <#/3>
no ‎在数字合并到字段中之前,值修改(add,sub,mul,div)。‎

eg:

 

 代码:

 1 //*** <<< Use Configuration Wizard in Context Menu >>> ***
 2 
 3 
 4 FUNC void Setup (void) {
 5 
 6 // <h> External Bus Interface (EBI)
 7 
 8 //   <e1.13> Enable Chip Select 0 (CSR0)
 9 //     <o1.20..31> BA: Base Address <0x0-0xFFF00000:0x100000><#/0x100000>
10 //                 <i> Start Address for Chip Select Signal
11 //     <o1.7..8>   PAGES: Page Size      <0=> 1M Byte    <1=> 4M Bytes
12 //                                       <2=> 16M Bytes  <3=> 64M Bytes
13 //                 <i> Selects Active Bits in Base Address
14 //     <o1.0..1>   DBW: Data Bus Width   <1=> 16-bit     <2=> 8-bit
15 //     <o1.12>     BAT: Byte Access Type <0=> Byte-write
16 //                                       <1=> Byte-select
17 //     <e1.5>      WSE: Enable Wait State Generation
18 //       <o1.2..4>   NWS: Number of Standard Wait States <1-8><#-1>
19 //     </e>
20 //     <o1.9..11>  TDF: Data Float Output Time <0-7>
21 //                 <i> Number of Cycles Added after the Transfer
22 //   </e>
23   _WDWORD(0xFFE00000, 0x010024A9);   // EBI_CSR0: Flash
24 
25 //   <e1.13> Enable Chip Select 1 (CSR1)
26 //     <o1.20..31> BA: Base Address <0x0-0xFFF00000:0x100000><#/0x100000>
27 //                 <i> Start Address for Chip Select Signal
28 //     <o1.7..8>   PAGES: Page Size      <0=> 1M Byte    <1=> 4M Bytes
29 //                                       <2=> 16M Bytes  <3=> 64M Bytes
30 //                 <i> Selects Active Bits in Base Address
31 //     <o1.0..1>   DBW: Data Bus Width   <1=> 16-bit     <2=> 8-bit
32 //     <o1.12>     BAT: Byte Access Type <0=> Byte-write
33 //                                       <1=> Byte-select
34 //     <e1.5>      WSE: Enable Wait State Generation
35 //       <o1.2..4>   NWS: Number of Standard Wait States <1-8><#-1>
36 //     </e>
37 //     <o1.9..11>  TDF: Data Float Output Time <0-7>
38 //                 <i> Number of Cycles Added after the Transfer
39 //   </e>
40   _WDWORD(0xFFE00004, 0x040034A5);   // EBI_CSR1: RAM
41 
42 //   <q1.4>        DRP: Data Read Protocol
43 //                      <0=> Standard Read
44 //                      <1=> Early Read
45   _WDWORD(0xFFE00024, 0x00000010);   // EBI_MCR:  Data Read Protocol
46 
47   _WDWORD(0xFFE00020, 0x00000001);   // EBI_RCR:  Remap Command
48 
49 // </h>
50 
51 // <o> Program Entry Point
52   PC = 0x04000000;
53 
54 }
55 
56 // <s> Change ID
57 // <s1.30> Change Password String
58 #define ID  "My User ID"
59 char pw[] = "My Password";
60 
61 
62 /*********************************************************/
63 /*  Example for enabling and disabling code              */
64 
65 // <c1> Use MY_CPU_VARIANT
66 // <i> Use MY_CPU_VARIANT, and set the include file
67 #define MY_CPU_VARIANT
68 #include "MyCpuVariant.h"
69 // </c>
70 
71 // <!c1> Disable log
72 // <i> Disable log file generation
73 #define _USE_LOG
74 // </c>
75 
76 // <c1>  Example of inconsistent comment
77 // <i> a mix of commented and uncommented lines in the block create an inconsistency
78 
79 // This type of comment, mixed with uncommented lines, creates the inconsistency
80 /* You can use this type of comment without creating an inconsistency */
81 
82    do_whatever;              // adding this type of comment here is allowed
83 
84 // </c>
85 
86 
87 //*** <<< end of configuration section >>>    ***
View Code

 样例2:

 1 // <<< Use Configuration Wizard in Context Menu >>>
 2 
 3 /*可展开一个标题*/
 4 // <h> 栈大小
 5 //   <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
 6 // </h>
 7 
 8 #define Stack_Size 0x00008000
 9 
10 // <c1>Enable HAL Driver Component
11 //  <i>Enable HAL Driver Component
12 //#define ENABLE_HAL_DRIVER_SUPPORT
13 // </c>
14 
15 /*e展开项带单选框觉得后面的宏值,o进一步提供下拉复选框,所以e提供了一个框架,框架下的值可以与宏值没关系*/
16 // <e>MCU ADC CH1 Param Config
17 //  <o>MCU ADC CH1 AF Port
18 //   <i> Default:PC1
19 //   <0=> PC1
20 #define MSP_ADC_CH1_AF_PORT 0
21 // </e>
22 
23 
24 /*通过独立的位计算给宏赋值*/
25 // <q.0> Enable UART0 Rx ISR
26 // <q.1> Enable UART0 Rx DMA
27 #define MSP_UART0_RX_MODE 0x02
28 
29 /*位带运算*/
30 // <o.8..15>Set MCU Clock Output Port
31 //  <0=>GPIO_PORT_A
32 //  <1=>GPIO_PORT_B
33 //  <2=>GPIO_PORT_C
34 //  <3=>GPIO_PORT_D
35 //  <4=>GPIO_PORT_E
36 // <o.0..7>Set MCU Clock Output Pin
37 //  <0=>GPIO_PIN_0
38 //  <1=>GPIO_PIN_1
39 //  <2=>GPIO_PIN_2
40 //  <3=>GPIO_PIN_3
41 //  <4=>GPIO_PIN_4
42 //  <5=>GPIO_PIN_5
43 //  <6=>GPIO_PIN_6
44 //  <7=>GPIO_PIN_7
45 //  <8=>GPIO_PIN_8
46 #define MSP_CKO_PORT 0x104
47 
48 /*下来选择框中选择给宏赋值*/
49 // <o>Set Internal high speed RC clock frequency(unit: hz)
50 //  <i>Default: 80MHz
51 //  <80000000UL=> 80MHz
52 //  <64000000UL=> 64MHz
53 //  <48000000UL=> 48MHz
54 //  <32000000UL=> 32MHz
55 //  <16000000UL=> 16MHz
56 //  <8000000UL=> 8MHz
57 #define MCU_CLK_FREQUENCE 64000000UL
58 
59 /*在范围内带步长的输入值进行宏赋值*/
60 // <o>Set SysTick Period
61 //  <i>Default: 1000 (Unit:us)
62 //  <0-16777215:3>
63 #define MCU_SYSTICK_FREQUENCE 9
64 
65 // <s>Define MSP Config File Version
66 //  <i>version
67 #define MSP_CONFIG_VERSION "1.0.1"
68 
69 
70 
71 
72 
73 // <<< end of configuration section >>
View Code

 调试模式下通过VIEW打不开各个端口时的处理办法:

在上方标题栏找到:Window->Reset View to Defaults,当弹出对话框后,点击Restart(将窗口复位)。

posted on 2022-08-30 10:51  杰瑞鼠  阅读(241)  评论(0编辑  收藏  举报