27 #include <libopencm3/stm32/gpio.h> 28 #include <libopencm3/stm32/rcc.h> 29 #include <libopencm3/stm32/usart.h> 42 #define BUSVOODOO_USART_ID 3 46 static enum busvoodoo_uart_setting_t { 47 BUSVOODOO_UART_SETTING_NONE,
48 BUSVOODOO_UART_SETTING_BAUDRATE,
49 BUSVOODOO_UART_SETTING_DATABITS,
50 BUSVOODOO_UART_SETTING_PARITY,
51 BUSVOODOO_UART_SETTING_STOPBITS,
52 BUSVOODOO_UART_SETTING_HWFLOWCTL,
53 BUSVOODOO_UART_SETTING_DRIVE,
54 BUSVOODOO_UART_SETTING_DONE,
78 bool complete =
false;
83 case BUSVOODOO_UART_SETTING_NONE:
88 case BUSVOODOO_UART_SETTING_BAUDRATE:
89 if (NULL==line || 0==strlen(line)) {
92 uint32_t baudrate = atoi(line);
93 if (baudrate>0 && baudrate<=2000000) {
103 case BUSVOODOO_UART_SETTING_DATABITS:
104 if (NULL==line || 0==strlen(line)) {
107 uint8_t databits = atoi(line);
108 if (8==databits || 9==databits) {
121 case BUSVOODOO_UART_SETTING_PARITY:
122 if (NULL==line || 0==strlen(line)) {
124 }
else if (1==strlen(line)) {
128 }
else if (
'2'==line[0]) {
131 }
else if (
'3'==line[0]) {
145 case BUSVOODOO_UART_SETTING_STOPBITS:
146 if (NULL==line || 0==strlen(line)) {
148 }
else if (1==strlen(line)) {
152 }
else if (
'2'==line[0]) {
155 }
else if (
'3'==line[0]) {
158 }
else if (
'4'==line[0]) {
164 printf(
"1) no flow control\n");
165 printf(
"2) RTS/CTS hardware flow control\n");
170 case BUSVOODOO_UART_SETTING_HWFLOWCTL:
171 if (NULL==line || 0==strlen(line)) {
173 }
else if (1==strlen(line)) {
174 if (
'1'==line[0] ||
'2'==line[0]) {
180 printf(
"1) push-pull (3.3V)\n");
181 printf(
"2) open-drain, with embedded pull-up resistors (2kO)\n");
182 printf(
"3) open-drain, with external pull-up resistors\n");
187 case BUSVOODOO_UART_SETTING_DRIVE:
188 if (NULL==line || 0==strlen(line)) {
190 }
else if (1==strlen(line)) {
191 uint8_t drive = atoi(line);
192 if (1==drive || 2==drive || 3==drive) {
199 rcc_periph_clock_enable(RCC_AFIO);
231 printf(
"use LV to set pull-up voltage\n");
238 char* pinout_io[10] = {
"GND",
"5V",
"3V3",
"LV",
"Rx",
"Tx", NULL, NULL, NULL, NULL};
240 pinout_io[6] =
"RTS";
241 pinout_io[7] =
"CTS";
296 printf(
"write: '%c'/0x", value);
343 }
else if (error_framing) {
345 }
else if (error_parity) {
363 uint32_t length = strlen(action);
364 if (NULL==action || 0==length) {
368 if (1==length &&
'r'==action[0]) {
372 for (uint32_t i=0; i<repetition; i++) {
375 }
else if (1==length &&
'u'==action[0]) {
379 printf(
"wait for %u us\n", repetition);
381 }
else if (1==length &&
'm'==action[0]) {
385 printf(
"wait for %u ms\n", repetition);
387 }
else if (
'0'==action[0]) {
392 for (uint32_t i=0; i<repetition; i++) {
395 }
else if (
'x'==action[1] ||
'b'==action[1]) {
397 }
else if (action[1]>=
'0' && action[1]<=
'9') {
402 }
else if (
'x'==action[0] && length>1) {
403 for (uint32_t i=1; i<length; i++) {
404 if (!((action[i]>=
'0' && action[i]<=
'9') || (action[i]>=
'a' && action[i]<=
'f') || (action[i]>=
'A' && action[i]<=
'F'))) {
411 uint32_t value = strtol(&action[1], NULL, 16);
412 for (uint32_t i=0; i<repetition; i++) {
415 }
else if (
'b'==action[0] && length>1) {
416 for (uint32_t i=1; i<length; i++) {
417 if (action[i]<
'0' || action[i]>
'1') {
424 uint32_t value = strtol(&action[1], NULL, 2);
425 for (uint32_t i=0; i<repetition; i++) {
428 }
else if (action[0]>=
'1' && action[0]<=
'9') {
429 for (uint32_t i=1; i<length; i++) {
430 if (action[i]<
'0' || action[i]>
'9') {
437 uint32_t value = strtol(&action[0], NULL, 10);
438 for (uint32_t i=0; i<repetition; i++) {
441 }
else if (length>=2 && (
'"'==action[0] ||
'\''==action[0]) && (action[length-1]==action[0])) {
445 for (uint32_t r=0; r<repetition; r++) {
446 for (uint32_t i=1; i<length-1; i++) {
464 if (NULL==argument || 0==strlen(argument)) {
465 printf(
"available actions (separated by space or ,):\n");
466 printf(
"0\twrite decimal value\n");
467 printf(
"0x0\twrite hexadecimal value\n");
468 printf(
"0b0\twrite binary value\n");
469 printf(
"\"a\"/'a'\twrite ASCII characters\n");
470 printf(
"r\tread value\n");
471 printf(
"u/m\twait 1 us/ms\n");
472 printf(
":n\trepeat action n times\n");
477 char* copy = calloc(strlen(argument)+1,
sizeof(
char));
481 strncpy(copy, argument, strlen(argument)+1);
484 printf(
"malformed action(s)\n");
486 printf(
"press any key to exit\n");
500 if (NULL==argument || 0==strlen(argument)) {
503 printf(
"press any key to exit\n");
507 printf(
"%c", ((
char*)(argument))[i]);
515 if (strcmp(argument,
"\r\n")) {
525 bool display_hex =
false;
526 bool display_bin =
false;
527 if (NULL!=argument && strlen(argument)>0) {
528 if (0==strcmp(argument,
"h") || 0==strcmp(argument,
"hex")) {
530 }
else if (0==strcmp(argument,
"b") || 0==strcmp(argument,
"bin")) {
533 printf(
"malformed argument\n");
537 printf(
"press any key to exit\n");
562 }
else if (display_bin) {
591 printf(
"press 5 times escape to exit\n");
593 uint8_t esc_count = 0;
629 printf(
"press any key to exit\n");
641 "perform protocol actions",
649 "show incoming data [in hexadecimal or binary]",
657 "transmit ASCII text (empty for CR+LF)",
665 "transmit and receive data",
673 "verify incoming transmission for errors",
682 "Universal Asynchronous Receiver-Transmitter",
#define USART_TX_PORT(x)
get port for USART transmit pin based on USART identifier
#define RCC_USART(x)
get RCC for USART based on USART identifier
#define BUSVOODOO_LED_PULSE
recommended duration in ms for pulsing LEDs to show activity
#define BUSVOODOO_USART_ID
USART peripheral.
BusVoodoo global definitions and methods (API)
void busvoodoo_oled_text_pinout(const char *pins[10], bool io_connector)
draw pin names on bottom (blue) part in display buffer
void busvoodoo_led_red_pulse(uint16_t ms)
pulse red LED for short duration
static bool busvoodoo_uart_pullup
if embedded pull-up resistors are used
static void busvoodoo_uart_command_actions(void *argument)
command to perform actions
void led_off(void)
switch off board LED
#define RCC_USART_PORT(x)
get RCC for USART port based on USART identifier
void busvoodoo_oled_update(void)
update OLED display RAM with current display buffer
static void busvoodoo_uart_command_transmit(void *argument)
command to transmit a string
global definitions and methods (API)
void busvoodoo_led_blue_pulse(uint16_t ms)
pulse blue LED for short duration
void sleep_us(uint32_t duration)
go to sleep for some microseconds
static bool busvoodoo_uart_setup(char **prefix, const char *line)
setup UART mode
#define USART_RX_PIN(x)
get pin for USART receive pin based on USART identifier
#define USART_TX_PIN(x)
get pin for USART transmit pin based on USART identifier
#define USART_CTS_PORT(x)
get port for USART CTS pin based on USART identifier
#define USART(x)
get USART based on USART identifier
static const struct menu_command_t busvoodoo_uart_commands[]
UART menu commands.
static uint32_t busvoodoo_uart_parity
UART parity setting.
static enum busvoodoo_uart_setting_t busvoodoo_uart_setting
current mode setup stage
static bool busvoodoo_uart_hwflowctl
UART hardware flow control setting (true = with hardware flow control, false = without hardware flow ...
static void busvoodoo_uart_command_transceive(void *argument)
command to transmit and receive data
static bool busvoodoo_uart_action(const char *action, uint32_t repetition, bool perform)
perform UART action
const char * busvoodoo_global_pinout_io[10]
I/O connector pinout.
BusVoodoo UART mode (API)
char user_input_get(void)
get user input
char busvoodoo_global_string[64]
shared string buffer, i.e.
struct busvoodoo_mode_t busvoodoo_uart_mode
UART mode interface definition.
size_t snprintf(char *str, size_t size, const char *format,...)
print format string on string or user output
static uint32_t busvoodoo_uart_stopbits
UART stop bits setting.
bool busvoodoo_global_actions(char *actions, bool perform, bool(*action_handler)(const char *action, uint32_t repetition, bool perform))
parse and perform actions
void sleep_ms(uint32_t duration)
go to sleep for some milliseconds
#define USART_RX_PORT(x)
get port for USART receive pin based on USART identifier
#define USART_RTS_PIN(x)
get pin for USART RTS pin based on USART identifier
size_t printf(const char *format,...)
print format string on user output
static void busvoodoo_uart_write(uint16_t value)
write to UART
#define USART_CTS_PIN(x)
get pin for USART CTS pin based on USART identifier
static void busvoodoo_uart_command_error(void *argument)
command to verify incoming transmission for error
static bool busvoodoo_uart_drive
pin drive mode (true = push-pull, false = open-drain)
printing utilities to replace the large printf from the standard library (API)
void busvoodoo_oled_text_left(char *text)
draw mode text on top (yellow) left side in display buffer
float busvoodoo_embedded_pullup(bool on)
enable embedded pull-up resistors
#define LENGTH(x)
get the length of an array
static void busvoodoo_uart_command_receive(void *argument)
command to receive data
static uint8_t busvoodoo_uart_databits
UART data bits.
library to show BusVoodoo mode information on SSD1306 OLED display: name, activity, pinout (API)
volatile bool user_input_available
flag set when user input is available
static void busvoodoo_uart_exit(void)
exit UART mode
BusVoodoo mode interface.
#define USART_RTS_PORT(x)
get port for USART RTS pin based on USART identifier
static uint32_t busvoodoo_uart_baudrate
UART baud rate (in bps)
static void busvoodoo_uart_read(void)
read from UART