# Build and Run ## What was found No STM32G474CEU6 Keil uVision project was found in the current `AD` workspace. The available files are: - Simulink models under `Inu_im_1wnd_3lvl/`. - S-function and C2000/TMS320 motor-control reference code under `Inu_im_1wnd_3lvl/Inu/`. - New portable STM32-safe wrapper files under `Core/Inc` and `Core/Src`. A sibling candidate project exists outside the writable root: - `F:\set\workspace\setcorp\set506\git_project\stm32g474\stm32g474_IHM08M\IHM08M\MDK-ARM\IHM08M.uvprojx` - Target: `STM32G474RETx`, board `NUCLEO-G474RE`, package `LQFP64`. - Requested target: `STM32G474CEU6`. Because of the target/package mismatch and write permissions, this project was analyzed but not modified. ## New files to add to Keil Add these files to the STM32G474CEU6 Keil project once the real `.uvprojx` is available: - `Core/Inc/ad_parameter_identification.h` - `Core/Src/ad_parameter_identification.c` - `Core/Inc/simulink_interface.h` - `Core/Src/simulink_interface.c` Add `Core/Inc` to the include path. ## Suggested call points After CubeMX init: ```c SimulinkInterface_Init(); ``` In the fast control loop after measurements are updated: ```c SimulinkInterface_SetMeasurements(&measurements); SimulinkInterface_StepFast(); ``` In a slow loop or diagnostic timer: ```c SimulinkInterface_StepSlow(); ``` ## Safety default `AD_PARAM_ID_ENABLE_POWER_TESTS` defaults to `0`. With this default, the code does not request PWM, driver enable, or any power-stage action. To allow hardware tests later, define the macro in the compiler settings or before including the header: ```c #define AD_PARAM_ID_ENABLE_POWER_TESTS 1 ``` Do this only after pinout, driver enable, break/fault inputs, current/voltage scaling, and emergency stop are verified on hardware. ## Keil build steps 1. Open the real STM32G474CEU6 `.uvprojx`. 2. Add `Core/Inc` to C/C++ include paths. 3. Add the two new `.c` files to a user group. 4. Build. 5. Resolve any project-specific include path or C dialect settings. 6. Keep generated Simulink files in a separate group and do not edit them directly. For the sibling `IHM08M.uvprojx` candidate, first confirm that `STM32G474RETx` is acceptable or regenerate it for `STM32G474CEU6`. Then copy/add the new files from this `AD` workspace into that project. ## Hardware check before any power test - Verify all PWM pins with oscilloscope while gate driver is disabled. - Verify driver enable polarity. - Verify fault/break input polarity. - Verify ADC offsets and scaling for currents and DC-link voltage. - Verify emergency stop path disables PWM in hardware. - Verify watchdog behavior. - Verify `AD_ParamID_IsPowerStageAllowed()` stays `0` with default build settings.