Generate Source Files with Custom User Code Blocks
Starting with DaVinci Configurator Classic 6, user code blocks are no longer managed automatically during source file generation. Instead, you now have full control using the DaVinci User Code Tool (DvUCT). The DaVinci User Code Tool introduces a dedicated step in the generation workflow to handle user code sections. This approach allows you to provide user code blocks as a separate input, rather than relying on previously generated data.
You can find the DaVinci User Code Tool in the BSW Package directory under: Misc/DvUCT.
User Code Blocks
User Code Blocks are special sections in the generated source files that are marked for user modifications. These blocks are preserved during subsequent code generations, allowing users to add custom code without losing their changes.
This example shows a user code block with filled-in data. User Code Blocks are generated by the DaVinci Configurator Classic and the content can be modified by the user after generation.
The DaVinci User Code Tool restores the modified user code after the DaVinci Configurator Classic has overwritten the files during the generation process.
/*********************************************************************************
*************************************
* DO NOT CHANGE THIS COMMENT! <USERBLOCK EcuM_GlobalConfigDefines> DO NOT CHANGE THIS COMMENT!
*********************************************************************************
************************************/
/* If ECUM_USE_GENERATED_GLOBAL_CONFIG is STD_ON, the generated EcuM_GlobalConfigRoot will be used.
* Turn to STD_OFF if custom implementation shall be used. Therefore use the corresponding user blocks */
#define ECUM_USE_GENERATED_GLOBAL_CONFIG STD_ON
/*********************************************************************************
*************************************
* DO NOT CHANGE THIS COMMENT! </USERBLOCK> DO NOT CHANGE THIS COMMENT!
*********************************************************************************
************************************/
Extract User Code Blocks From Generated Files
If you want to extract user code blocks from existing generated files you can use the DaVinci User Code Tool with the store command.
$ DvUCT.bat store -r=<PathToGenData> -u=<PathToUserCodeFiles>
This command extracts all user code blocks from the generated files located in <PathToGenData> and saves them into separate *.ucb files in the <PathToUserCodeFiles> directory.
If you want to change the content of the user code blocks, you can edit the corresponding *.ucb files in the <PathToUserCodeFiles> directory.
Adding User Code Using the Tool CLI
To fill the generated data with User Code Blocks, follow these steps:
-
Run the generation process with DaVinci Configurator Classic.
$ dvcfg-b.exe project generate --bsw-package=<PathToYourBswPackage> --project=<PathToYourProjectFile> -
Start the DaVinci User Code Tool to restore the User Code Blocks into the generated files.
$ DvUCT.bat restore -r=<PathToGenData> -u=<PathToUserCodeFiles> -
Check the generated files to ensure the User Code Blocks have been correctly inserted.
Restoring via an External Generation Step
You can automatically run the tool as an external generation step in your DaVinci Project:
-
Open the file
<project-folder>/Settings/Generator.json. -
Add a new entry for the external generation steps (this is a JSON excerpt, not a complete file):
"ExternalGenerationSteps": { "User Code Restore": { "Active": true, "Comment": "Execution of dvUCT restore command", "CommandLine": "$(BswRootPath)/Misc/DvUCT/Application/DvUCT.bat restore -r=<PathToGenData> -u=<PathToUserCodeFiles>" } }