【发布时间】:2016-10-03 09:08:04
【问题描述】:
我正在使用STM32CubeMX 并尝试使用generate my custom code (UM1718 第141 页) 使用过的周边产品表。使用外围句柄和实例按预期用途分组的闪存中的常量表很容易。比如这个头文件:
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 中所述:
用户模板文件必须兼容STM32CubeMX数据模型。这意味着模板必须以以下行开头:
[#ftl] [#list configs as dt] [#assign data = dt] [#assign peripheralParams =dt.peripheralParams] [#assign peripheralGPIOParams =dt.peripheralGPIOParams] [#assign usedIPs =dt.usedIPs]并以
结尾[/#list]
这是否意味着无法提取必要的信息(主要是关于 GPIO)?
或者我该如何检查?我已经尝试this one 描述数据模型,但只找到了 GPIO 端口列表。
【问题讨论】:
-
如果没有记录数据模型包含的内容,您可以检查调用 FreeMarker 的 Java 代码及其传递给它的内容。寻找
Template.process电话可能有助于找到它。或者,您可以尝试转储数据模型:stackoverflow.com/questions/19028337/… -
@ddekany,我无权访问 STM32CubeMX 源,正如我在我的问题中所写:我试图以与您所说的相同的方式转储数据模型(请参阅我的问题的第一行)。因此,据我了解,只有两种方法,它们都帮不了我?
-
您可以检查 Java 中的数据模型。在
freemarker.core.Environment.process上放置一个断点,然后查看rootDataModel字段。它将是某种TemplateModel,但在其中您可能会找到(部分)原始Java 对象。由于您没有 STM32CubeMX 的源代码,因此 JAD 之类的反编译器可能会有所帮助。 -
我曾尝试使用 JAD 反编译 CubeMX,但我是 Java 新手,但没有成功。
-
对不起,不是JAD,而是JD...jd.benow.ca
标签: code-generation freemarker stm32