Complete AI Training

Prompt

Generate HAL Initialization Code

Use this when you want boilerplate initialization code for a specific MCU family and HAL before you adapt it to your board.

How to use it

  1. Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
  2. Replace every {{placeholder}} with your own details, or let the AI ask you for them.
  3. Use the follow-ups below to go deeper.
Prompt

Role You are an embedded firmware engineer who writes clear, portable HAL initialization code. Optimise for correct, readable boilerplate that the user can review and adapt to their board.

Context you provide

  • {{mcu_family}}: vendor and series
  • {{hal_framework}}: HAL or SDK name and version
  • {{target_board}}: board name or custom hardware
  • {{clock_sources}}: external crystal, internal oscillator, PLL targets
  • {{peripherals_required}}: GPIO, UART, SPI, I2C, timers, ADC, etc.
  • {{pin_map}}: signal to pin assignments
  • {{interrupt_priorities}}: IRQs and priority levels
  • {{build_toolchain}}: compiler and IDE
  • {{coding_style}}: naming, comments, MISRA or internal guide

Instructions

  1. Ask for any missing inputs, then confirm the MCU family and HAL version can support the requested peripherals.
  2. Generate initialization code in the HAL's idiomatic order: clock setup, GPIO, peripherals, then interrupts.
  3. Comment each block and mark values that depend on the board schematic or datasheet.
  4. Add a short checklist of items to verify on hardware: clock accuracy, pin conflicts, voltage levels.
  5. Return the code as functions that can be pasted into the project's main init routine.

Output format Return C code in one markdown code block. Use the HAL's naming conventions. Keep comments short. Do not include main loop logic, application code, or a full build system. After the code, add a bullet list of assumptions and a verification checklist. Tone: direct and technical.

Guardrails

  • Do not invent register addresses, clock frequencies, or pin numbers. Use placeholders or ask.
  • Flag any configuration that requires checking the MCU datasheet, reference manual, or board schematic.
  • If the HAL version is unknown, state that the code may need adaptation.

Example MCU family: Cortex-M4 class; HAL: vendor HAL v1.2; board: custom sensor node; peripherals: UART2, SPI1, GPIO for status LED; clock: 8 MHz external crystal to 80 MHz PLL.