STM32: pins: rework debug output

Show infornation related to current pin mode only
This commit is contained in:
Andrey Gusakov 2025-02-13 18:55:01 +03:00 committed by rusefillc
parent dee7fa6ba4
commit a992a638fe
2 changed files with 26 additions and 12 deletions

View File

@ -151,7 +151,7 @@ static void reportPins() {
ioportid_t port = getBrainPinPort(brainPin);
debugBrainPin(pin_state, sizeof(pin_state), brainPin);
const char *boardPinName = getBoardSpecificPinName(brainPin);
const char *boardPinName = getBoardSpecificPinName(brainPin);
efiPrintf("pin %s%d (%s): %s %s", portname(port), pin, boardPinName, pin_user, pin_state);
totalPinsUsed++;
}

View File

@ -155,7 +155,6 @@ unsigned int getBrainPinOnchipNum(void) {
return BRAIN_PIN_ONCHIP_PINS;
}
static const char *mode_names[4] = { "Input", "GP out", "Alt", "Analog" };
static const char *od_names[2] = { "Push-Pull", "Open-Drain" };
static const char *speed_names[4] = { "Low", "Medium", "High", "Very High" };
static const char *pull_names[4] = { "No pull", "Pull-up", "Pull-down", "Reserved" };
@ -169,17 +168,32 @@ void debugBrainPin(char *buffer, size_t size, brain_pin_e brainPin) {
return;
}
uint32_t af = (pin < 8) ? port->AFRL : port->AFRH;
af = (af >> (4 * (pin & 0x07))) & 0x0f;
uint32_t mode = (port->MODER >> (pin * 2)) & 0x03;
chsnprintf(buffer, size, "Mode %s AF%d %s %s Speed %s IN %d OUT %d",
mode_names[(port->MODER >> (pin * 2)) & 0x03],
af,
od_names[(port->OTYPER >> pin) & 0x01],
pull_names[(port->PUPDR >> (pin * 2)) & 0x03],
speed_names[(port->OSPEEDR >> (pin * 2)) & 0x03],
(port->IDR >> pin) & 0x01,
(port->ODR >> pin) & 0x01);
if (mode == 0) {
chsnprintf(buffer, size, "Input %s IN %d",
pull_names[(port->PUPDR >> (pin * 2)) & 0x03],
(port->IDR >> pin) & 0x01);
} else if (mode == 1) {
chsnprintf(buffer, size, "GP out %s %s Speed %s OUT %d IN %d",
od_names[(port->OTYPER >> pin) & 0x01],
pull_names[(port->PUPDR >> (pin * 2)) & 0x03],
speed_names[(port->OSPEEDR >> (pin * 2)) & 0x03],
(port->ODR >> pin) & 0x01,
(port->IDR >> pin) & 0x01);
} else if (mode == 2) {
uint32_t af = (pin < 8) ? port->AFRL : port->AFRH;
af = (af >> (4 * (pin & 0x07))) & 0x0f;
chsnprintf(buffer, size, "Mode AF%d %s %s Speed %s IN %d OUT %d",
af,
od_names[(port->OTYPER >> pin) & 0x01],
pull_names[(port->PUPDR >> (pin * 2)) & 0x03],
speed_names[(port->OSPEEDR >> (pin * 2)) & 0x03],
(port->IDR >> pin) & 0x01,
(port->ODR >> pin) & 0x01);
} else if (mode == 3) {
chsnprintf(buffer, size, "Mode Analog");
}
}
#endif /* EFI_GPIO_HARDWARE */