Hello @Francis B.
First let me thank you for posting.
To change the initialization functions generated by CubeMX and make them global functions, you can follow these general steps:
1-Open your project in CubeMX and navigate to the "Pinout & Configuration" tab.
2-Review and modify the peripheral configurations as per your requirements.
3-In the "Project" tab, make sure that the "Generate peripheral initialization as a pair of '.c/.h' files per peripheral" option is selected. This will generate separate source (.c) and header (.h) files for each peripheral.
4-Generate the code based on your configurations.
5-Open the generated source file ,find the initialization function for the peripheral you want to make global. The function name should follow a pattern like HAL_<Peripheral>_MspInit. For example, for the USART1 peripheral, the function will be HAL_UART_MspInit then copy the function declaration from the generated source file.
6-Create a new header file (e.g., peripherals.h) or open an existing header file where you want to declare the global initialization functions and paste the copied function declaration into the header file.
7-Add the function declaration to the header file's list of function prototypes. Make sure it is declared with the appropriate visibility (e.g., extern) to be accessible globally.
8-Save the header file.
9-Open the main source file (e.g., main.c) or any other file where you want to call the global initialization functions.
10-Include the header file where you declared the global initialization functions using the #include preprocessor directive.
11-Call the global initialization function(s) as needed in your code.
12-Build and compile your project.
By following these steps, you can modify the initialization functions generated by CubeMX and make them accessible globally in your code. This allows you to have more control over the initialization process and make any necessary modifications without modifying the generated code directly.
Thx
Ghofrane