application: add voltages check to self-tests
This commit is contained in:
parent
2ede3ef1b2
commit
5773f62be2
169
application.c
169
application.c
|
@ -44,42 +44,40 @@
|
|||
#include "usart.h" // USART utilities
|
||||
#include "usb_cdcacm.h" // USB CDC ACM utilities
|
||||
|
||||
//#include "rs.h" // RS-232/485 utilities
|
||||
#include "i2c_master.h"
|
||||
|
||||
//#include "rs485.h" // RS-485 utilities
|
||||
//#include "rs232.h" // RS-232 utilities
|
||||
//#include "i2c_master.h" // I2C utilities
|
||||
|
||||
#define WATCHDOG_PERIOD 10000 /**< watchdog period in ms */
|
||||
|
||||
/** @defgroup busvoodoo_peripherals peripheral pin definitions
|
||||
* @{
|
||||
*/
|
||||
#define BUSVOODOO_5VPULLUP_PORT A /**< 5V pull-up enable pin (active low) */
|
||||
#define BUSVOODOO_5VPULLUP_PIN 15 /**< 5V pull-up enable pin (active low) */
|
||||
#define BUSVOODOO_XVPULLUP_PORT B /**< xV pull-up enable pin (active low) */
|
||||
#define BUSVOODOO_XVPULLUP_PIN 3 /**< xV pull-up enable pin (active low) */
|
||||
#define BUSVOODOO_5VPULLUP_PORT B /**< 5V pull-up enable pin (active low) */
|
||||
#define BUSVOODOO_5VPULLUP_PIN 4 /**< 5V pull-up enable pin (active low) */
|
||||
#define BUSVOODOO_OEPULLUP_PORT A /**< bus switch output enable pin to enable embedded pull-ups (active low) */
|
||||
#define BUSVOODOO_OEPULLUP_PIN 15 /**< bus switch output enable pin to enable embedded pull-ups (active low) */
|
||||
#define BUSVOODOO_XVEN_PORT A /**< xV enable pin (active high) */
|
||||
#define BUSVOODOO_XVEN_PIN 6 /**< xV enable pin (active high) */
|
||||
#define BUSVOODOO_12VEN_PORT A /**< 12V enable pin (active high) */
|
||||
#define BUSVOODOO_12VEN_PIN 7 /**< 12V enable pin (active high) */
|
||||
#define BUSVOODOO_RS232EN_PORT C /**< RS-232 enable pin (active low) */
|
||||
#define BUSVOODOO_RS232EN_PIN 13 /**< RS-232 enable pin (active low) */
|
||||
#define BUSVOODOO_12VEN_PORT A /**< 12V enable pin (active low) */
|
||||
#define BUSVOODOO_12VEN_PIN 7 /**< 12V enable pin (active low) */
|
||||
#define BUSVOODOO_VOUTEN_PORT B /**< voltage output (5V and 3.3V) enable pin (active low) */
|
||||
#define BUSVOODOO_VOUTEN_PIN 4 /**< voltage output (5V and 3.3V) enable pin (active low) */
|
||||
#define BUSVOODOO_VOUTEN_PIN 3 /**< voltage output (5V and 3.3V) enable pin (active low) */
|
||||
/** @} */
|
||||
|
||||
/** @defgroup busvoodoo_adc inputs to measure voltages
|
||||
* @{
|
||||
*/
|
||||
#define BUSVOODOO_3V3_CHANNEL 12 /**< ADC channel to measure 5V rail */
|
||||
#define BUSVOODOO_5V_CHANNEL 13 /**< ADC channel to measure 3.3V rail */
|
||||
#define BUSVOODOO_5V_CHANNEL 9 /**< ADC channel to measure 3.3V rail */
|
||||
#define BUSVOODOO_XV_CHANNEL 11 /**< ADC channel to measure xV rail */
|
||||
#define BUSVOODOO_12V_CHANNEL 10 /**< ADC channel to measure 12V rail */
|
||||
#define BUSVOODOO_12V_CHANNEL 15 /**< ADC channel to measure 12V rail */
|
||||
/** @} */
|
||||
|
||||
#define BUSVOOFOO_XVCTL_CHANNEL CHANNEL_1 /**< DAC channel to control xV output voltage */
|
||||
#define BUSVOODOO_XV_DEFAULT (0.8*(1+33.0/10.0)) /**< default (when not driven) xV voltage regulator output voltage based on R1 and R2 */
|
||||
#define BUSVOODOO_XV_DEFAULT (0.8*(1+30.0/10.0)) /**< default (when not driven) xV voltage regulator output voltage based on R1 and R2 */
|
||||
#define BUSVOODOO_XV_TEST 2.5 /**< target xV output voltage to test if we can set control the xV voltage regulator */
|
||||
#define BUSVOODOO_XV_SET(x) ((0.8*(1+33.0/10.0)-x)*(10.0/33.0)+0.8) /**< voltage to output for the DAC to set the desired xV output voltage (based on resistor values on the xV adjust pins and xV voltage reference) */
|
||||
#define BUSVOODOO_XV_SET(x) ((0.8*(1+30.0/10.0)-x)*(10.0/30.0)+0.8) /**< voltage to output for the DAC to set the desired xV output voltage (based on resistor values on the xV adjust pins and xV voltage reference) */
|
||||
#define BUSVOOFOO_12VCTL_CHANNEL CHANNEL_2 /**< DAC channel to control 12V output voltage */
|
||||
#define BUSVOODOO_12V_DEFAULT (1.25*(1+100.0/10.0)) /**< default (when not driven) 12V voltage regulator output voltage based on R1 and R2 */
|
||||
#define BUSVOODOO_12V_TEST 12.0 /**< target 12V output voltage to test if we can set control the 12V voltage regulator */
|
||||
|
@ -92,10 +90,7 @@
|
|||
static const char* busvoodoo_io_names[13] = {"I2C_SMBA/SPI_NSS/I2S_WS", "SDIO_CMD", "USART_CTS/SPI_SCK/I2S_CK", "SDIO_D3/UART_RX", "I2C_SDA/USART_RX", "SDIO_D0", "SPI_MOSI/I2S_SD", "SDIO_CK/USART_CK", "I2C_SCL/USART_TX", "SDIO_D1", "I2S_MCK", "USART_RTS/SPI_MISO", "SDIO_D2/UART_TX"}; /**< I/O individual signal names */
|
||||
static const uint32_t busvoodoo_io_ports[13] = {GPIOB, GPIOD, GPIOB, GPIOC, GPIOB, GPIOC, GPIOB, GPIOC, GPIOB, GPIOC, GPIOC, GPIOB, GPIOC}; /**< port of individual signals */
|
||||
static const uint32_t busvoodoo_io_pins[13] = {GPIO12, GPIO2, GPIO13, GPIO11, GPIO11, GPIO8, GPIO15, GPIO12, GPIO10, GPIO9, GPIO6, GPIO14, GPIO10}; /**< pin of individual signals */
|
||||
// ideal pinout
|
||||
//static const uint8_t busvoodoo_io_groups[13] = {1, 1, 3, 3, 5, 5, 2, 2, 4, 4, 6, 6, 6}; /**< which I/O (group) does the signal belong to */
|
||||
// schematic/layout v0.001 pinout (SDIO_D2/UART_TX landed in group 6 instead of 3)
|
||||
static const uint8_t busvoodoo_io_groups[13] = {1, 1, 3, 3, 5, 5, 2, 2, 4, 4, 6, 6, 3}; /**< which I/O (group) does the signal belong to */
|
||||
static const uint8_t busvoodoo_io_groups[13] = {6, 6, 4, 4, 1, 1, 5, 5, 2, 2, 3, 3, 3}; /**< which I/O pin (group) does the signal belong to */
|
||||
|
||||
/** @} */
|
||||
|
||||
|
@ -155,15 +150,15 @@ static void safe_state(void)
|
|||
gpio_set_mode(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO(BUSVOODOO_VOUTEN_PIN)); // set pin as output (open-drain pulled high to disable the pMOS)
|
||||
gpio_clear(GPIO(BUSVOODOO_XVEN_PORT), GPIO(BUSVOODOO_XVEN_PIN)); // disable xV voltage regulator
|
||||
gpio_set_mode(GPIO(BUSVOODOO_XVEN_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_XVEN_PIN)); // set pin as output (push-pull, pulled low for safety)
|
||||
gpio_clear(GPIO(BUSVOODOO_12VEN_PORT), GPIO(BUSVOODOO_12VEN_PIN)); // disable 12V voltage regulator
|
||||
gpio_set_mode(GPIO(BUSVOODOO_12VEN_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_12VEN_PIN)); // set pin as output (push-pull, pulled low for safety)
|
||||
gpio_set(GPIO(BUSVOODOO_12VEN_PORT), GPIO(BUSVOODOO_12VEN_PIN)); // disable 12V voltage regulator
|
||||
gpio_set_mode(GPIO(BUSVOODOO_12VEN_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO(BUSVOODOO_12VEN_PIN)); // set pin as output (open-drain pulled high to disable the pMOS)
|
||||
|
||||
// disable embedded pull-ups
|
||||
gpio_primary_remap(AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON, 0); // disable JTAG (but keep SWD) so to use the underlying GPIOs (PA15, PB3, PB4)
|
||||
gpio_set(GPIO(BUSVOODOO_5VPULLUP_PORT), GPIO(BUSVOODOO_5VPULLUP_PIN)); // set pin high to disable 5V embedded pull-up
|
||||
gpio_set_mode(GPIO(BUSVOODOO_5VPULLUP_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO(BUSVOODOO_5VPULLUP_PIN)); // set pin as output (open-drain pulled high to disable the pMOS)
|
||||
gpio_set(GPIO(BUSVOODOO_XVPULLUP_PORT), GPIO(BUSVOODOO_XVPULLUP_PIN)); // set pin high to disable xV embedded pull-up
|
||||
gpio_set_mode(GPIO(BUSVOODOO_XVPULLUP_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO(BUSVOODOO_XVPULLUP_PIN)); // set pin as output (open-drain pulled high to disable the pMOS)
|
||||
gpio_set(GPIO(BUSVOODOO_OEPULLUP_PORT), GPIO(BUSVOODOO_OEPULLUP_PIN)); // set pin high to disable embedded pull-up bus switch
|
||||
gpio_set_mode(GPIO(BUSVOODOO_OEPULLUP_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO(BUSVOODOO_OEPULLUP_PIN)); // set pin as output (open-drain pulled high to disable the bus switch)
|
||||
|
||||
// disable all signal I/O outputs
|
||||
for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins); pin++) {
|
||||
|
@ -244,14 +239,14 @@ static bool test_self(void)
|
|||
// check 5V power rail
|
||||
float voltage = rail_voltage(BUSVOODOO_5V_CHANNEL); // get 5V power rail voltage
|
||||
if (voltage<4.0) {
|
||||
printf("5V power rail voltage is too low: %d.%02uV, check USB port\n", (int32_t)voltage, (uint32_t)((voltage-(int32_t)voltage)*100));
|
||||
printf("5V power rail voltage is too low: %.2fV, check USB port\n", voltage);
|
||||
#if DEBUG
|
||||
while (true);
|
||||
#else
|
||||
goto error;
|
||||
#endif
|
||||
} else if (voltage>5.5) {
|
||||
printf("5V power rail voltage is too high: %d.%02uV, check USB port\n", (int32_t)voltage, (uint32_t)((voltage-(int32_t)voltage)*100));
|
||||
printf("5V power rail voltage is too high: %.2fV, check USB port\n", voltage);
|
||||
#if DEBUG
|
||||
while (true);
|
||||
#else
|
||||
|
@ -262,14 +257,14 @@ static bool test_self(void)
|
|||
// check 3.3V power rail
|
||||
voltage = rail_voltage(BUSVOODOO_3V3_CHANNEL); // get 3.3V power rail voltage
|
||||
if (voltage<3.0) {
|
||||
printf("3.3V power rail voltage is too low: %d.%02uV, check OLED connector and voltage regulator\n", (int32_t)voltage, (uint32_t)((voltage-(int32_t)voltage)*100));
|
||||
printf("3.3V power rail voltage is too low: %.2fV, check OLED connector and voltage regulator\n", voltage);
|
||||
#if DEBUG
|
||||
while (true);
|
||||
#else
|
||||
goto error;
|
||||
#endif
|
||||
} else if (voltage>3.6) {
|
||||
printf("3.3V power rail voltage is too high: %d.%02uV, check OLED connector and voltage regulator\n", (int32_t)voltage, (uint32_t)((voltage-(int32_t)voltage)*100));
|
||||
printf("3.3V power rail voltage is too high: %.2fV, check OLED connector and voltage regulator\n", voltage);
|
||||
#if DEBUG
|
||||
while (true);
|
||||
#else
|
||||
|
@ -278,19 +273,30 @@ static bool test_self(void)
|
|||
}
|
||||
|
||||
// check xV voltage regulator
|
||||
gpio_clear(GPIO(BUSVOODOO_XVEN_PORT), GPIO(BUSVOODOO_XVEN_PIN)); // disable xV voltage regulator
|
||||
sleep_ms(1); // let voltage settle
|
||||
voltage = rail_voltage(BUSVOODOO_XV_CHANNEL); // get xV voltage
|
||||
if (voltage>0.2) { // ensure the output is at 0V when the regulator is not enabled
|
||||
printf("xV voltage is not 0V when the regulator is disabled: %.2fV, check xV voltage regulator\n", voltage);
|
||||
#if DEBUG
|
||||
while (true);
|
||||
#else
|
||||
goto error;
|
||||
#endif
|
||||
}
|
||||
gpio_set(GPIO(BUSVOODOO_XVEN_PORT), GPIO(BUSVOODOO_XVEN_PIN)); // enable xV voltage regulator
|
||||
sleep_ms(1); // let the voltage regulator start and voltage settle
|
||||
voltage = rail_voltage(BUSVOODOO_XV_CHANNEL); // get xV voltage
|
||||
// without being driven it should be around the default voltage
|
||||
if (voltage<BUSVOODOO_XV_DEFAULT-0.2) {
|
||||
printf("xV voltage is lower than expected: %d.%02uV, check xV voltage regulator\n", (int32_t)voltage, (uint32_t)((voltage-(int32_t)voltage)*100));
|
||||
printf("xV voltage is lower than expected when the regulator is enabled: %.2fV, check xV voltage regulator\n", voltage);
|
||||
#if DEBUG
|
||||
while (true);
|
||||
#else
|
||||
goto error;
|
||||
#endif
|
||||
} else if (voltage>BUSVOODOO_XV_DEFAULT+0.2) {
|
||||
printf("xV voltage is too high: %d.%02uV, check xV voltage regulator\n", (int32_t)voltage, (uint32_t)((voltage-(int32_t)voltage)*100));
|
||||
printf("xV voltage is too high when the regulator is enabled: %.2fV, check xV voltage regulator\n", voltage);
|
||||
#if DEBUG
|
||||
while (true);
|
||||
#else
|
||||
|
@ -312,14 +318,14 @@ static bool test_self(void)
|
|||
voltage = rail_voltage(BUSVOODOO_XV_CHANNEL); // get xV voltage
|
||||
// check if it matched desired voltage
|
||||
if (voltage<-BUSVOODOO_XV_TEST-0.2) {
|
||||
printf("xV voltage is too low: %d.%02uV, check xV voltage regulator\n", (int32_t)voltage, (uint32_t)((voltage-(int32_t)voltage)*100));
|
||||
printf("xV voltage is too low when regulator is controlled: %.2fV, check xV voltage regulator\n", voltage);
|
||||
#if DEBUG
|
||||
while (true);
|
||||
#else
|
||||
goto error;
|
||||
#endif
|
||||
} else if (voltage>BUSVOODOO_XV_TEST+0.2) {
|
||||
printf("xV voltage is too high: %d.%02uV, check xV voltage regulator\n", (int32_t)voltage, (uint32_t)((voltage-(int32_t)voltage)*100));
|
||||
printf("xV voltage is too high when regulator is controlled: %.2fV, check xV voltage regulator\n", voltage);
|
||||
#if DEBUG
|
||||
while (true);
|
||||
#else
|
||||
|
@ -331,19 +337,30 @@ static bool test_self(void)
|
|||
sleep_ms(1); // let voltage settle
|
||||
|
||||
// check 12V voltage regulator
|
||||
gpio_set(GPIO(BUSVOODOO_12VEN_PORT), GPIO(BUSVOODOO_12VEN_PIN)); // enable 12V voltage regulator
|
||||
gpio_set(GPIO(BUSVOODOO_12VEN_PORT), GPIO(BUSVOODOO_12VEN_PIN)); // disable 12V voltage regulator
|
||||
sleep_ms(1); // let voltage settle
|
||||
voltage = rail_voltage(BUSVOODOO_12V_CHANNEL); // get 12V voltage
|
||||
if (voltage>0.2) { // ensure the output is at 0V when the regulator is not enabled
|
||||
printf("12V voltage is not 0V when the regulator is disabled: %.2fV, check 12V voltage regulator\n", voltage);
|
||||
#if DEBUG
|
||||
while (true);
|
||||
#else
|
||||
goto error;
|
||||
#endif
|
||||
}
|
||||
gpio_clear(GPIO(BUSVOODOO_12VEN_PORT), GPIO(BUSVOODOO_12VEN_PIN)); // enable 12V voltage regulator
|
||||
sleep_ms(1); // let the voltage regulator start and voltage settle
|
||||
voltage = rail_voltage(BUSVOODOO_12V_CHANNEL); // get 12V voltage
|
||||
// without being driven it should be around the default voltage
|
||||
if (voltage<BUSVOODOO_12V_DEFAULT-0.3) {
|
||||
printf("12V voltage is lower than expected: %d.%02uV, check 12V voltage regulator\n", (int32_t)voltage, (uint32_t)((voltage-(int32_t)voltage)*100));
|
||||
printf("12V voltage is lower than expected when regulator is enabled: %.2fV, check 12V voltage regulator\n", voltage);
|
||||
#if DEBUG
|
||||
while (true);
|
||||
#else
|
||||
goto error;
|
||||
#endif
|
||||
} else if (voltage>BUSVOODOO_12V_DEFAULT+0.3) {
|
||||
printf("12V voltage is too high: %d.%02uV, check 12V voltage regulator\n", (int32_t)voltage, (uint32_t)((voltage-(int32_t)voltage)*100));
|
||||
printf("12V voltage is too high when regulator is enabled: %.2V, check 12V voltage regulator\n", voltage);
|
||||
#if DEBUG
|
||||
while (true);
|
||||
#else
|
||||
|
@ -364,14 +381,14 @@ static bool test_self(void)
|
|||
sleep_ms(5); // let voltage settle
|
||||
voltage = rail_voltage(BUSVOODOO_12V_CHANNEL); // get 12V voltage
|
||||
if (voltage<-BUSVOODOO_12V_TEST-0.3) {
|
||||
printf("12V voltage is too low: %d.%02uV, check 12V voltage regulator\n", (int32_t)voltage, (uint32_t)((voltage-(int32_t)voltage)*100));
|
||||
printf("12V voltage is too low when regulator is controlled: %.2fV, check 12V voltage regulator\n", voltage);
|
||||
#if DEBUG
|
||||
while (true);
|
||||
#else
|
||||
goto error;
|
||||
#endif
|
||||
} else if (voltage>BUSVOODOO_12V_TEST+0.3) {
|
||||
printf("12V voltage is too high: %d.%02uV, check 12V voltage regulator\n", (int32_t)voltage, (uint32_t)((voltage-(int32_t)voltage)*100));
|
||||
printf("12V voltage is too high when regulator is controlled: %.2fV, check 12V voltage regulator\n", voltage);
|
||||
#if DEBUG
|
||||
while (true);
|
||||
#else
|
||||
|
@ -379,7 +396,7 @@ static bool test_self(void)
|
|||
#endif
|
||||
}
|
||||
dac_disable(BUSVOOFOO_12VCTL_CHANNEL); // disable 12V control
|
||||
gpio_clear(GPIO(BUSVOODOO_12VEN_PORT), GPIO(BUSVOODOO_12VEN_PIN)); // disable 12V voltage regulator
|
||||
gpio_set(GPIO(BUSVOODOO_12VEN_PORT), GPIO(BUSVOODOO_12VEN_PIN)); // disable 12V voltage regulator
|
||||
sleep_ms(1); // let voltage settle
|
||||
|
||||
// pull all pins down and ensure they are low
|
||||
|
@ -404,12 +421,11 @@ static bool test_self(void)
|
|||
}
|
||||
for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins) && pin<LENGTH(busvoodoo_io_names); pin++) {
|
||||
if (!gpio_get(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin])) { // ensure it really is high
|
||||
// this does not apply to v0.001 because of a design error
|
||||
printf("signal %s is low although it is pulled up\n", busvoodoo_io_names[pin]); // warn user about the error
|
||||
#if DEBUG
|
||||
// while (true);
|
||||
while (true);
|
||||
#else
|
||||
// goto error;
|
||||
goto error;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -427,12 +443,11 @@ static bool test_self(void)
|
|||
printf("signal %s of I/O-%u is low while it should be set high by signal %s of I/O-%u\n", busvoodoo_io_names[pin2], busvoodoo_io_groups[pin2], busvoodoo_io_names[pin1], busvoodoo_io_groups[pin1]); // warn user about the error
|
||||
goto error;
|
||||
} else if (busvoodoo_io_groups[pin1]!=busvoodoo_io_groups[pin2] && gpio_get(busvoodoo_io_ports[pin2], busvoodoo_io_pins[pin2])) {
|
||||
// this does not apply to v0.001 because of a design error
|
||||
// printf("signal %s of I/O-%u is high while it should not be set high by signal %s of I/O-%u\n", busvoodoo_io_names[pin2], busvoodoo_io_groups[pin2], busvoodoo_io_names[pin1], busvoodoo_io_groups[pin1]); // warn user about the error
|
||||
printf("signal %s of I/O-%u is high while it should not be set high by signal %s of I/O-%u\n", busvoodoo_io_names[pin2], busvoodoo_io_groups[pin2], busvoodoo_io_names[pin1], busvoodoo_io_groups[pin1]); // warn user about the error
|
||||
#if DEBUG
|
||||
// while (true);
|
||||
while (true);
|
||||
#else
|
||||
// goto error;
|
||||
goto error;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -456,17 +471,16 @@ static bool test_self(void)
|
|||
goto error;
|
||||
#endif
|
||||
} else if (busvoodoo_io_groups[pin1]!=busvoodoo_io_groups[pin2] && !gpio_get(busvoodoo_io_ports[pin2], busvoodoo_io_pins[pin2])) {
|
||||
// this does not apply to v0.001 because of a design error
|
||||
// printf("signal %s of I/O-%u is low while it should not be set low by signal %s of I/O-%u\n", busvoodoo_io_names[pin2], busvoodoo_io_groups[pin2], busvoodoo_io_names[pin1], busvoodoo_io_groups[pin1]); // warn user about the error
|
||||
printf("signal %s of I/O-%u is low while it should not be set low by signal %s of I/O-%u\n", busvoodoo_io_names[pin2], busvoodoo_io_groups[pin2], busvoodoo_io_names[pin1], busvoodoo_io_groups[pin1]); // warn user about the error
|
||||
#if DEBUG
|
||||
// while (true);
|
||||
while (true);
|
||||
#else
|
||||
// goto error;
|
||||
goto error;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
gpio_set_mode(busvoodoo_io_ports[pin1], GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, busvoodoo_io_pins[pin1]); // set pin back to input
|
||||
gpio_clear(busvoodoo_io_ports[pin1], busvoodoo_io_pins[pin1]); // pull pin back down
|
||||
gpio_set(busvoodoo_io_ports[pin1], busvoodoo_io_pins[pin1]); // pull pin back up
|
||||
}
|
||||
|
||||
// test 5V pull-up
|
||||
|
@ -475,17 +489,18 @@ static bool test_self(void)
|
|||
gpio_clear(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin]); // pull down to ensure it is not high by accident
|
||||
}
|
||||
gpio_clear(GPIO(BUSVOODOO_5VPULLUP_PORT), GPIO(BUSVOODOO_5VPULLUP_PIN)); // enable 5V pull-up
|
||||
gpio_clear(GPIO(BUSVOODOO_OEPULLUP_PORT), GPIO(BUSVOODOO_OEPULLUP_PIN)); // switch on embedded pull-ups
|
||||
sleep_ms(1); // wait a bit for voltage to settle
|
||||
voltage = rail_voltage(BUSVOODOO_5V_CHANNEL); // get 5V power rail voltage
|
||||
if (voltage<4.0) {
|
||||
printf("5V power rail voltage is too low: %d.%02uV, check for shorts on I/O connector\n", (int32_t)voltage, (uint32_t)((voltage-(int32_t)voltage)*100));
|
||||
printf("5V power rail voltage is too low: %.2fV, check for shorts on I/O connector\n", voltage);
|
||||
#if DEBUG
|
||||
while (true);
|
||||
#else
|
||||
goto error;
|
||||
#endif
|
||||
} else if (voltage>5.5) {
|
||||
printf("5V power rail voltage is too high: %d.%02uV, check USB port\n", (int32_t)voltage, (uint32_t)((voltage-(int32_t)voltage)*100));
|
||||
printf("5V power rail voltage is too high: %.2fV, check USB port\n", voltage);
|
||||
#if DEBUG
|
||||
while (true);
|
||||
#else
|
||||
|
@ -503,6 +518,7 @@ static bool test_self(void)
|
|||
}
|
||||
}
|
||||
gpio_set(GPIO(BUSVOODOO_5VPULLUP_PORT), GPIO(BUSVOODOO_5VPULLUP_PIN)); // disable 5V pull-up
|
||||
gpio_set(GPIO(BUSVOODOO_OEPULLUP_PORT), GPIO(BUSVOODOO_OEPULLUP_PIN)); // switch off embedded pull-up
|
||||
|
||||
// test xV pull-up set to 3.3V
|
||||
for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins); pin++) {
|
||||
|
@ -510,18 +526,18 @@ static bool test_self(void)
|
|||
gpio_clear(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin]); // pull down to ensure it is not high by accident
|
||||
}
|
||||
gpio_set(GPIO(BUSVOODOO_XVEN_PORT), GPIO(BUSVOODOO_XVEN_PIN)); // enable xV voltage regulator
|
||||
gpio_clear(GPIO(BUSVOODOO_XVPULLUP_PORT), GPIO(BUSVOODOO_XVPULLUP_PIN)); // enable xV pull-up
|
||||
gpio_clear(GPIO(BUSVOODOO_OEPULLUP_PORT), GPIO(BUSVOODOO_OEPULLUP_PIN)); // switch in embedded pull-up
|
||||
sleep_ms(1); // let the voltage regulator start and voltage settle
|
||||
voltage = rail_voltage(BUSVOODOO_XV_CHANNEL); // get xV voltage (without being driven it should be around 3.2V)
|
||||
if (voltage<BUSVOODOO_XV_DEFAULT-0.2) {
|
||||
printf("xV voltage is lower than expected: %d.%02uV, check xV voltage regulator\n", (int32_t)voltage, (uint32_t)((voltage-(int32_t)voltage)*100));
|
||||
printf("xV voltage is lower than expected: %.2fV, check xV voltage regulator\n", voltage);
|
||||
#if DEBUG
|
||||
while (true);
|
||||
#else
|
||||
goto error;
|
||||
#endif
|
||||
} else if (voltage>BUSVOODOO_XV_DEFAULT+0.2) {
|
||||
printf("xV voltage is too high: %d.%02uV, check xV voltage regulator\n", (int32_t)voltage, (uint32_t)((voltage-(int32_t)voltage)*100));
|
||||
printf("xV voltage is too high: %.2fV, check xV voltage regulator\n", voltage);
|
||||
#if DEBUG
|
||||
while (true);
|
||||
#else
|
||||
|
@ -538,7 +554,7 @@ static bool test_self(void)
|
|||
#endif
|
||||
}
|
||||
}
|
||||
gpio_clear(GPIO(BUSVOODOO_XVPULLUP_PORT), GPIO(BUSVOODOO_XVPULLUP_PIN)); // disable xV pull-up
|
||||
gpio_set(GPIO(BUSVOODOO_OEPULLUP_PORT), GPIO(BUSVOODOO_OEPULLUP_PIN)); // switch off embedded pull-up
|
||||
gpio_clear(GPIO(BUSVOODOO_XVEN_PORT), GPIO(BUSVOODOO_XVEN_PIN)); // disable xV voltage regulator
|
||||
|
||||
// test 5V and 3.3V outputs
|
||||
|
@ -546,14 +562,14 @@ static bool test_self(void)
|
|||
sleep_ms(1); // wait a bit for voltage to settle
|
||||
voltage = rail_voltage(BUSVOODOO_5V_CHANNEL); // get 5V power rail voltage
|
||||
if (voltage<4.0) {
|
||||
printf("5V power rail voltage is too low: %d.%02uV, check pin 2 on I/O connector\n", (int32_t)voltage, (uint32_t)((voltage-(int32_t)voltage)*100));
|
||||
printf("5V power rail voltage is too low: %.2fV, check pin 2 on I/O connector\n", voltage);
|
||||
#if DEBUG
|
||||
// while (true);
|
||||
while (true);
|
||||
#else
|
||||
goto error;
|
||||
#endif
|
||||
} else if (voltage>5.5) {
|
||||
printf("5V power rail voltage is too high: %d.%02uV, check pin 2 on I/O connector\n", (int32_t)voltage, (uint32_t)((voltage-(int32_t)voltage)*100));
|
||||
printf("5V power rail voltage is too high: %.2fV, check pin 2 on I/O connector\n", voltage);
|
||||
#if DEBUG
|
||||
while (true);
|
||||
#else
|
||||
|
@ -562,14 +578,14 @@ static bool test_self(void)
|
|||
}
|
||||
voltage = rail_voltage(BUSVOODOO_3V3_CHANNEL); // get 3.3V power rail voltage
|
||||
if (voltage<3.0) {
|
||||
printf("3.3V power rail voltage is too low: %d.%02uV, check pin 3 on I/O connector\n", (int32_t)voltage, (uint32_t)((voltage-(int32_t)voltage)*100));
|
||||
printf("3.3V power rail voltage is too low: %.2fV, check pin 3 on I/O connector\n", voltage);
|
||||
#if DEBUG
|
||||
while (true);
|
||||
#else
|
||||
goto error;
|
||||
#endif
|
||||
} else if (voltage>3.6) {
|
||||
printf("3.3V power rail voltage is too high: %d.%02uV, check pin 3 on I/O connector\n", (int32_t)voltage, (uint32_t)((voltage-(int32_t)voltage)*100));
|
||||
printf("3.3V power rail voltage is too high: %.2fV, check pin 3 on I/O connector\n", voltage);
|
||||
#if DEBUG
|
||||
while (true);
|
||||
#else
|
||||
|
@ -623,7 +639,7 @@ static void test_external(void)
|
|||
goto end;
|
||||
}
|
||||
gpio_set(GPIO(BUSVOODOO_XVEN_PORT), GPIO(BUSVOODOO_XVEN_PIN)); // enable xV voltage regulator
|
||||
printf("check pin 4 on I/O connector to verify xV output, it should be switched at 3.4V\n");
|
||||
printf("check pin 4 on I/O connector to verify xV output, it should be switched at %d.%dV\n", (int32_t)BUSVOODOO_XV_DEFAULT, (uint32_t)((BUSVOODOO_XV_DEFAULT-(int32_t)BUSVOODOO_XV_DEFAULT)*10));
|
||||
if (!wait_space()) {
|
||||
goto end;
|
||||
}
|
||||
|
@ -650,6 +666,18 @@ static void test_external(void)
|
|||
}
|
||||
}
|
||||
|
||||
// test 12V output on RS/CAN pin 1
|
||||
printf("check pin 1 on RS/CAN connector to verify 12V output, it should be switched off\n");
|
||||
if (!wait_space()) {
|
||||
goto end;
|
||||
}
|
||||
gpio_clear(GPIO(BUSVOODOO_12VEN_PORT), GPIO(BUSVOODOO_12VEN_PIN)); // enable 12V voltage regulator
|
||||
printf("check pin 1 on RS/CAN connector to verify 12V output, it should be switched at %d.%dV\n", (int32_t)BUSVOODOO_12V_DEFAULT, (uint32_t)((BUSVOODOO_12V_DEFAULT-(int32_t)BUSVOODOO_12V_DEFAULT)*10));
|
||||
if (!wait_space()) {
|
||||
goto end;
|
||||
}
|
||||
gpio_set(GPIO(BUSVOODOO_12VEN_PORT), GPIO(BUSVOODOO_12VEN_PIN)); // disable 12V voltage regulator
|
||||
|
||||
end:
|
||||
safe_state(); // go back to safe state
|
||||
}
|
||||
|
@ -751,7 +779,7 @@ void main(void)
|
|||
rcc_periph_clock_enable(RCC_GPIOC); // enable clock for all GPIO domains
|
||||
rcc_periph_clock_enable(RCC_GPIOD); // enable clock for all GPIO domains
|
||||
safe_state(); // switch off all outputs
|
||||
|
||||
|
||||
// setup ADC to measure the 5V, 3.3V, xV, and 12V power rails voltages
|
||||
rcc_periph_clock_enable(RCC_ADC12_IN(BUSVOODOO_5V_CHANNEL)); // enable clock for GPIO domain for 5V channel
|
||||
gpio_set_mode(ADC12_IN_PORT(BUSVOODOO_5V_CHANNEL), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, ADC12_IN_PIN(BUSVOODOO_5V_CHANNEL)); // set 5V channel as analogue input for the ADC
|
||||
|
@ -794,9 +822,17 @@ void main(void)
|
|||
printf("self-test succeeded\n"); // notify user
|
||||
}
|
||||
|
||||
// printf("testing RS port\n");
|
||||
// rs_setup();
|
||||
/*
|
||||
printf("testing RS-485 port\n");
|
||||
rs485_setup();
|
||||
*/
|
||||
|
||||
/*
|
||||
printf("testing RS-232 port\n");
|
||||
rs232_setup();
|
||||
*/
|
||||
|
||||
/*
|
||||
printf("testing OLED screen\n");
|
||||
i2c_master_setup(false);
|
||||
const uint8_t oled_set_mux_ratio[] = {0x00, 0xa8, 0x3f};
|
||||
|
@ -823,8 +859,7 @@ void main(void)
|
|||
i2c_master_write(0x3c, oled_enable_charge_pump_regulator, LENGTH(oled_enable_charge_pump_regulator), NULL, 0);
|
||||
const uint8_t oled_display_on[] = {0x80, 0xaf};
|
||||
i2c_master_write(0x3c, oled_display_on, LENGTH(oled_display_on), NULL, 0);
|
||||
while (true) {
|
||||
}
|
||||
*/
|
||||
|
||||
printf("performing external test, please follow instructions\n");
|
||||
test_external(); // perform external test
|
||||
|
|
Loading…
Reference in New Issue