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

Optimization Tab

Memory Tab

Output Tab

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
| Parameter | Variable | Description | Options |
|---|
| Select Compiler | COMP_LIST | Installed compiler version selection (auto-detected) | XC16 v1.xx-v2.xx | XC32 v2.xx-v4.xx | XC-DSC v3.xx |
| Always use the latest compiler | LATEST_CMPLR | Always use latest installed compiler | on / off |
| Device Family Pack (DFP) | DFP_LIST | Device Family Pack version | from compiler | v1.xx.xx | Update DFP list |
| CMSIS DSP Library (ARM) | CMSIS_DSP | CMSIS DSP library for ARM | Not used | v5.x.x |
Optimization Levels
| Level | Speed | Code Size | Use Case |
|---|
| -O0 | Slowest | Largest | Debug - no optimization |
| -O1 | Moderate | Reduced | Basic optimization |
| -O2 | Fast | Smaller | Production (recommended) |
| -O3 | Fastest | May increase | Maximum speed |
| -Os | Varies | Smallest | Size-constrained |
dsPIC Options (16-bit)
| Option | Description | Impact |
|---|
| USE_64BIT_DOUBLE | 64-bit doubles vs 32-bit | 2Γ memory, higher precision |
| PROCEDURAL_ABSTRACTION | Extract common code (-mpa) | 5-15% size reduction |
| MCODE | Code memory model | small ( |
| MDATA | Data memory model | small (near) / large (far) |
| MLARGEARRAY | Arrays >32KB | 32-bit indexing required |
| GC_SECTIONS | Remove unused code/data | 10-30% size reduction |
ARM/PIC32 Options (32-bit)
| Option | Description | Impact |
|---|
| OPTIMIZATION_FLTO | Link-Time Optimization | 5-20% improvement, slow build |
| OPTIMIZATION_REORDER | Reorder for cache locality | Speed improvement |
| CONSERVE_STACK | Minimize stack usage | Reduced stack requirements |
Debug Options
| Option | Description | Output |
|---|
| DEBUG_INFO | Debug symbols in ELF | Required for debugging |
| AssemblyListing | .lst file generation | Assembly/source mix |
| ProduceHexOutput | .hex file generation | Programming file |
| MCHP_STACK_USAGE | Stack usage report (MCHP) | .su files |
| GCC_STACK_USAGE | Stack usage report (GCC) | .su files |
Linker Configuration
| Parameter | Description |
|---|
| UseCustom_LinkerScript | Use custom memory map |
| LinkerScript | Path to .gld/.ld file |
| HEAP_SIZE | Heap allocation (bytes) |
| CUSTOM_OPTIM | Additional compiler flags |
| CUSTOM_OPTIM_LD | Additional linker flags |
Math Libraries (dsPIC)
| Library | Speed | Accuracy |
|---|
| Standard | Moderate | Full precision |
| Fast | 2-3Γ faster | Slightly reduced |
| Relaxed | Maximum speed | Trade 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