首创为CW32L083创建GCC开发工程模版
<p>【目的】</p><p> </p>
<div >官方示例提供了MDK、IAR的示例,也提供了以上两个环境的工程模板,但是没有GCC的工程模板,GCC编译环境与MDK、IAR主要区别就是C语言启动环境的配置、链接文件的不一至,因为要实现VScode或者其他的编译器来实现开发环境的搭建,就需要自己编写CW32L083_FLASH.ld、以及startup_cw32l083_gcc.s。</div>
<div >【实现的思路】</div>
<div >1、寻找官方支持,我在CW32生态群里发了求助的信息,没有回复。</div>
<div >2、在淘宝客服,咨询,回复说,没有工程。</div>
<div >3、有大佬提供了CW32F030的工程,我了解到CW32F030与CW32L083一样是CortexM0+的内核,所以想他的启动文件跟LD应该可以相互借鉴。所以偿试修改CW32F030的工程来实现GCC的工程。</div>
<div >【实现步骤】</div>
<div >1、拷贝一份工程,另存为cw32l083_gcc,并用vscode打开。</div>
<div >2、到官网下载cw32l083的固件库。</div>
<div >3、把cw32l083-stdperiph-lib/Libraries下面的固件替换掉cw32l083_gcc/Libraries固件。</div>
<div >4、复制cw32l083.h、system_cw32l083.h到/Libraries/CMSIS/Device/目录下面。删除原来的cw32f030.h以及system_cwl083.h。</div>
<div >5、Libraries/CMSIS/Device/startup_cw32f030_gcc.s重命名为startup_cw32l083_gcc.s。</div>
<div >6、Libraries/CMSIS/Device/CW32f030_FLASH.ld重命名为CW32L083_FLASH.ld。</div>
<div >7、Debug/CW32F030.svd 重命名为CW32L083.svd。并把其文件内的cwf030修改为cw32l083.</div>
<div >8、复制l083固件库中的cw32l083-stdperiph-lib/IdeSupport/MDKWHXY.CW32L083_DFP.1.0.8.pack 到Debug/WHXY.CW32L083_DFP.1.0.8.pack,并删除原来的.pack文件。</div>
<div >9、复制cw32l083-stdperiph-lib/Examples/GPIO/gpio_blink/USER/src/interrupts_cw32l083.c 到/cw32l083_gcc/Core/app/interrupts_cw32l083.c。以及inc下面的interrupts_cw32l083.h。</div>
<div >10、修改Libraries/Libraries.mk文件内容,主要是文件夹的名称重新定位。</div>
<div >
<div style="border:1px solid #cccccc">
<blockquote style=" overflow-wrap:break-word"># 模块名_DIR 是上一层传递下来的参数,<br style=" overflow-wrap:break-word" />
# 是从工程根目录到该模块文件夹的路径<br style=" overflow-wrap:break-word" />
<br style=" overflow-wrap:break-word" />
# 向 C_SOURCES 中添加需要编译的源文件<br style=" overflow-wrap:break-word" />
C_SOURCES += $(wildcard $(Libraries_DIR)/CW32L083_StdLib/src/*.c)<br style=" overflow-wrap:break-word" />
<br style=" overflow-wrap:break-word" />
# 向 C_INCLUDES 中添加头文件路径<br style=" overflow-wrap:break-word" />
C_INCLUDES += -I$(Libraries_DIR)/CMSIS/Include<br style=" overflow-wrap:break-word" />
C_INCLUDES += -I$(Libraries_DIR)/CMSIS/Device/<br style=" overflow-wrap:break-word" />
C_INCLUDES += -I$(Libraries_DIR)/CW32L083_StdLib/inc<br style=" overflow-wrap:break-word" />
<br style=" overflow-wrap:break-word" />
<br style=" overflow-wrap:break-word" />
# 向 LIBDIR 中添加静态库文件路径<br style=" overflow-wrap:break-word" />
# LIBDIR += -L$(Libraries_DIR)/Lib<br style=" overflow-wrap:break-word" />
# 向 LIBS 中添加需要链接的静态库<br style=" overflow-wrap:break-word" />
# LIBS += -lxxxx<br style=" overflow-wrap:break-word" />
<br style=" overflow-wrap:break-word" />
# link script<br style=" overflow-wrap:break-word" />
LDSCRIPT = $(Libraries_DIR)/CMSIS/Device/CW32L083_FLASH.ld<br style=" overflow-wrap:break-word" />
<br style=" overflow-wrap:break-word" />
<br style=" overflow-wrap:break-word" />
# 汇编文件宏定义<br style=" overflow-wrap:break-word" />
AS_DEFS +=<br style=" overflow-wrap:break-word" />
<br style=" overflow-wrap:break-word" />
# 汇编头文件目录<br style=" overflow-wrap:break-word" />
AS_INCLUDES +=<br style=" overflow-wrap:break-word" />
<br style=" overflow-wrap:break-word" />
# 汇编源文件(starup)<br style=" overflow-wrap:break-word" />
ASM_SOURCES += $(Libraries_DIR)/CMSIS/Device/startup_cw32l083_gcc.s<br style=" overflow-wrap:break-word" />
</blockquote>
</div>
11、修改makefile,修加gcc的路径:</div>
<div >
<div style="border:1px solid #cccccc">
<blockquote style=" overflow-wrap:break-word">#######################################<br style=" overflow-wrap:break-word" />
# 编译器指定<br style=" overflow-wrap:break-word" />
#######################################<br style=" overflow-wrap:break-word" />
PREFIX = arm-none-eabi-<br style=" overflow-wrap:break-word" />
# 启用下一项以指定GCC目录<br style=" overflow-wrap:break-word" />
GCC_PATH = /Applications/ARM/bin/</blockquote>
</div>
12、修改pyocd.yaml,指定tartgets、pack包名称:</div>
<div >
<div style="border:1px solid #cccccc">
<blockquote style=" overflow-wrap:break-word">pack: ./Debug/WHXY.CW32L083_DFP.1.0.8.pack<br style=" overflow-wrap:break-word" />
target_override: CW32L083vc<br style=" overflow-wrap:break-word" />
frequency: 24000000</blockquote>
</div>
13、查找CW32L083用户手册,修改/Libraries/CMSIS/Device/CW32L083_FLASH.ld的RAM、FLASH如下:</div>
<div >
<div style="border:1px solid #cccccc">
<blockquote style=" overflow-wrap:break-word">/* Specify the memory areas */<br style=" overflow-wrap:break-word" />
MEMORY<br style=" overflow-wrap:break-word" />
{<br style=" overflow-wrap:break-word" />
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 24K<br style=" overflow-wrap:break-word" />
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 256K<br style=" overflow-wrap:break-word" />
}</blockquote>
</div>
14、由于.h与MDK的编译上有所差别会报警告</div>
<div >
<div style="border:1px solid #cccccc">
<blockquote style=" overflow-wrap:break-word">Libraries/CW32L083_StdLib/inc/cw32l083_gtim.h:272:52: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]<br style=" overflow-wrap:break-word" />
272 | #define IS_GTIM_DMA(DMA) (((DMA) & 0xFFFFFFC0 == 0x0UL) && (DMA) != 0x0UL)</blockquote>
</div>
修改为:#define IS_GTIM_DMA(DMA) ((((DMA) & 0xFFFFFFC0) == 0x0UL) && (DMA) != 0x0UL),消除运算符的警告。</div>
<div >15、修改SysTick.c中的__weak 编译错误,修改为:__attribute__ ((weak))</div>
<div >到此,工程修改就结束。</div>
<div >编译后无警告无错误:</div>
<div >
<div style="border:1px solid #cccccc">
<blockquote style=" overflow-wrap:break-word"> build_exec/template.elf<br style=" overflow-wrap:break-word" />
build_exec/template.elf -> build_exec/template.hex<br style=" overflow-wrap:break-word" />
build_exec/template.elf -> build_exec/template.bin<br style=" overflow-wrap:break-word" />
build_exec/template.elf -> build_exec/template.s<br style=" overflow-wrap:break-word" />
build_exec/template.elf<br style=" overflow-wrap:break-word" />
text data bss dec hex filename<br style=" overflow-wrap:break-word" />
1088 16 1568 2672 a70 build_exec/template.elf<br style=" overflow-wrap:break-word" />
-e Build Finish</blockquote>
</div>
修改app_main.c的LED针脚,内容如下:</div>
<div >
<div style="border:1px solid #cccccc">
<blockquote style=" overflow-wrap:break-word">#include "app_main.h"<br style=" overflow-wrap:break-word" />
#include "cw32l083_gpio.h"<br style=" overflow-wrap:break-word" />
#include "cw32l083_rcc.h"<br style=" overflow-wrap:break-word" />
<br style=" overflow-wrap:break-word" />
static inline void LED_Init()<br style=" overflow-wrap:break-word" />
{<br style=" overflow-wrap:break-word" />
GPIO_InitTypeDef GPIO_InitStruct;<br style=" overflow-wrap:break-word" />
RCC_AHBPeriphClk_Enable(RCC_AHB_PERIPH_GPIOC, ENABLE);<br style=" overflow-wrap:break-word" />
<br style=" overflow-wrap:break-word" />
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;<br style=" overflow-wrap:break-word" />
GPIO_InitStruct.IT = GPIO_IT_NONE;<br style=" overflow-wrap:break-word" />
GPIO_InitStruct.Pins = GPIO_PIN_2;<br style=" overflow-wrap:break-word" />
GPIO_Init(CW_GPIOC, &GPIO_InitStruct);<br style=" overflow-wrap:break-word" />
}<br style=" overflow-wrap:break-word" />
<br style=" overflow-wrap:break-word" />
int main(void)<br style=" overflow-wrap:break-word" />
{<br style=" overflow-wrap:break-word" />
LED_Init();<br style=" overflow-wrap:break-word" />
// 开启两线调试接口<br style=" overflow-wrap:break-word" />
RCC_SWDIO_Config(RCC_SYSCTRL_SWDIOEN);<br style=" overflow-wrap:break-word" />
<br style=" overflow-wrap:break-word" />
while (1)<br style=" overflow-wrap:break-word" />
{<br style=" overflow-wrap:break-word" />
GPIO_TogglePin(CW_GPIOC, GPIO_PIN_2);<br style=" overflow-wrap:break-word" />
FirmwareDelay(1000000);<br style=" overflow-wrap:break-word" />
}<br style=" overflow-wrap:break-word" />
<br style=" overflow-wrap:break-word" />
return 0;<br style=" overflow-wrap:break-word" />
}<br style=" overflow-wrap:break-word" />
<br style=" overflow-wrap:break-word" />
/******************************************************************************<br style=" overflow-wrap:break-word" />
* EOF (not truncated)<br style=" overflow-wrap:break-word" />
******************************************************************************/<br style=" overflow-wrap:break-word" />
#ifdef USE_FULL_ASSERT<br style=" overflow-wrap:break-word" />
/**<br style=" overflow-wrap:break-word" />
* @brief Reports the name of the source file and the source line number<br style=" overflow-wrap:break-word" />
* where the assert_param error has occurred.<br style=" overflow-wrap:break-word" />
* @param file: pointer to the source file name<br style=" overflow-wrap:break-word" />
* @param line: assert_param error line source number<br style=" overflow-wrap:break-word" />
* @retval None<br style=" overflow-wrap:break-word" />
*/<br style=" overflow-wrap:break-word" />
void assert_failed(uint8_t *file, uint32_t line)<br style=" overflow-wrap:break-word" />
{<br style=" overflow-wrap:break-word" />
/* USER CODE BEGIN 6 */<br style=" overflow-wrap:break-word" />
/* User can add his own implementation to report the file name and line number,<br style=" overflow-wrap:break-word" />
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */<br style=" overflow-wrap:break-word" />
/* USER CODE END 6 */<br style=" overflow-wrap:break-word" />
}<br style=" overflow-wrap:break-word" />
#endif /* USE_FULL_ASSERT */</blockquote>
</div>
编译下载,就可以实现Led1闪烁了。</div>
<div >
<div style="border:1px solid #cccccc">
<blockquote style=" overflow-wrap:break-word">liujianhuadeMacBook-Pro:cw32l083_gcc liujianhua$ make flash<br style=" overflow-wrap:break-word" />
-e Start pyOCD<br style=" overflow-wrap:break-word" />
0000909 I Loading /Users/liujianhua/cw32l083/cw32l083_gcc/build_exec/template.elf <br style=" overflow-wrap:break-word" />
[==================================================] 100%<br style=" overflow-wrap:break-word" />
0001522 I Erased 0 bytes (0 sectors), programmed 0 bytes (0 pages), skipped 1536 bytes (3 pages) at 2.45 kB/s </blockquote>
</div>
【总结】</div>
<div >经过N次的试验,终于成功的实现了cw32l083的gcc工程模块的创建。使得在linux、macOS环境下不能用MDK、IAR的难题。</div>
<div >附工程文件</div>
<div ></div>
<p>楼主拿到板子了?</p>
damiaa 发表于 2023-6-20 09:01
楼主拿到板子了?
<p>我是自费买的,也不贵,主要这板子低功耗非常优秀!</p>
lugl4313820 发表于 2023-6-20 09:47
我是自费买的,也不贵,主要这板子低功耗非常优秀!
<p>楼主眼光不错,这个板子比较全面,做有些小产品完全可以。<img height="48" src="https://bbs.eeworld.com.cn/static/editor/plugins/hkemoji/sticker/facebook/wanwan88.gif" width="59" /></p>
damiaa 发表于 2023-6-20 10:17
楼主眼光不错,这个板子比较全面,做有些小产品完全可以。
<p>多谢版主大佬的认可,正在加油学习之中。</p>
<p>你好,方便分享一下原始CW32F030工程吗?</p>
nehcoab 发表于 2024-8-8 10:49
你好,方便分享一下原始CW32F030工程吗?
<p>已经分享在附件了,你可以下载使用。</p>
页:
[1]