Compiler Options Block Icon
The CompilerOptimisation block configures compiler toolchain, optimization levels, Device Family Pack (DFP) selection, and linker options for controlling code size, execution speed, and build behavior.

When to use:

When to use:

  • Need to change optimization level from default (-O2)
  • Selecting specific compiler or DFP version (not latest)
  • Code exceeds available memory β€” enable size optimizations (-Os, GC_SECTIONS)
  • Debug build needed β€” disable optimization (-O0, enable DEBUG_INFO)
  • Custom compiler/linker flags required (CUSTOM_OPTIM)

When NOT to use:

  • Default compiler settings work for your application
  • No memory constraints or timing requirements β€” defaults are production-ready
  • Unsure of optimization impact β€” start with defaults, measure performance first

Block Dialog

Compiler Options β€” Compiler Tab
Optimization TabCompiler Options β€” Optimization Tab
Memory TabCompiler Options β€” Memory Tab
Output TabCompiler Options β€” Output Tab
Messages TabCompiler Options β€” Messages Tab

Ports

Inputs: None (configuration block only)

Outputs: None (configuration block only)

This is a configuration block that sets compiler and linker options. It does not have signal portsβ€”it provides build system configuration used during code generation.

Examples

Programmatic Setup

% Add block to model
add_block('MCHP_Blockset/System Configuration/Compiler Options', [mdl '/CompilerOpts']);

% Configure key parameters
set_param([mdl '/CompilerOpts'], 'OPTIMIZATION_LEVEL', '2');
set_param([mdl '/CompilerOpts'], 'DEBUG_INFO', 'on');
set_param([mdl '/CompilerOpts'], 'ProduceHexOutput', 'on');

Compiler Selection

ParameterVariableDescriptionOptions
Select CompilerCOMP_LISTInstalled compiler version selection (auto-detected)XC16 v1.xx-v2.xx | XC32 v2.xx-v4.xx | XC-DSC v3.xx
Always use the latest compilerLATEST_CMPLRAlways use latest installed compileron / off
Device Family Pack (DFP)DFP_LISTDevice Family Pack versionfrom compiler | v1.xx.xx | Update DFP list
CMSIS DSP Library (ARM)CMSIS_DSPCMSIS DSP library for ARMNot used | v5.x.x

Optimization Levels

LevelSpeedCode SizeUse Case
-O0SlowestLargestDebug - no optimization
-O1ModerateReducedBasic optimization
-O2FastSmallerProduction (recommended)
-O3FastestMay increaseMaximum speed
-OsVariesSmallestSize-constrained

dsPIC Options (16-bit)

OptionDescriptionImpact
USE_64BIT_DOUBLE64-bit doubles vs 32-bit2Γ— memory, higher precision
PROCEDURAL_ABSTRACTIONExtract common code (-mpa)5-15% size reduction
MCODECode memory modelsmall (
MDATAData memory modelsmall (near) / large (far)
MLARGEARRAYArrays >32KB32-bit indexing required
GC_SECTIONSRemove unused code/data10-30% size reduction

ARM/PIC32 Options (32-bit)

OptionDescriptionImpact
OPTIMIZATION_FLTOLink-Time Optimization5-20% improvement, slow build
OPTIMIZATION_REORDERReorder for cache localitySpeed improvement
CONSERVE_STACKMinimize stack usageReduced stack requirements

Debug Options

OptionDescriptionOutput
DEBUG_INFODebug symbols in ELFRequired for debugging
AssemblyListing.lst file generationAssembly/source mix
ProduceHexOutput.hex file generationProgramming file
MCHP_STACK_USAGEStack usage report (MCHP).su files
GCC_STACK_USAGEStack usage report (GCC).su files

Linker Configuration

ParameterDescription
UseCustom_LinkerScriptUse custom memory map
LinkerScriptPath to .gld/.ld file
HEAP_SIZEHeap allocation (bytes)
CUSTOM_OPTIMAdditional compiler flags
CUSTOM_OPTIM_LDAdditional linker flags

Math Libraries (dsPIC)

LibrarySpeedAccuracy
StandardModerateFull precision
Fast2-3Γ— fasterSlightly reduced
RelaxedMaximum speedTrade precision

Example Configurations

Debug

OPTIMIZATION_LEVEL: -O0
DEBUG_INFO: on
GC_SECTIONS: None
β†’ Largest code, easiest debugging

Production (Speed)

OPTIMIZATION_LEVEL: -O2
PROCEDURAL_ABSTRACTION: on (dsPIC)
OPTIMIZATION_FLTO: on (ARM/PIC32)
GC_SECTIONS: Remove unused
β†’ Fast execution, moderate size

Size-Constrained

OPTIMIZATION_LEVEL: -Os
PROCEDURAL_ABSTRACTION: on
GC_SECTIONS: Remove unused
β†’ Minimum code size