我使用 STM32CubeMX 并尝试 生成我的自定义代码(UM1718第141页),其中包含使用的外设表格。通过将外设句柄和实例根据预期使用目的进行分组,可以很容易地在 Flash 中拥有常量表格。例如,这个头文件:
some.h:
/* TIM table */
#define EM_TIM1 0 // index
#define EM_TIM6 1
#define TIM_CNT 2 // count
#define TIM_0_INST TIM1 // table of instaces
#define TIM_1_INST TIM6
extern TIM_HandleTypeDef htim1; // table of handles
extern TIM_HandleTypeDef htim6;
#define TIM_0_HNDL htim1 // table of handles
#define TIM_1_HNDL htim6
struct tim_tab_s {
TIM_TypeDef * inst;
TIM_HandleTypeDef * hndl;
};
extern struct tim_tab_s const tim_tab[TIM_CNT];
我已经使用这个自定义模板生成:
some_h.ftl:
[#ftl]
[#list configs as dt]
[#assign data = dt]
[#assign peripheralParams =dt.peripheralParams]
[#assign peripheralGPIOParams =dt.peripheralGPIOParams]
[#assign peripheralDMAParams =dt.peripheralDMAParams]
[#assign peripheralNVICParams =dt.peripheralNVICParams]
[#assign usedIPs =dt.usedIPs]
[#assign ip_pref = "EM_"]
[#-- ip desrcibe grpName varName instType hndlType --]
[#assign ip_tim =["TIM", "htim", "TIM_TypeDef", "TIM_HandleTypeDef" ]]
[#assign ip_grps = [ip_tim]]
[#list ip_grps as ip_group]
[#assign ip_grp = ip_group[0]]
[#assign ip_var = ip_group[1]]
[#assign ip_instType = ip_group[2]]
[#assign ip_hndlType = ip_group[3]]
/* ${ip_grp} table */
[#assign ip_id = 0] [#-- IPs Index --]
[#list usedIPs as ip]
[#if peripheralParams.get(ip).entrySet()?size>0&&ip?contains(ip_grp)]
#define ${ip_pref}${ip} ${ip_id}[#if ip_id == 0] // index[/#if]
[#assign ip_id = ip_id + 1]
[/#if]
[/#list][#-- list IPs --]
#n
#define ${ip_grp}_CNT ${ip_id} // count
#n
[#assign ip_id = 0] [#-- IPs Instaces --]
[#list usedIPs as ip]
[#if peripheralParams.get(ip).entrySet()?size>0&&ip?contains(ip_grp)]
#define ${ip_grp}_${ip_id}_INST ${ip}[#if ip_id == 0] // table of instaces[/#if]
[#assign ip_id = ip_id + 1]
[/#if]
[/#list][#-- list IPs --]
#n
[#assign ip_id = 0] [#-- IPs HAL handles declar --]
[#list usedIPs as ip]
[#if peripheralParams.get(ip).entrySet()?size>0&&ip? contains(ip_grp)]
extern ${ip_hndlType} ${ip_var}${ip.replace(ip_grp,"")};[#if ip_id == 0] // table of handles[/#if]
[#assign ip_id = ip_id + 1]
[/#if]
[/#list][#-- list IPs --]
#n
[#assign ip_id = 0] [#-- IPs HAL handles --]
[#list usedIPs as ip]
[#if peripheralParams.get(ip).entrySet()?size>0&&ip?contains(ip_grp)]
#define ${ip_grp}_${ip_id}_HNDL ${ip_var}${ip.replace(ip_grp,"")}[#if ip_id == 0] // table of handles[/#if]
[#assign ip_id = ip_id + 1]
[/#if]
[/#list][#-- list IPs --]
[/#list][#-- list ip_grps --]
[/#list][#-- list configs --]
我直到现在都没有使用过freemarker。
我的问题是我找不到从这个数据模型中提取更多信息的方法:
- 关于句柄类型和名称(我只是简单地声明了它 `[#assign ip_tim =["TIM", "htim", "TIM_TypeDef", "TIM_HandleTypeDef" ]]`), - 关于未与任何外设相关联但已初始化并具有标签的GPIO(我对此一无所知)。
如UM1718所述:
The user template file must be compatible with STM32CubeMX data model. This means that the template must start with the following lines:
[#ftl] [#list configs as dt] [#assign data = dt] [#assign peripheralParams =dt.peripheralParams] [#assign peripheralGPIOParams =dt.peripheralGPIOParams] [#assign usedIPs =dt.usedIPs]
and end with
[/#list]
这是否意味着没有办法提取必要的信息(主要是关于GPIO)?
或者我该如何检查?我尝试过this one来描述数据模型,但只找到了GPIO端口列表。
freemarker.core.Environment.process
上设置断点,然后查看rootDataModel
字段。它将是某种TemplateModel
,但在其中你可能会找到(部分)原始的Java对象。如果你没有STM32CubeMX的源代码,像JAD这样的反编译器可能会有所帮助。 - ddekany