Code: Select all
void * gpio_ports[] = {GPIOA, GPIOB, GPIOC, GPIOD, GPIOE,
GPIOF, GPIOG, GPIOH, GPIOI, GPIOJ};
void cmd_showmode (BaseSequentialStream *chp, int argc, char **argv) // Debug: pint hw pin mode.
{
char *p;
int i;
stm32_gpio_t *gpp;
int bn, pn;
static char *modes[] = {"IN", "OUT", "AF", "ANA"};
static char *otypes[] = {"PP", "OD"};
static char *ospeeds[] = {"LOW", "MED", "LOW", "HI"};
static char *pupd[] = {"none", "pup", "pdn", "res"};
if (argc < 1) {
chprintf (chp, "need a pin.\r\n");
return;
}
for (i=0;i<argc;i++) {
p = argv[i];
if (*p == 'p') p++;
if (*p == 'P') p++;
pn = (*p - 'A') & 0xf; // cheap tolower
bn = atoi (p+1);
gpp = gpio_ports[pn];
chprintf (chp, "P%c%d: ", 'A'+pn, bn);
chprintf (chp, "mode: %s, ", modes[(gpp->MODER >> (2*bn))&3]);
chprintf (chp, "otype: %s, ", otypes[(gpp->OTYPER >> bn)&1]);
chprintf (chp, "ospeed: %s, ", ospeeds[(gpp->OSPEEDR >> (2*bn))&3]);
chprintf (chp, "pupd: %s, ", pupd[(gpp->PUPDR >> (2*bn))&3]);
chprintf (chp, "idr: %d, ", (gpp->IDR >> (1*bn))&1);
chprintf (chp, "ord: %d, ", (gpp->ODR >> (1*bn))&1);
if (bn<8) chprintf (chp, "AFR: %d, ", (gpp->AFRL >> (4* bn ) ) &0xf);
if (bn>7) chprintf (chp, "AFR: %d, ", (gpp->AFRH >> (4*(bn-8)) ) &0xf);
chprintf (chp, "\r\n");
}
}
It is possible that this was written a while ago. I see "cubeMX" list the expected IOspeed as "very high", where mine just goes up to "hi".
Why I didn't declare the ports array correctly I don't remember. Instead of the array, a calculation should to work too.
(stm32_gpio_t *)(((uint32)GPIOA) + pn*0x400)