Tool/software: TI-RTOS
I'm struggling to debug an application using the UART. It would appear that UART_write does not seem to flush.
I've taken the uartecho.c example and added a PIN callback where I print the id:
/* * ======== uartecho.c ======== */ #include <stdint.h> #include <stddef.h> #include <stdio.h> #include <string.h> #include <stdlib.h> /* Driver Header files */ #include <ti/drivers/GPIO.h> #include <ti/drivers/UART.h> /* Example/Board Header files */ #include "Board.h" PIN_Config pinTable[] = { Board_PIN_BUTTON0 | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLUP, Board_PIN_BUTTON1 | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLUP, PIN_TERMINATE }; static UART_Handle uart; void UART_writeint(int val, int base) { #if 0 // sprintf causes hangs... why? char str[16]; if (base == 10) sprintf(str, "%d", val); else sprintf(str, "%x", val); UART_write(uart, str, strlen(str)); #else char buf[32]; char ascii[] = "0123456789abcdef"; char *p = &buf[sizeof(buf)-1]; int i = val; *p = 0; if (i >= 0) { i = -i; } do { p--; *p = ascii[abs(i) % base]; i /= base; } while (i && p > buf); if (val < 0 && p > buf) { p--; *p = '-'; } UART_write(uart, p, (int)(&buf[sizeof(buf)] - p) - 1); #endif } static int count=0; static void Board_keyCallback(PIN_Handle hPin, PIN_Id pinId) { UART_write(uart, "key:", 4); UART_writeint(count++, 16); UART_write(uart, "\r\n", 2); } /* * ======== mainThread ======== */ void *mainThread(void *arg0) { char input; const char echoPrompt[] = "Echoing characters:\r\n"; UART_Params uartParams; PIN_State pinState; PIN_Handle pinHandle; /* Configure Button pins and callback */ pinHandle = PIN_open(&pinState, pinTable); PIN_registerIntCb(pinHandle, Board_keyCallback); PIN_setConfig(pinHandle, PIN_BM_IRQ, Board_PIN_BUTTON0 | PIN_IRQ_NEGEDGE); PIN_setConfig(pinHandle, PIN_BM_IRQ, Board_PIN_BUTTON1 | PIN_IRQ_NEGEDGE); /* Call driver init functions */ GPIO_init(); UART_init(); /* Configure the LED pin */ GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW); /* Turn on user LED */ GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON); /* Create a UART with data processing off. */ UART_Params_init(&uartParams); uartParams.writeDataMode = UART_DATA_BINARY; uartParams.readDataMode = UART_DATA_BINARY; uartParams.readReturnMode = UART_RETURN_FULL; uartParams.readEcho = UART_ECHO_OFF; uartParams.baudRate = 115200; uart = UART_open(Board_UART0, &uartParams); if (uart == NULL) { /* UART_open() failed */ while (1); } UART_write(uart, echoPrompt, sizeof(echoPrompt)); /* Loop forever echoing */ while (1) { UART_read(uart, &input, 1); UART_write(uart, &input, 1); } }
When run and BTN1 changes state I see 'key:' and nothing else. The two UART_write's following that never send any characters. This would appear to only occur within a callback... what's going on here?
Additionally as my code states if I use 'sprintf' the app appears to crash.
Ultimately I would like to be able to make System_printf() go over the UART... is there a simple way to do that?
Thanks,
Tim