3.1.25. waf_tools.hcg

Integration of the TI HALCoGen code generator into the Waf build system.

This waf tool configures the TI HalCoGen (Hardware Abstraction Layer Code Generator, https://www.ti.com/tool/HALCOGEN) so that HAL source files can be generated as part of the Waf build process. HALCoGen reads a .hcg configuration file (XML) together with a corresponding .dil device file and produces C sources, assembly files, and headers for the target microcontroller’s peripherals.

Note

HALCoGen is only available on Windows. On other platforms the tool is configured with an empty HALCOGEN variable and code generation tasks will be skipped.

Because the foxBMS project ships its own FreeRTOS port, the FreeRTOS sources generated by HALCoGen are removed after generation. The only information retained from those sources is the configCPU_CLOCK_HZ define, which is extracted from the generated FreeRTOSConfig.h and written into a dedicated configuration header (config_cpu_clock_hz.h).

Additionally, the tool validates the generated HL_sys_startup.c against a known hash to detect unintentional changes in the startup code caused by HALCoGen configuration modifications.

The tool is loaded in two build environments:

  • ti_arm_cgt: The generated HAL sources are compiled and linked into the

    embedded firmware binary (features c and asm are active on the task generator).

  • unit_test_gcc: The HAL sources are only generated so that their headers

    are available for include paths and mock generation during unit testing. They are not compiled by GCC.

3.1.25.1. Usage

  1. Load the tool during configure:

    def configure(ctx):
        ctx.load("hcg", tooldir=TOOLDIR)
    
  2. In a build script, declare a task generator with a .hcg source file:

    def build(bld):
        # Embedded build (ti_arm_cgt): generated sources are compiled
        bld(
            features="c asm cstlib",
            source=bld.srcnode.find_node("conf/hcg/app.hcg"),
            remove=bld.srcnode.find_node("conf/hcg/app-remove.yaml"),
            startup_hash=bld.path.find_node("app-startup.hash"),
            uselib="HAL",
            target="hal",
        )
    
        # Unit test build (gcc): sources are only generated, not compiled
        bld(
            source=bld.srcnode.find_node("conf/hcg/app.hcg"),
            remove=bld.srcnode.find_node("conf/hcg/app-remove.yaml"),
            startup_hash=bld.path.find_node("app-startup.hash"),
            target="hal",
        )
    

    The remove attribute points to a YAML file listing generated files that shall be deleted after code generation (e.g. FreeRTOS sources). The startup_hash attribute points to a file containing the expected hash of HL_sys_startup.c.

  3. When the c or asm features are present on the task generator, generated .c and .asm files are automatically appended to the task generator’s source list and compiled. Otherwise only the code generation step is performed.

3.1.25.2. Dependencies

  • TI HALCoGen (Windows only, HALCOGEN executable)

  • TI F021 Flash API (include and library paths resolved from HALCoGen installation)

  • PyYAML (for parsing the remove-list configuration)

Functions

configure(ctx)

Configure the TI HALCoGen code generator tool.

process_hcg(self, node)

Create a HALCoGen code generation task from a .hcg source node.

Classes

NodeStructure(xml_file_path, remove)

Parses and holds all generated file information from a HALCoGen configuration.

hcg_compiler(*k, **kw)

Task that executes the HALCoGen code generator.

Exceptions

ToolNotSupportedError

Raised when the HALCoGen configuration selects an unsupported toolchain.