HC32 启动初始化配置
配置ddl_config.h
官方提供的库函数中有ddl_config.h文件,改文件是管理库函数是否加载配置文件。部分内容如下:
/*******************************************************************************
* Global pre-processor symbols/macros ('#define')
******************************************************************************/
/* Chip module on-off define */
#define DDL_ON (1U)
#define DDL_OFF (0U)
/**
* @brief This is the list of modules to be used in the Device Driver Library.
* Select the modules you need to use to DDL_ON.
* @note DDL_ICG_ENABLE must be turned on(DDL_ON) to ensure that the chip works
* properly.
* @note DDL_UTILITY_ENABLE must be turned on(DDL_ON) if using Device Driver
* Library.
* @note DDL_PRINT_ENABLE must be turned on(DDL_ON) if using printf function.
*/
#define DDL_ICG_ENABLE (DDL_ON)
#define DDL_UTILITY_ENABLE (DDL_ON)
#define DDL_PRINT_ENABLE (DDL_OFF)
……省略……
在使用到相关的库函数时将对应的地方配置为DLL_ON。
初始化配置( ICG)
芯片复位解除后,硬件电路会读取 FLASH 地址0x00000400H ~0x0000045FH 把数据加载到初始化配置寄存器。地址 0x00000410H~0x0000045FH 为预约功能,请写入全 1 保证芯片正常动作。
在添加官方提供的DLL库后,相关的配置在hc32f4a0_icg.c 文件中可以看到相关的配置。
/**
* @brief ICG parameters configuration
*/
/* The ICG area is filled with F by default, HRC = 16MHZ,
Please modify this value as required */
#if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
const uint32_t u32ICG[] __attribute__((section(".ARM.__at_0x400"))) =
#elif defined (__GNUC__) && !defined (__CC_ARM)
const uint32_t u32ICG[] __attribute__((section(".icg_sec"))) =
#elif defined (__CC_ARM)
const uint32_t u32ICG[] __attribute__((at(0x400))) =
#elif defined (__ICCARM__)
#pragma location = 0x400
__root static const uint32_t u32ICG[] =
#else
#error "unsupported compiler!!"
#endif
{
/* ICG 0~3 */
0xFFFFFFFFUL,
0xFFFFFFFFUL,
0xFFFFFFFFUL,
0xFFFFFFFFUL,
/* Reserved 0~3 */
0xFFFFFFFFUL,
0xFFFFFFFFUL,
0xFFFFFFFFUL,
0xFFFFFFFFUL,
/* Reserved 4~7 */
0xFFFFFFFFUL,
0xFFFFFFFFUL,
0xFFFFFFFFUL,
0xFFFFFFFFUL,
/* Reserved 8~11 */
0xFFFFFFFFUL,
0xFFFFFFFFUL,
0xFFFFFFFFUL,
0xFFFFFFFFUL,
/* Reserved 12~15 */
0xFFFFFFFFUL,
0xFFFFFFFFUL,
0xFFFFFFFFUL,
0xFFFFFFFFUL,
/* Reserved 16~19 */
0xFFFFFFFFUL,
0xFFFFFFFFUL,
0xFFFFFFFFUL,
0xFFFFFFFFUL,
};
如果在库函数配置文件中 #define DDL_ICG_ENABLE (DDL_OFF)时,编译后的程序下载到板子上也不会运行。解决办法有两种:
- 在配置文件中直接打开 #define DDL_ICG_ENABLE (DDL_ON)
- 在main.c 的文件中添加上面的配置代码,在编译时,程序最后会将相关内容链接到400H地址。