From 49344a7b159e44f3fd29d5628b63e45f3335ecc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Sat, 28 Apr 2018 17:45:21 +0200 Subject: [PATCH] BV: add BusVoodoo hardware version 0 support in main branch, using environment variable --- Rakefile | 6 +++- application.c | 2 +- global.h | 9 +++++- lib/busvoodoo_global.c | 2 ++ lib/busvoodoo_global.h | 2 ++ lib/busvoodoo_hiz.c | 64 +++++++++++++++++++++++++++++++++++++++++- lib/usb_cdcacm.c | 9 ++++-- 7 files changed, 88 insertions(+), 6 deletions(-) diff --git a/Rakefile b/Rakefile index f70882f..9631ac1 100644 --- a/Rakefile +++ b/Rakefile @@ -38,6 +38,10 @@ OBJCOPY = PREFIX+"-objcopy" OBJDUMP = PREFIX+"-objdump" GDB = PREFIX+"-gdb" +# BusVoodoo hardware version (0=0, 1=A, ...) +# mainly because version 0 uses different pins) +BUSVOODOO_HARDWARE_VERSION = ENV["BUSVOODOO_HARDWARE_VERSION"] || 1 + # compiler flags cflags = [ENV["CFLAGS"]] # optimize for size @@ -145,7 +149,7 @@ end desc "compile source into object" rule '.o' => ['.c', proc{|f| File.file?(f.ext("h")) ? f.ext("h") : []}, proc{|f| dependencies(f).collect{|d| File.file?(d.ext("h")) ? d.ext("h") : []}}, "#{LIBOPENCM3_LIB}/lib#{STM32F1_LIB}.a"] do |t| - sh "#{CC} #{cflags} #{archflags} -o #{t.name} -c #{t.prerequisites[0]}" + sh "#{CC} #{cflags} #{archflags} -DBUSVOODOO_HARDWARE_VERSION='#{BUSVOODOO_HARDWARE_VERSION}' -o #{t.name} -c #{t.prerequisites[0]}" end desc "generate dependencies" diff --git a/application.c b/application.c index 98a06f3..f183adf 100644 --- a/application.c +++ b/application.c @@ -274,7 +274,7 @@ void main(void) uart_setup(); // setup USART (for printing) usb_cdcacm_setup(); // setup USB CDC ACM (for printing) busvoodoo_setup(); // setup BusVoodoo board - printf("\nwelcome to BusVoodoo (%s)\n", busvoodoo_full ? "full" : "light"); // print welcome message + printf("\nwelcome to \x1b[32mBus\x1b[35mVoodoo\x1b[0m (%s)\n", busvoodoo_full ? "full" : "light"); // print welcome message // setup terminal terminal_prefix = "BV"; // set default prefix diff --git a/global.h b/global.h index e3e2817..0b9e5d3 100644 --- a/global.h +++ b/global.h @@ -407,10 +407,17 @@ #define DFU_FORCE_PIN BUTTON_PIN /**< button pin */ #define DFU_FORCE_VALUE 0 /**< button floating unpressed, connected to ground pressed to force DFU mode */ #elif defined(BUSVOODOO) - /* on BusVoodoo DFU input is on PC4 */ +#if BUSVOODOO_HARDWARE_VERSION==0 + /* on BusVoodoo v0 DFU input is on PC7 */ + #define DFU_FORCE_PORT C /**< GPIO port (port C) */ + #define DFU_FORCE_PIN 7 /**< GPIO pin (pin PC7) */ + #define DFU_FORCE_VALUE 1 /**< pin is pulled low, and goes high when shorted with VUSB */ +#else + /* on BusVoodoo vA DFU input is on PC4 */ #define DFU_FORCE_PORT C /**< GPIO port (port C) */ #define DFU_FORCE_PIN 4 /**< GPIO pin (pin PC4) */ #define DFU_FORCE_VALUE 1 /**< pin floating, set high when shorted with nearby VCC */ +#endif #else /* use the JNTRST pin as GPIO (SWJ will still be working, minus NTRST) */ #define DFU_FORCE_PORT B /**< JNTRST port (needs to be remapped to become PB4) */ diff --git a/lib/busvoodoo_global.c b/lib/busvoodoo_global.c index 8186c97..1233080 100644 --- a/lib/busvoodoo_global.c +++ b/lib/busvoodoo_global.c @@ -197,11 +197,13 @@ void busvoodoo_safe_state(void) gpio_set_mode(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS485_TX_PIN)); // set pin to floating gpio_set_mode(GPIO(BUSVOODOO_RS485_RX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS485_RX_PIN)); // set pin to floating +#if BUSVOODOO_HARDWARE_VERSION!=0 // disable CAN transceiver and 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)); // set pin to floating gpio_set_mode(GPIO(BUSVOODOO_CAN_RX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_CAN_RX_PIN)); // set pin to floating gpio_set(GPIO(BUSVOODOO_CAN_EN_PORT), GPIO(BUSVOODOO_CAN_EN_PIN)); // set high to power off transceiver gpio_set_mode(GPIO(BUSVOODOO_CAN_EN_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO(BUSVOODOO_CAN_EN_PIN)); // use external pull-up resistor to set high by default +#endif } } diff --git a/lib/busvoodoo_global.h b/lib/busvoodoo_global.h index bf83a4b..b3c919e 100644 --- a/lib/busvoodoo_global.h +++ b/lib/busvoodoo_global.h @@ -86,6 +86,7 @@ #define BUSVOODOO_RS485_RX_PIN 3 /**< RS-485 Receive input pin */ /** @} */ +#if BUSVOODOO_HARDWARE_VERSION!=0 /** @defgroup busvoodoo_can CAN transceiver connection definition * @{ */ @@ -96,6 +97,7 @@ #define BUSVOODOO_CAN_RX_PORT B /**< CAN Receive input pin */ #define BUSVOODOO_CAN_RX_PIN 8 /**< CAN Receive input pin */ /** @} */ +#endif /** @defgroup busvoodoo_version ADC pin used to identify hardware version based on voltage */ diff --git a/lib/busvoodoo_hiz.c b/lib/busvoodoo_hiz.c index 5ab195e..7fe9d23 100644 --- a/lib/busvoodoo_hiz.c +++ b/lib/busvoodoo_hiz.c @@ -347,6 +347,7 @@ static bool busvoodoo_hiz_test_self(bool halt) gpio_set_mode(GPIO(BUSVOODOO_RS485_RX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS485_RX_PIN)); // set pin to floating } +#if BUSVOODOO_HARDWARE_VERSION!=0 // test CAN transceiver if (busvoodoo_full) { // configure transceiver @@ -380,6 +381,7 @@ static bool busvoodoo_hiz_test_self(bool halt) gpio_set_mode(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_CAN_TX_PIN)); // set pin to floating gpio_set_mode(GPIO(BUSVOODOO_CAN_RX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_CAN_RX_PIN)); // set pin to floating } +#endif to_return = true; // all tests are successful printf("self-test succeeded\n"); // notify user @@ -546,6 +548,33 @@ static bool busvoodoo_hiz_test_pins(bool halt) } pinout[0] = NULL; // clear pin to test +#if BUSVOODOO_HARDWARE_VERSION==0 + // test RS-485 port pin B + gpio_set(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO(BUSVOODOO_RS485_DE_PIN)); // enable transmitter + gpio_set_mode(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX as output + gpio_clear(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX low -> B will be high + printf("%sRS/CAN pin 4\n", lv_to); + led_red(); // notify user to perform action + pinout[6] = "O"; // set target testing pin + busvoodoo_oled_text_pinout((const char**)pinout, false); // display pins to user + busvoodoo_oled_update(); // update screen + do { + sleep_ms(100); // wait for user to make connection + } while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<2.0 && !user_input_available); // wait until pin is connected + led_blue(); // notify user test is running + if (user_input_available) { // user interruption + goto error; + } + gpio_set(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX high + sleep_ms(100); // wait for voltage to settle (and debounce) + if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>1.0) { + printf("RS-485 output B is high while it should be low\n"); + goto error; + } + gpio_clear(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO(BUSVOODOO_RS485_DE_PIN)); // set low to disable transmitter + gpio_set_mode(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS485_TX_PIN)); // set pin to floating + pinout[6] = NULL; // clear pin to test +#else // test RS-485 output A gpio_set(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO(BUSVOODOO_RS485_DE_PIN)); // enable transmitter gpio_set_mode(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX as output @@ -571,7 +600,9 @@ static bool busvoodoo_hiz_test_pins(bool halt) gpio_clear(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO(BUSVOODOO_RS485_DE_PIN)); // set low to disable transmitter gpio_set_mode(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS485_TX_PIN)); // set pin to floating pinout[4] = NULL; // clear pin to test +#endif +#if BUSVOODOO_HARDWARE_VERSION!=0 // test CAN output L // configure transceiver gpio_clear(GPIO(BUSVOODOO_CAN_EN_PORT), GPIO(BUSVOODOO_CAN_EN_PIN)); // pull low to power transceiver @@ -599,7 +630,35 @@ static bool busvoodoo_hiz_test_pins(bool halt) // release transceiver gpio_set(GPIO(BUSVOODOO_CAN_EN_PORT), GPIO(BUSVOODOO_CAN_EN_PIN)); // set high to power off transceiver gpio_set_mode(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_CAN_TX_PIN)); // set pin to floating +#endif +#if BUSVOODOO_HARDWARE_VERSION==0 + // test RS-485 output A + gpio_set(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO(BUSVOODOO_RS485_DE_PIN)); // enable transmitter + gpio_set_mode(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX as output + gpio_set(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX high -> A will be high + printf("%sRS/CAN pin 5\n", lv_to); + led_red(); // notify user to perform action + pinout[8] = "O"; // set target testing pin + busvoodoo_oled_text_pinout((const char**)pinout, false); // display pins to user + busvoodoo_oled_update(); // update screen + do { + sleep_ms(100); // wait for user to make connection + } while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<2.0 && !user_input_available); // wait until pin is connected + led_blue(); // notify user test is running + if (user_input_available) { // user interruption + goto error; + } + gpio_clear(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX low + sleep_ms(100); // wait for voltage to settle (and debounce) + if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>1.0) { + printf("RS-485 output A is high while it should be low\n"); + goto error; + } + gpio_clear(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO(BUSVOODOO_RS485_DE_PIN)); // set low to disable transmitter + gpio_set_mode(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS485_TX_PIN)); // set pin to floating + pinout[8] = NULL; // clear pin to test +#else // test RS-485 port pin B gpio_set(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO(BUSVOODOO_RS485_DE_PIN)); // enable transmitter gpio_set_mode(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX as output @@ -625,7 +684,9 @@ static bool busvoodoo_hiz_test_pins(bool halt) gpio_clear(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO(BUSVOODOO_RS485_DE_PIN)); // set low to disable transmitter gpio_set_mode(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS485_TX_PIN)); // set pin to floating pinout[6] = NULL; // clear pin to test - +#endif + +#if BUSVOODOO_HARDWARE_VERSION!=0 // test CAN output H // configure transceiver gpio_clear(GPIO(BUSVOODOO_CAN_EN_PORT), GPIO(BUSVOODOO_CAN_EN_PIN)); // pull low to power transceiver @@ -654,6 +715,7 @@ static bool busvoodoo_hiz_test_pins(bool halt) // release transceiver gpio_set(GPIO(BUSVOODOO_CAN_EN_PORT), GPIO(BUSVOODOO_CAN_EN_PIN)); // set high to power off transceiver gpio_set_mode(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_CAN_TX_PIN)); // set pin to floating +#endif // test RS-232 port (with itself) rcc_periph_clock_enable(RCC_GPIO(BUSVOODOO_RS232_EN_PORT)); // enable clock for GPIO domain diff --git a/lib/usb_cdcacm.c b/lib/usb_cdcacm.c index 0781bf1..98dfb88 100644 --- a/lib/usb_cdcacm.c +++ b/lib/usb_cdcacm.c @@ -68,7 +68,7 @@ static const struct usb_device_descriptor usb_cdcacm_device_descriptor = { .bcdDevice = 0x0000, /**< Device Release Number: board version number */ .iManufacturer = 1, /**< the index of the string in the string table that represents the name of the manufacturer of this device */ .iProduct = 2, /**< the index of the string in the string table that represents the name of the product */ - .iSerialNumber = 0, /**< the index of the string in the string table that represents the serial number of this item in string form */ + .iSerialNumber = 3, /**< the index of the string in the string table that represents the serial number of this item in string form */ .bNumConfigurations = 1, /**< the number of possible configurations this device has */ }; @@ -202,7 +202,7 @@ static const struct usb_interface_descriptor usb_dfu_interface = { .bInterfaceClass = 0xFE, /**< DFU interface class (not defined in libopencm3 dfu lib) */ .bInterfaceSubClass = 1, /**< DFU interface subclass (not defined in libopencm3 dfu lib) */ .bInterfaceProtocol = 1, /**< runtime protocol (not defined in libopencm3 dfu lib) */ - .iInterface = 3, /**< the index of the string in the string table that represents interface description */ + .iInterface = 4, /**< the index of the string in the string table that represents interface description */ .extra = &usb_dfu_functional, /**< point to functional descriptor */ .extralen = sizeof(usb_dfu_functional), /**< size of functional descriptor */ @@ -240,6 +240,11 @@ static const struct usb_config_descriptor usb_cdcacm_configuration_descriptor = static const char *usb_strings[] = { "CuVoodoo", /**< manufacturer string */ "BusVoodoo multi-protocol debugging adapter", /**< product string */ +#if BUSVOODOO_HARDWARE_VERSION==0 + "0", /** BusVoodoo hardware version */ +#else + (char[]){'A'+BUSVOODOO_HARDWARE_VERSION-1, 0}, /** BusVoodoo hardware version */ +#endif "DFU bootloader (runtime mode)", /**< DFU interface string */ };