application: improve self-test and add pin test

This commit is contained in:
King Kévin 2017-12-22 17:25:05 +01:00
parent bebb9f37ac
commit 6c554a9ffd
1 changed files with 406 additions and 182 deletions

View File

@ -65,7 +65,7 @@
#define BUSVOODOO_VOUTEN_PIN 3 /**< voltage output (5V and 3.3V) enable pin (active low) */
/** @} */
/** @defgroup busvoodoo_adc inputs to measure voltages
/** @defgroup busvoodoo_adc ADC inputs to measure voltages from voltage regulators
* @{
*/
#define BUSVOODOO_3V3_CHANNEL 12 /**< ADC channel to measure 5V rail */
@ -74,26 +74,66 @@
#define BUSVOODOO_12V_CHANNEL 15 /**< ADC channel to measure 12V rail */
/** @} */
#define BUSVOOFOO_XVCTL_CHANNEL CHANNEL_1 /**< DAC channel to control xV output voltage */
/** @defgroup busvoodoo_dac DAC output to set voltages of voltage regulators
* @{
*/
#define BUSVOODOO_XVCTL_PORT A /**< pin to control xV output voltage */
#define BUSVOODOO_XVCTL_PIN 4 /**< pin to control xV output voltage */
#define BUSVOODOO_XVCTL_CHANNEL CHANNEL_1 /**< DAC channel to control xV output voltage */
#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+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_12VCTL_PORT A /**< pin to control 12V output voltage */
#define BUSVOODOO_12VCTL_PIN 5 /**< pin to control 12V output voltage */
#define BUSVOODOO_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 */
#define BUSVOODOO_12V_SET(x) ((1.25*(1+100.0/10.0)-x)*(10.0/100.0)+1.25) /**< voltage to output for the DAC to set the desired
12V output voltage (based on resistor values on the 12V adjust pins and 12V voltage reference) */
/** @} */
/** @defgroup busvoodoo_io I/O pin definitions
/** @defgroup busvoodoo_rs232 RS-232 transceiver connection definition
* @{
*/
#define BUSVOODOO_RS232_EN_PORT B /**< RS-232 pin to enable receiver (active low, pulled up) */
#define BUSVOODOO_RS232_EN_PIN 5 /**< RS-232 pin to enable receiver (active low, pulled up) */
#define BUSVOODOO_RS232_SHDN_PORT C /**< RS-232 pin to enable transmitter (active high, pulled low) */
#define BUSVOODOO_RS232_SHDN_PIN 15 /**< RS-232 pin to enable transmitter (active high, pulled low) */
#define BUSVOODOO_RS232_RTS_PORT A /**< RS-232 Request-To-Send output pin */
#define BUSVOODOO_RS232_RTS_PIN 1 /**< RS-232 Request-To-Send output pin */
#define BUSVOODOO_RS232_CTS_PORT A /**< RS-232 Clear-To-Send input pin */
#define BUSVOODOO_RS232_CTS_PIN 0 /**< RS-232 Clear-To-Send input pin */
#define BUSVOODOO_RS232_TX_PORT A /**< RS-232 Transmit output pin */
#define BUSVOODOO_RS232_TX_PIN 2 /**< RS-232 Transmit output pin */
#define BUSVOODOO_RS232_RX_PORT A /**< RS-232 Receive input pin */
#define BUSVOODOO_RS232_RX_PIN 3 /**< RS-232 Receive input pin */
/** @} */
/** @defgroup busvoodoo_can CAN transceiver connection definition
* @{
*/
#define BUSVOODOO_CAN_EN_PORT C /**< CAN pin to enable transceiver (active high, pulled low) */
#define BUSVOODOO_CAN_EN_PIN 14 /**< CAN pin to enable transceiver (active high, pulled low) */
#define BUSVOODOO_CAN_S_PORT C /**< CAN pin to set to silent mode (active low, pulled high) */
#define BUSVOODOO_CAN_S_PIN 13 /**< CAN pin to set to silent mode (active low, pulled high) */
#define BUSVOODOO_CAN_TX_PORT B /**< CAN Transmit output pin */
#define BUSVOODOO_CAN_TX_PIN 9 /**< CAN Transmit output pin */
#define BUSVOODOO_CAN_RX_PORT B /**< CAN Receive input pin */
#define BUSVOODOO_CAN_RX_PIN 8 /**< CAN Receive input pin */
/** @} */
/** @defgroup busvoodoo_io I/O connector pin definition
* @{
*/
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 */
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 */
/** @} */
/** is the BusVoodoo board fully populated (with 12V voltage regulator, RS-232, RS-485, CAN transceiver on the back side) */
static bool busvoodoo_full = false;
size_t putc(char c)
{
size_t length = 0; // number of characters printed
@ -153,6 +193,10 @@ static void safe_state(void)
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)
// set DAC channel back to analog
gpio_set_mode(GPIO(BUSVOODOO_XVCTL_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, GPIO(BUSVOODOO_XVCTL_PIN)); // set xV pin as analog
gpio_set_mode(GPIO(BUSVOODOO_12VCTL_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, GPIO(BUSVOODOO_12VCTL_PIN)); // set 12V pin as analog
// 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
@ -164,6 +208,20 @@ static void safe_state(void)
for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins); pin++) {
gpio_set_mode(busvoodoo_io_ports[pin], GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, busvoodoo_io_pins[pin]); // set pin back to input (floating)
}
// disable all RS-232 and some RS-485 signals (put back to input floating)
gpio_set_mode(GPIO(BUSVOODOO_RS232_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS232_TX_PIN));
gpio_set_mode(GPIO(BUSVOODOO_RS232_RX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS232_RX_PIN));
gpio_set_mode(GPIO(BUSVOODOO_RS232_RTS_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS232_RTS_PIN));
gpio_set_mode(GPIO(BUSVOODOO_RS232_CTS_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS232_CTS_PIN));
gpio_set(GPIO(BUSVOODOO_RS232_EN_PORT), GPIO(BUSVOODOO_RS232_EN_PIN)); // set high to disable receiver
gpio_clear(GPIO(BUSVOODOO_RS232_SHDN_PORT), GPIO(BUSVOODOO_RS232_SHDN_PIN)); // set low to disable transmitter
// disable all CAN and some RS-458 signals (put back to input floating)
gpio_set_mode(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_CAN_TX_PIN));
gpio_set_mode(GPIO(BUSVOODOO_CAN_RX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_CAN_RX_PIN));
gpio_set_mode(GPIO(BUSVOODOO_CAN_EN_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_CAN_EN_PIN));
gpio_set_mode(GPIO(BUSVOODOO_CAN_S_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_CAN_S_PIN));
}
/** read power rail voltage
@ -213,6 +271,9 @@ static bool test_self(void)
bool to_return = false; // success of the self-test
safe_state(); // start from a safe state
printf("remove all cables from connector\n");
wait_space();
// get device information
// get device identifier (DEV_ID)
// 0x412: low-density, 16-32 kB flash
@ -220,33 +281,27 @@ static bool test_self(void)
// 0x414: high-density, 256-512 kB flash
// 0x430: XL-density, 768-1024 kB flash
// 0x418: connectivity
if (0x414!=(DBGMCU_IDCODE&DBGMCU_IDCODE_DEV_ID_MASK)) {
printf("this is not a high-density device: a wrong micro-controller might have been used\n");
#if DEBUG
#else
goto error;
#endif
if (0==(DBGMCU_IDCODE&DBGMCU_IDCODE_DEV_ID_MASK)) {
printf("device identifier not set: this is probably a defective micro-controller\n");
} else if (0x414!=(DBGMCU_IDCODE&DBGMCU_IDCODE_DEV_ID_MASK)) {
printf("this (DEV_ID=%03x) is not a high-density device: a wrong micro-controller might have been used\n", (DBGMCU_IDCODE&DBGMCU_IDCODE_DEV_ID_MASK));
}
// ensure flash size is ok
if (0xffff==DESIG_FLASH_SIZE) {
printf("unknown flash size: this is probably a defective micro-controller\n");
#if DEBUG
#else
goto error;
#endif
}
// 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: %.2fV, check USB port\n", voltage);
printf("5V power rail voltage is too low: %.2fV\n", voltage);
#if DEBUG
while (true);
#else
goto error;
#endif
} else if (voltage>5.5) {
printf("5V power rail voltage is too high: %.2fV, check USB port\n", voltage);
printf("5V power rail voltage is too high: %.2fV\n", voltage);
#if DEBUG
while (true);
#else
@ -257,14 +312,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: %.2fV, check OLED connector and voltage regulator\n", voltage);
printf("3.3V power rail voltage is too low: %.2fV\n", voltage);
#if DEBUG
while (true);
#else
goto error;
#endif
} else if (voltage>3.6) {
printf("3.3V power rail voltage is too high: %.2fV, check OLED connector and voltage regulator\n", voltage);
printf("3.3V power rail voltage is too high: %.2fV\n", voltage);
#if DEBUG
while (true);
#else
@ -272,12 +327,49 @@ static bool test_self(void)
#endif
}
// test 5V and 3.3V outputs
gpio_clear(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // enable Vout
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 when 5V output is enabled: %.2fV\n", voltage);
#if DEBUG
while (true);
#else
goto error;
#endif
} else if (voltage>5.5) {
printf("5V power rail voltage is too high when 5V output is enabled: %.2fV\n", voltage);
#if DEBUG
while (true);
#else
goto error;
#endif
}
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 when 3V3 output is enabled: %.2fV\n", voltage);
#if DEBUG
while (true);
#else
goto error;
#endif
} else if (voltage>3.6) {
printf("3.3V power rail voltage is too high when 3V3 is enabled: %.2fV\n", voltage);
#if DEBUG
while (true);
#else
goto error;
#endif
}
gpio_set(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // disable Vout
// 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);
printf("xV voltage is %.2fV instead of 0V when the regulator is disabled\n", voltage);
#if DEBUG
while (true);
#else
@ -285,18 +377,18 @@ static bool test_self(void)
#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
sleep_ms(5); // 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 when the regulator is enabled: %.2fV, check xV voltage regulator\n", voltage);
printf("xV voltage is lower (%.2fV) than expected (%.2fV) when the regulator is enabled\n", voltage, BUSVOODOO_XV_DEFAULT);
#if DEBUG
while (true);
#else
goto error;
#endif
} else if (voltage>BUSVOODOO_XV_DEFAULT+0.2) {
printf("xV voltage is too high when the regulator is enabled: %.2fV, check xV voltage regulator\n", voltage);
printf("xV voltage is higher (%.2fV) than expected (%.2fV) when the regulator is enabled\n", voltage, BUSVOODOO_XV_DEFAULT);
#if DEBUG
while (true);
#else
@ -311,93 +403,95 @@ static bool test_self(void)
goto error;
}
uint16_t dac_set = BUSVOODOO_XV_SET(BUSVOODOO_XV_TEST)/voltage*4095; // DAC value corresponding to the voltage
dac_load_data_buffer_single(dac_set, RIGHT12, BUSVOOFOO_XVCTL_CHANNEL); // set output so the voltage regulator is set to 2.5V
dac_software_trigger(BUSVOOFOO_XVCTL_CHANNEL); // transfer the value to the DAC
dac_enable(BUSVOOFOO_XVCTL_CHANNEL); // enable DAC
dac_load_data_buffer_single(dac_set, RIGHT12, BUSVOODOO_XVCTL_CHANNEL); // set output so the voltage regulator is set to 2.5V
dac_software_trigger(BUSVOODOO_XVCTL_CHANNEL); // transfer the value to the DAC
dac_enable(BUSVOODOO_XVCTL_CHANNEL); // enable DAC
sleep_ms(5); // let voltage settle
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 when regulator is controlled: %.2fV, check xV voltage regulator\n", voltage);
if (voltage<BUSVOODOO_XV_TEST-0.2) {
printf("xV voltage is lower (%.2fV) than set (%.2fV)\n", voltage, BUSVOODOO_XV_TEST);
#if DEBUG
while (true);
#else
goto error;
#endif
} else if (voltage>BUSVOODOO_XV_TEST+0.2) {
printf("xV voltage is too high when regulator is controlled: %.2fV, check xV voltage regulator\n", voltage);
printf("xV voltage is highed (%.2fV) than set (%.2fV)\n", voltage, BUSVOODOO_XV_TEST);
#if DEBUG
while (true);
#else
goto error;
#endif
}
dac_disable(BUSVOOFOO_XVCTL_CHANNEL); // disable xV control
dac_disable(BUSVOODOO_XVCTL_CHANNEL); // disable xV control
gpio_clear(GPIO(BUSVOODOO_XVEN_PORT), GPIO(BUSVOODOO_XVEN_PIN)); // disable xV voltage regulator
sleep_ms(1); // let voltage settle
// check 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 (busvoodoo_full) {
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 %.2fV instead of 0V when the regulator is disabled\n", voltage);
#if DEBUG
while (true);
while (true);
#else
goto error;
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 when regulator is enabled: %.2fV, check 12V voltage regulator\n", voltage);
}
gpio_clear(GPIO(BUSVOODOO_12VEN_PORT), GPIO(BUSVOODOO_12VEN_PIN)); // enable 12V voltage regulator
sleep_ms(10); // 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 (%.2fV) than expected (%.2fV) when regulator is enabled\n", voltage, BUSVOODOO_12V_DEFAULT);
#if DEBUG
while (true);
while (true);
#else
goto error;
goto error;
#endif
} else if (voltage>BUSVOODOO_12V_DEFAULT+0.3) {
printf("12V voltage is too high when regulator is enabled: %.2V, check 12V voltage regulator\n", voltage);
} else if (voltage>BUSVOODOO_12V_DEFAULT+0.3) {
printf("12V voltage is higher (%.2fV) than expected (%.2fV) when regulator is enabled\n", voltage, BUSVOODOO_12V_DEFAULT);
#if DEBUG
while (true);
while (true);
#else
goto error;
goto error;
#endif
}
}
// check if we can control 12V voltage regulator
voltage = rail_voltage(BUSVOODOO_3V3_CHANNEL); // get reference voltage
if (isnan(voltage)) {
printf("can get 3V3 rail voltage");
goto error;
}
dac_set = BUSVOODOO_12V_SET(BUSVOODOO_12V_TEST)/voltage*4095; // DAC value corresponding to the voltage
dac_load_data_buffer_single(dac_set, RIGHT12, BUSVOOFOO_12VCTL_CHANNEL); // set output so the voltage regulator is set to desired output voltage
dac_software_trigger(BUSVOOFOO_12VCTL_CHANNEL); // transfer the value to the DAC
dac_enable(BUSVOOFOO_12VCTL_CHANNEL); // enable DAC
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 when regulator is controlled: %.2fV, check 12V voltage regulator\n", voltage);
// check if we can control 12V voltage regulator
voltage = rail_voltage(BUSVOODOO_3V3_CHANNEL); // get reference voltage
if (isnan(voltage)) {
printf("can get 3V3 rail voltage");
goto error;
}
dac_set = BUSVOODOO_12V_SET(BUSVOODOO_12V_TEST)/voltage*4095; // DAC value corresponding to the voltage
dac_load_data_buffer_single(dac_set, RIGHT12, BUSVOODOO_12VCTL_CHANNEL); // set output so the voltage regulator is set to desired output voltage
dac_software_trigger(BUSVOODOO_12VCTL_CHANNEL); // transfer the value to the DAC
dac_enable(BUSVOODOO_12VCTL_CHANNEL); // enable DAC
sleep_ms(10); // let voltage settle
voltage = rail_voltage(BUSVOODOO_12V_CHANNEL); // get 12V voltage
if (voltage<BUSVOODOO_12V_TEST-0.3) {
printf("12V voltage is lower (%.2fV) than set (%.2fV)\n", voltage, BUSVOODOO_12V_TEST);
#if DEBUG
while (true);
while (true);
#else
goto error;
goto error;
#endif
} else if (voltage>BUSVOODOO_12V_TEST+0.3) {
printf("12V voltage is too high when regulator is controlled: %.2fV, check 12V voltage regulator\n", voltage);
} else if (voltage>BUSVOODOO_12V_TEST+0.3) {
printf("12V voltage is higher (%.2fV) than set (%.2fV)\n", voltage, BUSVOODOO_12V_TEST);
#if DEBUG
while (true);
while (true);
#else
goto error;
goto error;
#endif
}
dac_disable(BUSVOODOO_12VCTL_CHANNEL); // disable 12V control
gpio_set(GPIO(BUSVOODOO_12VEN_PORT), GPIO(BUSVOODOO_12VEN_PIN)); // disable 12V voltage regulator
sleep_ms(1); // let voltage settle
}
dac_disable(BUSVOOFOO_12VCTL_CHANNEL); // disable 12V control
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
for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins); pin++) {
@ -421,7 +515,7 @@ 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
printf("signal %s is low although it is pulled up\n", busvoodoo_io_names[pin]); // warn user about the error
printf("signal %s is low although it is pulled up (internal)\n", busvoodoo_io_names[pin]); // warn user about the error
#if DEBUG
while (true);
#else
@ -441,7 +535,11 @@ static bool test_self(void)
for (uint8_t pin2=0; pin2<LENGTH(busvoodoo_io_ports) && pin2<LENGTH(busvoodoo_io_pins) && pin2<LENGTH(busvoodoo_io_groups) && pin2<LENGTH(busvoodoo_io_names); pin2++) {
if (busvoodoo_io_groups[pin1]==busvoodoo_io_groups[pin2] && !gpio_get(busvoodoo_io_ports[pin2], busvoodoo_io_pins[pin2])) {
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
#if DEBUG
while (true);
#else
goto error;
#endif
} else if (busvoodoo_io_groups[pin1]!=busvoodoo_io_groups[pin2] && gpio_get(busvoodoo_io_ports[pin2], busvoodoo_io_pins[pin2])) {
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
@ -493,14 +591,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: %.2fV, check for shorts on I/O connector\n", voltage);
printf("5V power rail voltage is too low when used to pull up: %.2fV\n", voltage);
#if DEBUG
while (true);
#else
goto error;
#endif
} else if (voltage>5.5) {
printf("5V power rail voltage is too high: %.2fV, check USB port\n", voltage);
printf("5V power rail voltage is too high when used to pull up: %.2fV\n", voltage);
#if DEBUG
while (true);
#else
@ -509,7 +607,7 @@ 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
printf("signal %s is low although it is pulled up by 5V\n", busvoodoo_io_names[pin]); // warn user about the error
printf("signal %s is low although it is pulled up by 5V (embedded)\n", busvoodoo_io_names[pin]); // warn user about the error
#if DEBUG
while (true);
#else
@ -527,17 +625,17 @@ static bool test_self(void)
}
gpio_set(GPIO(BUSVOODOO_XVEN_PORT), GPIO(BUSVOODOO_XVEN_PIN)); // enable xV voltage regulator
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
sleep_ms(5); // 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: %.2fV, check xV voltage regulator\n", voltage);
printf("xV voltage is lower (%.2fV) than expected (%.2fV) when used to pull up\n", voltage, BUSVOODOO_XV_DEFAULT);
#if DEBUG
while (true);
#else
goto error;
#endif
} else if (voltage>BUSVOODOO_XV_DEFAULT+0.2) {
printf("xV voltage is too high: %.2fV, check xV voltage regulator\n", voltage);
printf("xV voltage is higher (%.2fV) than expected (%.2fV) when used to pull up\n", voltage, BUSVOODOO_XV_DEFAULT);
#if DEBUG
while (true);
#else
@ -546,7 +644,7 @@ 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
printf("signal %s is low although it is pulled up by xV\n", busvoodoo_io_names[pin]); // warn user about the error
printf("signal %s is low although it is pulled up by xV (embedded)\n", busvoodoo_io_names[pin]); // warn user about the error
#if DEBUG
while (true);
#else
@ -557,129 +655,217 @@ static bool test_self(void)
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
gpio_clear(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // enable Vout
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: %.2fV, check pin 2 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: %.2fV, check pin 2 on I/O connector\n", voltage);
#if DEBUG
while (true);
#else
goto error;
#endif
}
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: %.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: %.2fV, check pin 3 on I/O connector\n", voltage);
#if DEBUG
while (true);
#else
goto error;
#endif
}
gpio_set(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // disable Vout
to_return = true; // all tests are successful
error:
safe_state(); // set back to safe state
if (!to_return) {
printf("the test procedure has been interrupted for safety reasons\n");
printf("the test procedure has been aborted for safety reasons\n");
}
return to_return;
}
/** perform tests using external user */
static void test_external(void)
/** test if signals are soldered correctly to the connector pins */
static bool test_pins(void)
{
bool to_return = false; // test result to return
safe_state(); // start from safe state with all outputs switched off
// test 5V output on pin 2
printf("check pin 2 on I/O connector to verify 5V output, it should be switched off\n");
if (!wait_space()) {
goto end;
const char* xv_to = "connect I/O pin 4 to "; // most outputs will be tested using xV ADC
const char* xv_high = "pin 4 is high while it should be low, other pin might be defective\n"; // error message if expect low output is high
printf("test will proceed automatically once the connection is detected\n");
// test GND on pin 1 by shorting xV_CTL to ground (through 40k resistor) and measure short
gpio_set(GPIO(BUSVOODOO_XVCTL_PORT), GPIO(BUSVOODOO_XVCTL_PIN)); // set pin high
gpio_set_mode(GPIO(BUSVOODOO_XVCTL_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_XVCTL_PIN)); // set xV control pin as output
printf("%sI/O pin 1\n", xv_to);
while (rail_voltage(BUSVOODOO_XV_CHANNEL)>0.2) { // wait until pin is shorted to ground
sleep_ms(200); // wait for user to make connection
}
gpio_clear(GPIO(BUSVOODOO_XVCTL_PORT), GPIO(BUSVOODOO_XVCTL_PIN)); // set pin low
gpio_set_mode(GPIO(BUSVOODOO_XVCTL_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_XVCTL_PIN)); // set xV control pin as output
led_toggle(); // notify user test is almost almost
sleep_ms(200); // wait for voltage to settle an debounce
if (rail_voltage(BUSVOODOO_XV_CHANNEL)>0.2) {
printf(xv_high);
#if DEBUG
while (true);
#else
goto error;
#endif
}
gpio_set_mode(GPIO(BUSVOODOO_XVCTL_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, GPIO(BUSVOODOO_XVCTL_PIN)); // set xV control pin back to analog input for DAC
led_toggle(); // notify user test is complete
// test 5V output on pin 2
gpio_clear(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // enable Vout
printf("check pin 2 on I/O connector to verify 5V output, it should be switched on\n");
if (!wait_space()) {
goto end;
printf("%sI/O pin 2\n", xv_to);
while (rail_voltage(BUSVOODOO_XV_CHANNEL)<0.2) { // wait until pin is connected
sleep_ms(200); // wait for user to make connection
}
gpio_set(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // disable Vout
led_toggle(); // notify user test is almost complete
sleep_ms(200); // wait for voltage to settle and debounce
if (rail_voltage(BUSVOODOO_XV_CHANNEL)>0.2) {
printf(xv_high);
#if DEBUG
while (true);
#else
goto error;
#endif
}
led_toggle(); // notify user test is complete
// test 3.3V output on pin 3
printf("check pin 3 on I/O connector to verify 3.3V output, it should be switched off\n");
if (!wait_space()) {
goto end;
}
gpio_clear(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // enable Vout
printf("check pin 3 on I/O connector to verify 3.3V output, it should be switched on\n");
if (!wait_space()) {
goto end;
printf("%sI/O pin 3\n", xv_to);
while (rail_voltage(BUSVOODOO_XV_CHANNEL)<0.2 || rail_voltage(BUSVOODOO_XV_CHANNEL)>3.5) { // wait until pin is connected
sleep_ms(200); // wait for user to make connection
}
gpio_set(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // disable Vout
// test xV output on pin 4
printf("check pin 4 on I/O connector to verify xV output, it should be switched off\n");
if (!wait_space()) {
goto end;
led_toggle(); // notify user test is almost complete
sleep_ms(200); // wait for voltage to settle and debounce
if (rail_voltage(BUSVOODOO_XV_CHANNEL)>0.2) {
printf(xv_high);
#if DEBUG
while (true);
#else
goto error;
#endif
}
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 %d.%dV\n", (int32_t)BUSVOODOO_XV_DEFAULT, (uint32_t)((BUSVOODOO_XV_DEFAULT-(int32_t)BUSVOODOO_XV_DEFAULT)*10));
if (!wait_space()) {
goto end;
}
gpio_clear(GPIO(BUSVOODOO_XVEN_PORT), GPIO(BUSVOODOO_XVEN_PIN)); // disable xV voltage regulator
led_toggle(); // notify user test is complete
// test I/O pins
for (uint8_t io=1; io<=6; io++) { // test each I/O pin
for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins) && pin<LENGTH(busvoodoo_io_groups); pin++) { // look for a pin mapped on this I/O
if (busvoodoo_io_groups[pin]==io) {
gpio_set_mode(busvoodoo_io_ports[pin], GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, busvoodoo_io_pins[pin]); // set pin to output
gpio_clear(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin]); // set pin low
printf("check pin %u on I/O connector to verify output, it should be low\n", 4+io);
if (!wait_space()) {
goto end;
}
gpio_set(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin]); // set pin high
printf("check pin %u on I/O connector to verify output, it should be high\n", 4+io);
if (!wait_space()) {
goto end;
gpio_set_mode(busvoodoo_io_ports[pin], GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, busvoodoo_io_pins[pin]); // set pin to output
printf("%sI/O pin %u\n", xv_to, io+4);
while (rail_voltage(BUSVOODOO_XV_CHANNEL)<0.2) { // wait until pin is connected
sleep_ms(200); // wait for user to make connection
}
gpio_clear(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin]); // set pin low
led_toggle(); // notify user test is almost complete
sleep_ms(200); // wait for voltage to settle and debounce
if (rail_voltage(BUSVOODOO_XV_CHANNEL)>0.2) {
printf(xv_high);
#if DEBUG
while (true);
#else
goto error;
#endif
}
gpio_set_mode(busvoodoo_io_ports[pin], GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, busvoodoo_io_pins[pin]); // set pin back to input
led_toggle(); // notify user test is complete
break; // stop looking for pin
}
}
}
// 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
if (busvoodoo_full) {
// test 12V output on RS/CAN pin 1
double voltage = rail_voltage(BUSVOODOO_3V3_CHANNEL); // get reference voltage
uint16_t dac_set = BUSVOODOO_12V_SET(5.0)/voltage*4095; // DAC value corresponding to the voltage
dac_load_data_buffer_single(dac_set, RIGHT12, BUSVOODOO_12VCTL_CHANNEL); // set output so the voltage regulator is set to desired output voltage
dac_software_trigger(BUSVOODOO_12VCTL_CHANNEL); // transfer the value to the DAC
dac_enable(BUSVOODOO_12VCTL_CHANNEL); // enable DAC
gpio_clear(GPIO(BUSVOODOO_12VEN_PORT), GPIO(BUSVOODOO_12VEN_PIN)); // enable 12V voltage regulator
printf("%sRS/CAN pin 1\n", xv_to);
while (rail_voltage(BUSVOODOO_XV_CHANNEL)<0.2) { // wait until pin is connected
sleep_ms(200); // wait for user to make connection
}
gpio_set(GPIO(BUSVOODOO_12VEN_PORT), GPIO(BUSVOODOO_12VEN_PIN)); // disable 12V voltage regulator
dac_disable(BUSVOODOO_12VCTL_CHANNEL); // disable 12V control
led_toggle(); // notify user test is almost complete
sleep_ms(200); // wait for voltage to settle (and debounce)
if (rail_voltage(BUSVOODOO_XV_CHANNEL)>0.2) {
printf(xv_high);
#if DEBUG
while (true);
#else
goto error;
#endif
}
led_toggle(); // notify user test is complete
end:
// test RS-232 port (with itself)
rcc_periph_clock_enable(RCC_GPIO(BUSVOODOO_RS232_EN_PORT)); // enable clock for GPIO domain
gpio_clear(GPIO(BUSVOODOO_RS232_EN_PORT), GPIO(BUSVOODOO_RS232_EN_PIN)); // set low to enable receiver
gpio_set_mode(GPIO(BUSVOODOO_RS232_EN_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO(BUSVOODOO_RS232_EN_PIN)); // set pin as output (open-drain pulled high to disable receiver)
rcc_periph_clock_enable(RCC_GPIO(BUSVOODOO_RS232_SHDN_PORT)); // enable clock for GPIO domain
gpio_set(GPIO(BUSVOODOO_RS232_SHDN_PORT), GPIO(BUSVOODOO_RS232_SHDN_PIN)); // set high to enable transmitter
gpio_set_mode(GPIO(BUSVOODOO_RS232_SHDN_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_RS232_SHDN_PIN)); // set pin as output (push-pull pulled low to disable transmitter)
rcc_periph_clock_enable(RCC_GPIO(BUSVOODOO_RS232_TX_PORT)); // enable clock for GPIO
gpio_set_mode(GPIO(BUSVOODOO_RS232_TX_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_RS232_TX_PIN)); // set pin as output (push-pull)
rcc_periph_clock_enable(RCC_GPIO(BUSVOODOO_RS232_RX_PORT)); // enable clock for GPIO
gpio_set_mode(GPIO(BUSVOODOO_RS232_RX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO(BUSVOODOO_RS232_RX_PIN)); // set pin as input (with pull resistors)
// start by setting low since unconnected (pulled to ground by 3 kO) is considered as high
gpio_clear(GPIO(BUSVOODOO_RS232_TX_PORT), GPIO(BUSVOODOO_RS232_TX_PIN)); // set low
gpio_set(GPIO(BUSVOODOO_RS232_RX_PORT), GPIO(BUSVOODOO_RS232_RX_PIN)); // pull high to avoid false negative
sleep_ms(5);
printf("connect RS/CAN pin 2 to RS/CAN pin 3\n");
while (gpio_get(GPIO(BUSVOODOO_RS232_RX_PORT), GPIO(BUSVOODOO_RS232_RX_PIN))) { // wait until pin is connected
sleep_ms(200); // wait for user to make connection
}
gpio_set(GPIO(BUSVOODOO_RS232_TX_PORT), GPIO(BUSVOODOO_RS232_TX_PIN)); // set high
gpio_clear(GPIO(BUSVOODOO_RS232_RX_PORT), GPIO(BUSVOODOO_RS232_RX_PIN)); // pull low to avoid false negative
led_toggle(); // notify user test is almost complete
sleep_ms(200); // wait for voltage to settle and debounce
if (!gpio_get(GPIO(BUSVOODOO_RS232_RX_PORT), GPIO(BUSVOODOO_RS232_RX_PIN))) { // check if RX is set low by TX
printf("CAN/RS pin 2 is high while it should be set low by pin 3\n");
#if DEBUG
while (true);
#else
goto error;
#endif
}
gpio_set_mode(GPIO(BUSVOODOO_RS232_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS232_TX_PIN)); // free pin
gpio_set_mode(GPIO(BUSVOODOO_RS232_RX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS232_RX_PIN)); // free pin
led_toggle(); // notify user test is complete
rcc_periph_clock_enable(RCC_GPIO(BUSVOODOO_RS232_RTS_PORT)); // enable clock for GPIO
gpio_set_mode(GPIO(BUSVOODOO_RS232_RTS_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_RS232_RTS_PIN)); // set pin as output (push-pull)
rcc_periph_clock_enable(RCC_GPIO(BUSVOODOO_RS232_CTS_PORT)); // enable clock for GPIO
gpio_set_mode(GPIO(BUSVOODOO_RS232_CTS_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO(BUSVOODOO_RS232_CTS_PIN)); // set pin as input (with pull resistors)
// start by setting low since unconnected (pulled to ground by 3 kO) is considered as high
gpio_clear(GPIO(BUSVOODOO_RS232_RTS_PORT), GPIO(BUSVOODOO_RS232_RTS_PIN)); // set low
gpio_set(GPIO(BUSVOODOO_RS232_CTS_PORT), GPIO(BUSVOODOO_RS232_CTS_PIN)); // pull high to avoid false negative
printf("connect RS/CAN pin 4 to RS/CAN pin 5\n");
while (gpio_get(GPIO(BUSVOODOO_RS232_CTS_PORT), GPIO(BUSVOODOO_RS232_CTS_PIN))) { // wait until pin is connected
sleep_ms(200); // wait for user to make connection
}
gpio_set(GPIO(BUSVOODOO_RS232_RTS_PORT), GPIO(BUSVOODOO_RS232_RTS_PIN)); // set high
gpio_clear(GPIO(BUSVOODOO_RS232_CTS_PORT), GPIO(BUSVOODOO_RS232_CTS_PIN)); // pull low to avoid false negative
led_toggle(); // notify user test is almost complete
sleep_ms(200); // wait for voltage to settle an debounce
if (!gpio_get(GPIO(BUSVOODOO_RS232_CTS_PORT), GPIO(BUSVOODOO_RS232_CTS_PIN))) { // check if CTS is set high by RTS
printf("CAN/RS pin 5 is high while it should be set low by pin 4\n");
#if DEBUG
while (true);
#else
goto error;
#endif
}
gpio_set_mode(GPIO(BUSVOODOO_RS232_RTS_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS232_RTS_PIN)); // free pin
gpio_set_mode(GPIO(BUSVOODOO_RS232_CTS_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS232_CTS_PIN)); // free pin
led_toggle(); // notify user test is complete
gpio_set(GPIO(BUSVOODOO_RS232_EN_PORT), GPIO(BUSVOODOO_RS232_EN_PIN)); // set high to disable receiver
gpio_clear(GPIO(BUSVOODOO_RS232_SHDN_PORT), GPIO(BUSVOODOO_RS232_SHDN_PIN)); // set low to disable transmitter
}
to_return = true; // all tests passed
#if DEBUG
#else
error:
#endif
safe_state(); // go back to safe state
if (!to_return) {
printf("the test procedure has been aborted for safety reasons\n");
}
return to_return;
}
/** user input command */
@ -759,8 +945,8 @@ void main(void)
uart_setup(); // setup USART (for printing)
usb_cdcacm_setup(); // setup USB CDC ACM (for printing)
led_blink(0, 1); // switch blue LED on to show firmware is working
printf("\nwelcome to BusVoodoo\n"); // print welcome message
/*
#if !(DEBUG)
// show watchdog information
printf("watchdog set to (%.2fs)\n",WATCHDOG_PERIOD/1000.0);
@ -772,6 +958,7 @@ void main(void)
printf("hardware wachtdog used (started at reset)\n");
}
#endif
*/
// enable all GPIO domains since we use pins on all ports
rcc_periph_clock_enable(RCC_GPIOA); // enable clock for all GPIO domains
@ -780,6 +967,21 @@ void main(void)
rcc_periph_clock_enable(RCC_GPIOD); // enable clock for all GPIO domains
safe_state(); // switch off all outputs
printf("\nwelcome to BusVoodoo ("); // print welcome message
// check if this BusVoodoo is a full version
rcc_periph_clock_enable(RCC_ADC12_IN(BUSVOODOO_12V_CHANNEL)); // enable clock for GPIO domain for 12V channel
gpio_set(ADC12_IN_PORT(BUSVOODOO_12V_CHANNEL), ADC12_IN_PIN(BUSVOODOO_12V_CHANNEL)); // pull ADC 12V high
gpio_set_mode(ADC12_IN_PORT(BUSVOODOO_12V_CHANNEL), GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, ADC12_IN_PIN(BUSVOODOO_12V_CHANNEL)); // set 12V channel as digital input with pull-up capabilities
// on a full version (fully populated board) the ADC 12V signal will be pulled low
if (gpio_get(ADC12_IN_PORT(BUSVOODOO_12V_CHANNEL), ADC12_IN_PIN(BUSVOODOO_12V_CHANNEL))) { // check is ADC 12V is pulled low
busvoodoo_full = false;
printf("light");
} else {
busvoodoo_full = true;
printf("full");
}
printf(" version)\n");
// 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
@ -803,25 +1005,35 @@ void main(void)
adc_calibration(ADC1); // calibrate ADC for less accuracy errors
// setup DAC to control xV and 12V voltage outputs
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, GPIO4); // set both DAC channels as analog
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, GPIO5); // set both DAC channels as analog
gpio_set_mode(GPIO(BUSVOODOO_XVCTL_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, GPIO(BUSVOODOO_XVCTL_PIN)); // set xV pin as analog (the DAC will use it as output)
rcc_periph_clock_enable(RCC_DAC); // enable clock for DAC domain
dac_disable(BUSVOOFOO_XVCTL_CHANNEL); // disable output to configure it properly
dac_disable(BUSVOOFOO_12VCTL_CHANNEL); // disable output to configure it properly
dac_buffer_enable(BUSVOOFOO_XVCTL_CHANNEL); // enable output buffer to be able to drive larger loads (should be per default)
dac_buffer_enable(BUSVOOFOO_12VCTL_CHANNEL); // enable output buffer to be able to drive larger loads (should be per default)
dac_disable(BUSVOODOO_XVCTL_CHANNEL); // disable output to configure it properly
dac_buffer_enable(BUSVOODOO_XVCTL_CHANNEL); // enable output buffer to be able to drive larger loads (should be per default)
if (busvoodoo_full) {
gpio_set_mode(GPIO(BUSVOODOO_12VCTL_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, GPIO(BUSVOODOO_12VCTL_PIN)); // set 12V pin as analog (the DAC will use it as output)
dac_disable(BUSVOODOO_12VCTL_CHANNEL); // disable output to configure it properly
dac_buffer_enable(BUSVOODOO_12VCTL_CHANNEL); // enable output buffer to be able to drive larger loads (should be per default)
}
dac_set_trigger_source(DAC_CR_TSEL1_SW); // use software to trigger the voltage change
dac_set_trigger_source(DAC_CR_TSEL2_SW); // use software to trigger the voltage change
// perform tests
printf("performing self-test, please remove all cables from connector\n");
printf("performing self-test, please follow instructions\n");
if (!test_self()) { // perform self-test
printf("self-test failed\n"); // notify user
led_blink(0.5, 0.5); // show error on LEDs
} else {
led_blink(0, 1.0); // show blue OK LED
printf("self-test succeeded\n"); // notify user
}
printf("performing pin test, please follow instructions\n");
if (!test_pins()) { // perform external test
led_blink(0.5, 0.5); // show error on LEDs
} else {
led_blink(0, 1.0); // show blue OK LED
printf("pin test succeeded\n"); // notify user
}
/*
printf("testing RS-485 port\n");
rs485_setup();
@ -832,6 +1044,22 @@ void main(void)
rs232_setup();
*/
/*
// test CAN
gpio_clear(GPIOC, GPIO13);
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO13);
gpio_set(GPIOB, GPIO9);
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO9); // CAN TX
gpio_set_mode(GPIOB, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO8); // CAN RX
gpio_clear(GPIOC, GPIO7);
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO7); // CAN EN
while (true) {
gpio_toggle(GPIOB, GPIO9);
sleep_ms(100);
}
wait_space();
*/
/*
printf("testing OLED screen\n");
i2c_master_setup(false);
@ -861,9 +1089,6 @@ void main(void)
i2c_master_write(0x3c, oled_display_on, LENGTH(oled_display_on), NULL, 0);
*/
printf("performing external test, please follow instructions\n");
test_external(); // perform external test
// main loop
printf("command input: ready\n");
bool action = false; // if an action has been performed don't go to sleep
@ -887,8 +1112,7 @@ void main(void)
while (char_flag) { // user data received
char_flag = false; // reset flag
action = true; // action has been performed
//printf("%c",c); // echo receive character
printf("%02x\n",c);
printf("%c",c); // echo receive character
if (c=='\r' || c=='\n') { // end of command received
if (command_i>0) { // there is a command to process
command[command_i] = 0; // end string