The ARM Cortex-M is a group of 32-bit RISC ARM processor cores licensed by Arm Holdings. The cores are intended for microcontroller use, and consist of the Cortex-M0, Cortex-M0+, Cortex-M1, Cortex-M3, Cortex-M4, Cortex-M7, Cortex-M23, Cortex-M33, Cortex-M35P, Cortex-M55 and Cortex-M65. The ARM Cortex-M processors are designed for embedded applications requiring high performance and low power consumption. They are commonly used in a wide range of products including automotive systems, industrial automation, Internet of Things (IoT) devices, home appliances, and consumer electronics.
Embedded Coder from MathWorks provides production code generation support for the ARM Cortex-M series of processors. This allows developers to generate optimized C and C++ code targeting these ARM microcontrollers directly from MATLAB and Simulink models. Some key capabilities provided by Embedded Coder for ARM Cortex-M include:
Processor-Specific Code Generation
Embedded Coder generates portable ANSI/ISO C and C++ code that is optimized for the specific ARM Cortex-M processor targeted. Compiler optimizations like function inlining, dead code elimination, loop optimizations and more are applied automatically based on the target processor. This results in highly efficient code for the microcontroller.
Fixed-Point Support
For most embedded applications, fixed-point (integer) math is preferred over floating-point as it is faster and uses less memory. Embedded Coder allows users to define fixed-point data types and operations. The generated code implements fixed-point arithmetic efficiently using native C types and operations. Overflow, saturation, rounding and other effects are handled automatically.
Peripheral Blockset Integration
Embedded Coder integrates tightly with the Simulink Peripheral Blockset which provides blocks for configuring and accessing peripherals like ADC, PWM, GPIO, timers, communication interfaces and more. The generated code initializes the peripherals, handles interrupts and data transfers automatically. This saves a lot of time compared to manually writing peripheral initialization and interrupt handling code.
Device Hardware Abstraction
The generated code uses a device hardware abstraction layer that allows it to be ported across different ARM Cortex-M vendors easily. For example, the same model code can be retargeted to an STM32 or NXP LPC MCU just by changing the target configuration, no code changes are needed.
Fixed-Step Multi-Rate Execution
Embedded Coder enables multi-rate simulations in Simulink to run with fixed-step execution on Cortex-M hardware. Complex systems using components with different sample rates can be modeled and executed efficiently without loss of determinism.
Verification and Validation
The generated code can be verified for functional equivalence against the Simulink model using Embedded Coder verification tools. Additional code checks like MISRA-C compliance, standards compatibility and other static analysis can also be performed. Hardware in the loop (HIL) simulation lets users simulate the actual hardware running the generated code.
Code Profiling and Optimization
Profilers and other tools provided with Embedded Coder allow tracing and optimization of the generated code’s memory usage, timing, power consumption etc. The code can be instrumented to collect runtime data and identify hotspots that need optimization.
Native Code Generation
Unlike some code generators that output intermediate code or virtual machine code, Embedded Coder generates native code in C or C++ that is compiled directly to machine code by the ARM compiler toolchain. This ensures the code is compact and efficient, and allows integration with handwritten code or legacy code.
AUTOSAR Support
For automotive applications, Embedded Coder can generate production code compliant with AUTOSAR (AUTomotive Open System ARchitecture) methodology. This includes features like standardized software components, layered architecture and compliance with specifications like MISRA C. Seamless integration with other MATLAB and Simulink automotive toolboxes is provided.
Code Efficiency
The generated code is optimized to minimize memory usage through techniques like storing constants in flash rather than RAM, optimized data layout, shared lookup tables and more. Unused features can be excluded and modular build configurations allow creating deliverables with just needed functionality.
Hardware Interface Coding
Embedded Coder allows hand-coding optimized interfacing functions to ARM Cortex-M hardware using C or C++. These hand-coded files can be integrated with the auto-generated code to create efficient hardware access routines not possible from Simulink.
IDE Integration
The generated code can be built and debugged directly from popular IDEs like IAR, Keil, GCC, etc. with the required project files generated automatically. Debugging the code executing on hardware is greatly simplified by this IDE integration.
Customizable Code Generation
Users can customize the generated code architecture, file structure, naming conventions etc. as needed by modifying the ARM Cortex-M target templates. A batch code generation workflow allows automation of the entire process.
Safety Critical Code Generation
For safety critical applications like medical devices or automotive systems, Embedded Coder can generate code certified for safety standards like ISO 26262 ASIL D. This includes requirements traceability, requirements testing, static analysis, robustness testing and documentation.
Simulation and Verification
The Simulink model used for code generation can be simulated and verified extensively before generating code. Once code is available, the same test harness can be used with it for Hardware-In-the-Loop testing on real hardware. This ensures model behavior matches generated code behavior.
Model Debugging and Instrumentation
Models used for ARM Cortex-M code generation can be instrumented for tracing and debugging. Signals can be logged, breakpoints can be set, and step-by-step debugging is possible natively from Simulink before generating code.
Standards Compliant Code
Embedded Coder generates code following standards like MISRA C for improved reliability, ISO 26262 for automotive safety, and other standards. Strictness of standards compliance can be configured along with checks for standards violations.
Model Architecture and Design
Following best practices for Simulink modeling allows Embedded Coder to generate optimized code from the model. This includes proper subsystem design, avoiding algebraic loops, multi-rate modeling, utilizing model reference, avoiding direct feedthroughs etc. Embedded Coder checks models and suggests improvements.
Customization, Configuration and Control
Nearly every aspect of the generated code – file structure, naming, interfaces, architecture etc. can be customized by the user. Detailed control over the code generation process is provided through configuration settings, build scripts, pre/post code generation callbacks and other mechanisms.
Integration with External Tools
The generated code can interface with external tools like version control systems, requirements management tools, source control, build systems, test harnesses and more. Standard formats for build artifacts, documentation and reports enables easy integration.
IDE Agnostic Code
The generated code is standalone C/C++ code that can be built with any compiler or IDE toolchain. There are no dependencies on proprietary tools or file formats. The code integrates with third party tools, legacy codebases, external teams, etc.
ARM Compiler Optimization
The generated code can leverage highly optimized ARM compiler toolchains like ARMCLANG to produce the most efficient machine code for the target hardware. Intrinsic functions, IPO, vectorization, loop optimizations and other advanced optimizations are applied.
Vendor Agnostic Portable Code
The same auto-generated code can be retargeted to different ARM Cortex-M vendors like STMicroelectronics, NXP, Microchip, Cypress, etc. with no code changes needed. The hardware abstraction layer isolates vendor specific implementation.
Timing Analysis
Embedded Coder can perform detailed timing analysis of the generated code, estimating execution times of code sections based on processor speeds, memory access times, peripherals and other factors. Bottlenecks can be identified.
Code Traceability
Traceability between the model blocks and the generated code constructs is maintained. Changes to model can be accurately reflected in code. Impact analysis of model change on code can be performed.
Code Coverage Analysis
Code coverage analysis determines what portions of the auto-generated code are covered by a test suite. This allows improving tests to get maximum coverage and ensure code robustness.
So in summary, the ARM Cortex-M support in Embedded Coder enables high quality production code generation from MATLAB and Simulink models targeting ARM Cortex-M cores. Optimized fixed- and floating-point C and C++ code can be generated with peripheral drivers, real-time execution, standards compliance and extensive verification, validation, debugging and analysis capabilities. This accelerates embedded software development with ARM microcontrollers.