26 #include <libopencmsis/core_cm3.h> 27 #include <libopencm3/stm32/gpio.h> 28 #include <libopencm3/stm32/rcc.h> 29 #include <libopencm3/stm32/dbgmcu.h> 30 #include <libopencm3/stm32/desig.h> 31 #include <libopencm3/stm32/dac.h> 41 #define BUSVOODOO_LV_DEFAULT (0.8*(1+30.0/10.0)) 42 #define BUSVOODOO_LV_TEST 2.5 43 #define BUSVOODOO_HV_DEFAULT (1.25*(1+100.0/10.0)) 44 #define BUSVOODOO_HV_TEST 12.0 51 static bool busvoodoo_hiz_setup(char** prefix, const char* line) 58 const char* pinout_io[10] = {
"GND",
"5V",
"3V3",
"LV", NULL, NULL, NULL, NULL, NULL, NULL};
63 const char* pinout_rscan[5] = {
"HV", NULL, NULL, NULL, NULL};
86 bool to_return =
false;
96 if (0==(DBGMCU_IDCODE&DBGMCU_IDCODE_DEV_ID_MASK)) {
98 }
else if (0x414!=(DBGMCU_IDCODE&DBGMCU_IDCODE_DEV_ID_MASK)) {
99 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));
102 if (0xffff==DESIG_FLASH_SIZE) {
103 printf(
"unknown flash size: this is probably a defective micro-controller\n");
109 printf(
"5V power rail voltage is too low: %.2fV\n", voltage);
115 }
else if (voltage>5.5) {
116 printf(
"5V power rail voltage is too high: %.2fV\n", voltage);
123 printf(
"3.3V power rail voltage is too low: %.2fV\n", voltage);
125 }
else if (voltage>3.6) {
126 printf(
"3.3V power rail voltage is too high: %.2fV\n", voltage);
134 printf(
"5V power rail voltage is too low when 5V output is enabled: %.2fV\n", voltage);
136 }
else if (voltage>5.5) {
137 printf(
"5V power rail voltage is too high when 5V output is enabled: %.2fV\n", voltage);
142 printf(
"3.3V power rail voltage is too low when 3V3 output is enabled: %.2fV\n", voltage);
144 }
else if (voltage>3.6) {
145 printf(
"3.3V power rail voltage is too high when 3V3 is enabled: %.2fV\n", voltage);
153 printf(
"LV voltage is %.2fV instead of 0V when the regulator is disabled\n", voltage);
183 printf(
"HV voltage is %.2fV instead of 0V when the regulator is disabled\n", voltage);
283 printf(
"5V power rail voltage is too low when used to pull up: %.2fV\n", voltage);
285 }
else if (voltage>5.5) {
286 printf(
"5V power rail voltage is too high when used to pull up: %.2fV\n", voltage);
333 printf(
"RS-485 RX is high while TX is set low\n");
341 printf(
"RS-485 RX is low while TX is set high\n");
351 #if BUSVOODOO_HARDWARE_VERSION!=0 355 gpio_clear(
GPIO(BUSVOODOO_CAN_EN_PORT),
GPIO(BUSVOODOO_CAN_EN_PIN));
356 gpio_set_mode(
GPIO(BUSVOODOO_CAN_TX_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN,
GPIO(BUSVOODOO_CAN_TX_PIN));
357 gpio_set_mode(
GPIO(BUSVOODOO_CAN_RX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN,
GPIO(BUSVOODOO_CAN_RX_PIN));
359 gpio_clear(
GPIO(BUSVOODOO_CAN_RX_PORT),
GPIO(BUSVOODOO_CAN_RX_PIN));
360 gpio_set(
GPIO(BUSVOODOO_CAN_TX_PORT),
GPIO(BUSVOODOO_CAN_TX_PIN));
362 if (0==gpio_get(
GPIO(BUSVOODOO_CAN_RX_PORT),
GPIO(BUSVOODOO_CAN_RX_PIN))) {
363 printf(
"CAN RX is low while TX is set high\n");
367 gpio_set(
GPIO(BUSVOODOO_CAN_RX_PORT),
GPIO(BUSVOODOO_CAN_RX_PIN));
368 gpio_clear(
GPIO(BUSVOODOO_CAN_TX_PORT),
GPIO(BUSVOODOO_CAN_TX_PIN));
370 if (gpio_get(
GPIO(BUSVOODOO_CAN_RX_PORT),
GPIO(BUSVOODOO_CAN_RX_PIN))) {
371 printf(
"CAN RX is high while TX is set low\n");
376 if (!gpio_get(
GPIO(BUSVOODOO_CAN_RX_PORT),
GPIO(BUSVOODOO_CAN_RX_PIN))) {
377 printf(
"CAN RX is low while the output should be back to recessive\n");
381 gpio_set(
GPIO(BUSVOODOO_CAN_EN_PORT),
GPIO(BUSVOODOO_CAN_EN_PIN));
382 gpio_set_mode(
GPIO(BUSVOODOO_CAN_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT,
GPIO(BUSVOODOO_CAN_TX_PIN));
383 gpio_set_mode(
GPIO(BUSVOODOO_CAN_RX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT,
GPIO(BUSVOODOO_CAN_RX_PIN));
388 printf(
"self-test succeeded\n");
395 printf(
"the test procedure has been aborted for safety reasons\n");
409 bool to_return =
false;
412 const char* lv_to =
"connect I/O pin 4 to ";
413 char* pinout[10] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
421 printf(
"%sI/O pin 1\n", lv_to);
439 printf(
"I/O pin 4 is high while it should be low and shorted to ground\n");
447 printf(
"%sI/O pin 2\n", lv_to);
464 printf(
"5V output is high while the power output should be switched off\n");
471 printf(
"%sI/O pin 3\n", lv_to);
491 printf(
"3V3 output is high while the power output should be switched off\n");
497 for (uint8_t io=1; io<=6; io++) {
502 printf(
"%sI/O pin %u\n", lv_to, io+4);
519 printf(
"I/O pin %u is high while it should be low\n", io+4);
539 printf(
"%sRS/CAN pin 1\n", lv_to);
557 printf(
"HV output is high while voltage regulator should be switched off\n");
562 #if BUSVOODOO_HARDWARE_VERSION==0 567 printf(
"%sRS/CAN pin 4\n", lv_to);
584 printf(
"RS-485 output B is high while it should be low\n");
595 printf(
"%sRS/CAN pin 3\n", lv_to);
612 printf(
"RS-485 output A is high while it should be low\n");
620 #if BUSVOODOO_HARDWARE_VERSION!=0 623 gpio_clear(
GPIO(BUSVOODOO_CAN_EN_PORT),
GPIO(BUSVOODOO_CAN_EN_PIN));
624 gpio_set_mode(
GPIO(BUSVOODOO_CAN_TX_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN,
GPIO(BUSVOODOO_CAN_TX_PIN));
626 gpio_set(
GPIO(BUSVOODOO_CAN_TX_PORT),
GPIO(BUSVOODOO_CAN_TX_PIN));
630 printf(
"CAN L output is low while it should be at recessive 2.5V\n");
634 printf(
"CAN L output is high while it should be at recessive 2.5V\n");
638 gpio_clear(
GPIO(BUSVOODOO_CAN_TX_PORT),
GPIO(BUSVOODOO_CAN_TX_PIN));
642 printf(
"CAN L output is high while it should at dominant <2.25V\n");
646 gpio_set(
GPIO(BUSVOODOO_CAN_EN_PORT),
GPIO(BUSVOODOO_CAN_EN_PIN));
647 gpio_set_mode(
GPIO(BUSVOODOO_CAN_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT,
GPIO(BUSVOODOO_CAN_TX_PIN));
650 #if BUSVOODOO_HARDWARE_VERSION==0 655 printf(
"%sRS/CAN pin 5\n", lv_to);
672 printf(
"RS-485 output A is high while it should be low\n");
683 printf(
"%sRS/CAN pin 4\n", lv_to);
700 printf(
"RS-485 output B is high while it should be low\n");
708 #if BUSVOODOO_HARDWARE_VERSION!=0 711 gpio_clear(
GPIO(BUSVOODOO_CAN_EN_PORT),
GPIO(BUSVOODOO_CAN_EN_PIN));
712 gpio_set_mode(
GPIO(BUSVOODOO_CAN_TX_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN,
GPIO(BUSVOODOO_CAN_TX_PIN));
714 gpio_set(
GPIO(BUSVOODOO_CAN_TX_PORT),
GPIO(BUSVOODOO_CAN_TX_PIN));
718 printf(
"CAN H output is low while it should be at recessive 2.5V\n");
722 printf(
"CAN H output is high while it should be at recessive 2.5V\n");
726 gpio_clear(
GPIO(BUSVOODOO_CAN_TX_PORT),
GPIO(BUSVOODOO_CAN_TX_PIN));
730 printf(
"CAN H output is low while it dominant >2.75V\n");
731 printf(
"%.02f\n", voltage);
735 gpio_set(
GPIO(BUSVOODOO_CAN_EN_PORT),
GPIO(BUSVOODOO_CAN_EN_PIN));
736 gpio_set_mode(
GPIO(BUSVOODOO_CAN_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT,
GPIO(BUSVOODOO_CAN_TX_PIN));
754 printf(
"connect RS/CAN pin 2 to RS/CAN pin 3\n");
773 printf(
"RS-232 RX is high while it should be set low by RS-232 TX\n");
788 printf(
"connect RS/CAN pin 4 to RS/CAN pin 5\n");
807 printf(
"RS-232 CTS is high while it should be set low by RS-232 RTS\n");
822 printf(
"user interrupted the test\n");
828 printf(
"the test procedure has been aborted for safety reasons\n");
845 RCC_CSR |= RCC_CSR_RMVF;
860 printf(
"device ID: %08x%08x%08x\n", DESIG_UNIQUE_ID0, DESIG_UNIQUE_ID1, DESIG_UNIQUE_ID2);
874 printf(
"malformed argument\n");
878 printf(
"performing self-test\n");
880 printf(
"WARNING: halting on error can cause hardware damages (press any key to exit halt state)\n");
882 printf(
"remove all cables from connectors and press space to start (or any other key to abort)\n");
886 printf(
"self-test running\n");
892 printf(
"self-test failed\n");
898 printf(
"self-test aborted\n");
912 printf(
"malformed argument\n");
916 printf(
"performing pins test\n");
918 printf(
"WARNING: halting on error can cause hardware damages (press any key to exit halt state)\n");
922 char* pinout[10] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
927 printf(
"connect one lead of jumper wire to I/O pin 4 and press space to start (or any other key to abort)\n");
932 printf(
"pins test succeeded\n");
935 printf(
"pins test failed\n");
941 printf(
"pins test aborted\n");
955 .command_description =
"show hardware and firmware version",
957 .argument_description = NULL,
962 .name =
"bootloader",
963 .command_description =
"reboot into DFU bootloader",
965 .argument_description = NULL,
970 .name =
"self-test [halt]",
971 .command_description =
"perform board self-test (optional halt on error)",
973 .argument_description = NULL,
978 .name =
"pins-test [halt]",
979 .command_description =
"perform connector pins test (optional halt on error)",
981 .argument_description = NULL,
988 .description =
"High Impedance (Z)",
void busvoodoo_leds_off(void)
switch off blue and red LEDs
#define BUSVOODOO_5V_CHANNEL
ADC channel to measure 3.3V rail.
float busvoodoo_hv_set(float voltage)
set voltage on high voltage adjustable voltage regulator
#define BUSVOODOO_LV_TEST
target LV output voltage to test if we can set control the LV voltage regulator
static void busvoodoo_hiz_bootloader(void *argument)
switch to DFU bootloader
#define BUSVOODOO_HVCTL_CHANNEL
DAC channel to control HV output voltage.
static const struct menu_command_t busvoodoo_hiz_commands[]
HiZ menu commands.
BusVoodoo global definitions and methods (API)
#define BUSVOODOO_HVEN_PIN
high voltage (HV) enable pin (active low)
#define RCC_GPIO(x)
get RCC for GPIO based on GPIO identifier
void busvoodoo_oled_text_pinout(const char *pins[10], bool io_connector)
draw pin names on bottom (blue) part in display buffer
const char * name
name of the mode (i.e.
#define BUSVOODOO_LVCTL_PORT
pin to control LV output voltage
bool busvoodoo_vout_switch(bool on)
switch 3V3 and 5V power outputs on I/O connector
#define BUSVOODOO_RS232_EN_PORT
RS-232 pin to enable receiver (active low, pulled up)
#define BUSVOODOO_HV_SET(x)
voltage to output for the DAC to set the desired HV output voltage (based on resistor values on the H...
#define BUSVOODOO_HVEN_PORT
high voltage (HV) enable pin (active low)
#define BUSVOODOO_RS232_CTS_PORT
RS-232 Clear-To-Send input pin.
void busvoodoo_oled_update(void)
update OLED display RAM with current display buffer
float busvoodoo_lv_set(float voltage)
set voltage on low voltage adjustable voltage regulator
#define BUSVOODOO_LVEN_PIN
low voltage (LV) enable pin (active high)
const char * busvoodoo_global_pinout_rscan[5]
RS/CAN connector pinout.
const uint32_t busvoodoo_io_pins[13]
pin of individual signals
#define BUSVOODOO_RS232_TX_PORT
RS-232 Transmit output pin.
global definitions and methods (API)
enum menu_argument_t argument
what kind of argument it accepts
static void busvoodoo_hiz_exit(void)
exit HiZ mode
#define GPIO(x)
get GPIO based on GPIO identifier
#define BUSVOODOO_RS485_RX_PORT
RS-485 Receive input pin.
void sleep_us(uint32_t duration)
go to sleep for some microseconds
static void busvoodoo_hiz_command_test_self(void *argument)
command to perform board self-test
#define BUSVOODOO_HV_DEFAULT
default (when not driven) HV voltage regulator output voltage based on R1 and R2
#define BUSVOODOO_RS485_RE_PORT
RS-485 pin to enable receiver (active low, pulled up)
static bool busvoodoo_hiz_test_pins(bool halt)
test if signals are soldered correctly to the connector pins
bool busvoodoo_full
is the BusVoodoo board fully populated (with HV voltage regulator, RS-232, RS-485, CAN transceiver on the back side)
static void busvoodoo_hiz_version(void *argument)
show BusVoodoo version
const struct busvoodoo_mode_t busvoodoo_hiz_mode
HiZ mode interface definition.
const uint32_t busvoodoo_io_ports[13]
port of individual signals
#define BUSVOODOO_RS485_TX_PORT
RS-485 Transmit output pin.
#define BUSVOODOO_RS232_CTS_PIN
RS-232 Clear-To-Send input pin.
#define BUSVOODOO_LV_CHANNEL
ADC channel to measure LV rail.
#define BUSVOODOO_RS232_TX_PIN
RS-232 Transmit output pin.
#define BUSVOODOO_RS485_DE_PORT
RS-485 pin to enable transmitter (active high, pulled low)
#define BUSVOODOO_RS232_RTS_PIN
RS-232 Request-To-Send output pin.
const uint8_t busvoodoo_io_groups[13]
which I/O pin (group) does the signal belong to
char shortcut
short command code (0 if not available)
void busvoodoo_leds_blink(double period, double duty)
set LED blinking pattern
void busvoodoo_led_blue_on(void)
switch on blue LED
#define BUILD_MONTH
build month as number if known, or 0 if unknown
#define BUSVOODOO_HV_CHANNEL
ADC channel to measure HV rail.
const char * busvoodoo_global_pinout_io[10]
I/O connector pinout.
#define BUSVOODOO_LVCTL_PIN
pin to control LV output voltage
char user_input_get(void)
get user input
#define BUSVOODOO_RS232_EN_PIN
RS-232 pin to enable receiver (active low, pulled up)
static bool busvoodoo_hiz_setup(char **prefix, const char *line)
setup HiZ mode
float busvoodoo_vreg_get(uint8_t channel)
read voltage from power rail
const char * busvoodoo_io_names[13]
I/O individual signal names.
#define BUSVOODOO_VOUTEN_PORT
voltage output (5V and 3.3V) enable pin (active low)
void sleep_ms(uint32_t duration)
go to sleep for some milliseconds
size_t printf(const char *format,...)
print format string on user output
#define BUSVOODOO_VOUTEN_PIN
voltage output (5V and 3.3V) enable pin (active low)
#define BUSVOODOO_RS232_RX_PORT
RS-232 Receive input pin.
printing utilities to replace the large printf from the standard library (API)
#define BUSVOODOO_RS485_DE_PIN
RS-485 pin to enable transmitter (active high, pulled low)
void busvoodoo_oled_text_left(char *text)
draw mode text on top (yellow) left side in display buffer
#define BUSVOODOO_LVEN_PORT
low voltage (LV) enable pin (active high)
float busvoodoo_embedded_pullup(bool on)
enable embedded pull-up resistors
#define BUSVOODOO_HV_TEST
target HV output voltage to test if we can set control the HV voltage regulator
void busvoodoo_led_red_off(void)
switch off red LED
#define BUSVOODOO_RS232_RTS_PORT
RS-232 Request-To-Send output pin.
static bool busvoodoo_hiz_test_self(bool halt)
perform self tests
#define LENGTH(x)
get the length of an array
#define BUSVOODOO_RS485_RE_PIN
RS-485 pin to enable receiver (active low, pulled up)
void busvoodoo_oled_text_right(char *text)
draw mode text on top (yellow) right side in display buffer
void busvoodoo_led_red_on(void)
switch on red LED
#define BUSVOODOO_RS232_RX_PIN
RS-232 Receive input pin.
#define BUSVOODOO_LV_DEFAULT
default (when not driven) LV voltage regulator output voltage based on R1 and R2
BusVoodoo high impedance (HiZ) default mode (API)
#define BUSVOODOO_RS485_RX_PIN
RS-485 Receive input pin.
library to show BusVoodoo mode information on SSD1306 OLED display: name, activity, pinout (API)
static void busvoodoo_hiz_command_test_pins(void *argument)
command to perform pins test
volatile bool user_input_available
flag set when user input is available
#define BUSVOODOO_RS485_TX_PIN
RS-485 Transmit output pin.
void busvoodoo_safe_state(void)
set safe state by disabling all outputs
#define BUILD_YEAR
build year as number if known, or 0 if unknown
char busvoodoo_version
version of the hardware board
BusVoodoo mode interface.
#define BUSVOODOO_RS232_SHDN_PORT
RS-232 pin to enable transmitter (active high, pulled low)
#define BUSVOODOO_3V3_CHANNEL
ADC channel to measure 5V rail.
#define BUSVOODOO_RS232_SHDN_PIN
RS-232 pin to enable transmitter (active high, pulled low)
#define BUILD_DAY
build day as number if known, or 0 if unknown