Using the code generation parameters

You can select one or more parameters in the Code Gen dialog box to control how the code is generated.


Add Stack Check Code: Causes additional code to be generated that checks stack usage. The stack usage is reported with the Get Target Stack and Heap command.

Call from Foreign RTOS/User App: Lets you call the generated code from either a foreign RTOS on an embedded system or a user application.

Check for Performance Issues: Alerts you of operations that run slowly on an embedded system and advises how to change your diagram to improve performance. This parameter is not available for MSP430 and Arduino targets.

Embed Maps in Code: Builds the data files from any map block in the generated code. If the target does not have a file system, Embed automatically builds the data file in the generated code. If the target has a file system and you want to change the map file or if you want Embed to read the data file when the embed application starts running, turn this parameter off. This parameter is not available for Arduino targets.

Enable Preemption in Main Diagram: Allows higher priority interrupts to preempt execution of the main diagram.

Heap Size: Allocates memory on the target. The heap is mainly used by matrix blocks and Embed housekeeping routines. Generally, 0x400 is sufficient for initialization of these routines.

To see how much heap is required in your target application, check the initMatVars() function in the generated C file. Each Mat Decl uses arg1 * arg2 * 4 bytes of heap. For a good estimate of heap usage, add together all the bytes, plus an additional 500 bytes of Embed start-up heap. If your application has not allocated enough heap, Embed issues the following warning:

Insufficient memory to run on target

To correct this situation, increase the heap size and recompile.

This parameter is not available for Arduino targets; the heap is automatically allocated.

Include Block Nesting as Comment: Includes comments with the generated code that indicate the source compound block in the Embed diagram from which the generated code came.

Use selected compound edge pins for data exchange: Enables HIL operation. The generated code running on the target to send and receive data from Embed running on the PC.

This parameter is dimmed when no compound block is selected.

Minimize RAM Usage: Minimizes usage of RAM by omitting numerical integration and floating-point filters. The reward is that the target application will use less memory and fit on a lower-cost part.

On-Chip RAM Only: Some parts (like the F2812) have both off-chip and on-chip RAM. Activating the On-chip RAM Only option will use only on-chip RAM. Note that if you are targeting an Arduino, F280x, or MSP430 device, this parameter is dimmed because the targets do not have off-chip RAM.

Optimization Level: Specifies compiler optimization level, from 0 (no optimization) to 4 (highest level). In rare circumstances, Level 4 may yield inconsistent results, necessitating a lower level of optimization.

Periodic Function Name: Indicates the name of the main Embed time step function. This option can be ignored if you have not activated Call from Foreign RTOS/User App.

Result Dir: Displays where the result file will reside. If you want to change the directory, click .

Result File: Indicates the C file to be created. By default, the name of the file is the name of the open block diagram. When you press Compile, Embed automatically creates the C file, then compiles and links it to create an OUT or ELF file. You can alternatively press Code Gen to create only a C file. You can open and browse the C file by clicking on Browse.

Stack Size: Allocates memory on the target machine. The stack is used by function calls. Generally, 0x200 is adequate for most applications. This parameter is not available for Arduino targets; the stack is automatically allocated.

Subtarget: Indicates the specific target device. The subtarget is set in the Target Config block in the diagram.

Target: Indicates the embedded platform that the generated code will run on. Only the installed board libraries will appear in this drop-down list box. To create a Windows DLL, select Host. To create a simulation object, you must first select a compound block, then select Simulation Object from the Target drop-down list.

Target FLASH: Most embedded targets have FLASH memory. This is read-only memory that will retain its information even after power has been turned off.

When activated, Target FLASH causes the linker to allocate code and constants in FLASH and data in RAM. To burn the resulting executable to FLASH on C2000 and ARM Cortex M3 devices, you need to use a third-party product, like Texas Instruments UniFlash. When Target FLASH is not activated, code and data are written to RAM.

For Arduino targets, code is automatically written to FLASH memory; you can ignore this parameter.