Pin Mux & Clock Tree
Pin Mux Service
Pin Allocation
Track which peripherals are using which pins:
> fw_get_pin_assignmentsReturns all current pin allocations in the project.
> fw_check_pin_conflictsDetects when two peripherals are assigned to the same physical pin.
Alternate Function Database
Each MCU has a pin-to-alternate-function mapping (e.g., PA9 can be USART1_TX at AF7, or TIM1_CH2 at AF1).
> fw_gpio_alternate_functions PA9Lists all available alternate functions for a pin.
> fw_suggest_pin_assignment USART2_TXFinds available pins that support the requested peripheral signal, avoiding conflicts with existing allocations.
Source Code Scanning
The pin mux service scans your source code for HAL GPIO initialization calls and automatically tracks allocations:
// Detected: PA5 allocated to SPI1_SCK (AF5)
GPIO_InitStruct.Pin = GPIO_PIN_5;
GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);Pinout Visualization
> fw_pinout_showShows current pin assignments in a visual format.
> fw_pinout_checkValidates all pin assignments against MCU capabilities.
> fw_pinout_export format=csvExports pin assignments for documentation or PCB layout.
Available Pins
> fw_get_available_pins peripheral=SPI2Lists pins that are both capable of and available for a peripheral.
Clock Tree Service
Validation
> fw_validate_clock_treeChecks the current clock configuration against MCU constraints:
- PLL input frequency range
- VCO frequency range
- Prescaler valid values
- Maximum bus frequencies (AHB, APB1, APB2)
- USB 48MHz requirement (if USB enabled)
Constraints
> fw_get_clock_constraintsReturns all clock constraints for the selected MCU:
- HSE range
- HSI frequency
- PLL multiplier/divider ranges
- AHB max frequency
- APB1/APB2 max frequencies
- Flash wait states vs frequency
PLL Solving
> fw_suggest_clock_config target=168MHz source=HSE hse=8MHzSolves PLL parameters (M, N, P, Q) that achieve the target system clock frequency within all constraints.
Prescaler Calculation
> fw_calculate_prescaler peripheral=USART1 baudrate=115200Calculates the correct prescaler for a peripheral given the current clock tree.
Project Clock Config Detection
The clock tree service scans your project files for existing clock configuration:
| Source | What it reads |
|---|---|
.ioc files | STM32CubeMX clock settings |
system_stm32*.c | SystemClock_Config() function |
prj.conf | Zephyr clock DTS overlays |
sdkconfig | ESP-IDF clock settings |
Agent Tools
| Tool | Description |
|---|---|
fw_check_pin_conflicts | Detect pin assignment conflicts |
fw_get_pin_assignments | List all pin allocations |
fw_get_available_pins | Find free pins for a peripheral |
fw_suggest_pin_assignment | Suggest optimal pin for a signal |
fw_pinout_show | Visualize pin assignments |
fw_pinout_check | Validate all assignments |
fw_pinout_export | Export pin map |
fw_gpio_alternate_functions | List AFs for a pin |
fw_calculate_prescaler | Compute prescaler for baudrate |
fw_get_clock_constraints | MCU clock limits |
fw_suggest_clock_config | Solve PLL for target frequency |
fw_validate_clock_tree | Validate current clock config |
Last edited