application: add board test action
This commit is contained in:
parent
c0bd9291cc
commit
e2a3a60d3a
101
application.c
101
application.c
|
@ -376,6 +376,99 @@ static void command_pin(void* argument)
|
|||
} // connector
|
||||
}
|
||||
|
||||
/** run self test to test board connection to connectors
|
||||
* @param[in] argument no argument required
|
||||
*/
|
||||
static void command_test(void* argument)
|
||||
{
|
||||
(void)argument; // we won't use the argument
|
||||
|
||||
usb_pins_float(); // start with all pins in safe floating state
|
||||
printf("= test =\n");
|
||||
printf("run test to check board connections\n");
|
||||
printf("press any key to interrupt test\n\n");
|
||||
|
||||
// ensure all pins are floating
|
||||
printf("remove all cables from connectors\n");
|
||||
bool float_errors = true; // to test if all pins are floating
|
||||
while (float_errors) {
|
||||
float_errors = false; // restart test
|
||||
for (uint8_t connector = 0; connector < LENGTH(usb_connectors); connector++) { // test every connector
|
||||
for (uint8_t pin = 0; pin < usb_connectors[connector]->pins_nb; pin++) { // test every pin
|
||||
uint32_t pin_port = usb_connectors[connector]->pins[pin].port; // GPIO port corresponding to USB pin
|
||||
uint16_t pin_pin = usb_connectors[connector]->pins[pin].pin; // GPIO pin corresponding to USB pin
|
||||
gpio_set_mode(pin_port, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, pin_pin); // we will test if the input is floating by checking against a pull up and down
|
||||
gpio_set(pin_port, pin_pin); // pull up
|
||||
sleep_us(10); // wait for GPIO/line to settle
|
||||
bool high = (0 != gpio_get(pin_port, pin_pin)); // test if pin is high
|
||||
gpio_clear(pin_port, pin_pin); // pull down
|
||||
sleep_us(10); // wait for GPIO/line to settle
|
||||
bool low = (0 == gpio_get(pin_port, pin_pin)); // test if pin is low
|
||||
gpio_set_mode(pin_port, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, pin_pin); // put back to floating
|
||||
if (high && low) { // pull up and down worked
|
||||
} else { // pull up or down did not work
|
||||
printf("%s (%s) %s is not floating\n", usb_connectors[connector]->name, usb_connectors[connector]->host ? "host" : "device", usb_connectors[connector]->pins[pin].name); // print erroneous pin
|
||||
float_errors = true; // remember there is an error
|
||||
}
|
||||
} // pin
|
||||
} // connector
|
||||
if (float_errors) {
|
||||
if (user_input_available) { // user interruption
|
||||
goto end;
|
||||
}
|
||||
sleep_ms(500); // wait a bit before retesting
|
||||
if (user_input_available) { // user interruption
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
} // float_errors
|
||||
printf("all pins are floating\n");
|
||||
|
||||
// cables to test
|
||||
const struct usb_cable_t test_cables[] = {
|
||||
usb_cables[9], // A (host) - B 3.0 shielded cable
|
||||
usb_cables[14], // A (device) - B 3.0 shielded cable
|
||||
usb_cables[17], // A (host) - miniB 2.0 shielded cable
|
||||
usb_cables[25], // A (host) - microB 3.0 shielded cable
|
||||
};
|
||||
|
||||
for (uint8_t cable = 0; cable < LENGTH(test_cables); cable++) {
|
||||
printf("connect %s cable to connectors:\n", test_cables[cable].name);
|
||||
for (uint8_t connector = 0; connector < test_cables[cable].connectors_nb; connector++) {
|
||||
printf("- %s (%s)\n", test_cables[cable].connectors[connector]->name, test_cables[cable].connectors[connector]->host ? "host" : "device");
|
||||
}
|
||||
bool cable_ok = false; // if the cable is connected
|
||||
while (!cable_ok) { // wait until all pin pairs of cable are connected
|
||||
uint8_t defined, undefined, disconnected, error; // pair counting variables
|
||||
cable_ok = usb_cables_check_cable(&test_cables[cable], &defined, &undefined, &disconnected, &error); // test cable
|
||||
if (!cable_ok && defined > 0) { // not all pairs are connected
|
||||
printf("connection issues: defined=%u/%u, undefined=%u, disconnected=%u, error=%u\n", defined, test_cables[cable].pin_pairs_nb, undefined, disconnected, error); // show issue summary
|
||||
}
|
||||
if (!cable_ok) {
|
||||
if (user_input_available) { // user interruption
|
||||
goto end;
|
||||
}
|
||||
sleep_ms(500); // wait a bit before retesting
|
||||
if (user_input_available) { // user interruption
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("connections are ok\n");
|
||||
}
|
||||
goto end;
|
||||
|
||||
end:
|
||||
usb_pins_float(); // put pins back to safe state
|
||||
if (user_input_available) {
|
||||
printf("test interrupted\n");
|
||||
while (user_input_available) { // test has been interrupted
|
||||
user_input_get(); // discard input
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** list of all supported commands */
|
||||
static const struct menu_command_t menu_commands[] = {
|
||||
{
|
||||
|
@ -468,6 +561,14 @@ static const struct menu_command_t menu_commands[] = {
|
|||
.argument_description = "[nb] [H/L/h/l/x]",
|
||||
.command_handler = &command_pin,
|
||||
},
|
||||
{
|
||||
.shortcut = 't',
|
||||
.name = "test",
|
||||
.command_description = "run board test",
|
||||
.argument = MENU_ARGUMENT_NONE,
|
||||
.argument_description = NULL,
|
||||
.command_handler = &command_test,
|
||||
},
|
||||
};
|
||||
|
||||
static void command_help(void* argument)
|
||||
|
|
Loading…
Reference in New Issue