STM32N6 NPU Deployment — Politecnico di Milano  1.0
Documentation for Neural Network Deployment on STM32N6 NPU - Politecnico di Milano 2024-2025
external_memory_mgt.py File Reference

Dynamic C source code modification for external memory activation buffer management. More...

Go to the source code of this file.

Namespaces

 external_memory_mgt
 

Functions

None external_memory_mgt.update_activation_c_code (str c_project_path, str path_network_c_info, int available_AXIRAM, cfg=None, Dict custom_objects=None)
 

Detailed Description

Dynamic C source code modification for external memory activation buffer management.

This module contains a single function, update_activation_c_code(), which performs in-place modification of generated C firmware source files to correctly configure activation buffer placement across the STM32's AXIRAM and SDRAM memory regions.

Why this file exists: When ST Edge AI Core generates the C code for a neural network, it produces generic activation buffer declarations. However, the STM32H747I-DISCO board (and similar targets) has a complex memory hierarchy where different activation buffers must be placed in specific SRAM banks for optimal performance. This file patches the generated C source to add the correct GCC section attributes and linker directives.

Key operations performed:

  1. Determines the appropriate camera resolution based on the model's input shape
  2. Patches main.h with the correct camera resolution macros
  3. Patches main.c to declare activation buffers with explicit memory section attributes, distributing them across AXIRAM and SDRAM based on available space
  4. Patches ai_interface.h with the correct input buffer index and size

Note on project applicability: This function targets the STM32H747I-DISCO board. For the STM32N6570-DK used in this project, the memory management is handled differently by the Neural-ART toolchain. This file is documented for completeness as part of the common deployment module.

Note
This file is part of the STM32AI Model Zoo Services repository by STMicroelectronics. Doxygen documentation added for educational purposes as part of the Multidisciplinary Project — Neural Network Deployment on STM32N6 NPU. Politecnico di Milano, A.Y. 2024-2025. Authors: Giacomo Colosio, Sebastiano Colosio, Patrizio Acquadro, Tito Nicola Drugman

Definition in file external_memory_mgt.py.