Other Parts Discussed in Thread: EK-TM4C123GXL, SYSBIOS, CONTROLSUITE
Hi all, first post and just getting started with tiva c and TI rtos.
used tools:
- TI-RTOS TivaC 2.16.01.14
- gnu v4.8.4 linaro
- CCS 6.1.2.00015
I can't help but notice that the uartconsole example is missing from the gnu demos (which is probably due to the way `add_device` works), so I tried making my own using the gnu extension `fopencookie` (of which at least the symbol seems to be present).
So far, however, my code seems to hang after calling `fprintf`.
Steps to reproduce:
- Open a new project and use TI-RTOS Examples->EK-TM4C123GXL evaluation kit->driver examples->gnu driver examples->empty examples-> empty (minimal project)
Notes:
- I'm testing with a serial monitor on my PC. `UART_write` on its own works fine.
- breakpoints at the callbacks don't ever get called.
- Even when the `cookie_io_functions_t` simply return the requested number (`return n`), the program terminates
- The led blink code from the minimal example is still present and runs in the same loop (fine using `UART_write`)
Any help would greatly be appreciated. (either pointing out the flaw in my current setup, or directing me to a better way to implement a uart console with the gnu toolchain.)
The debugger console displays the following:
FSR = 0x0000 HFSR = 0x40000000 DFSR = 0x0000000b MMAR = 0xffffffd4 BFAR = 0xffffffd4 AFSR = 0x00000000 Terminating execution...
I'm using the following code:
/*
* ======== empty_min.c ========
*/
/* XDCtools Header files */
#include <xdc/std.h>
/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
/* TI-RTOS Header files */
#include <ti/drivers/GPIO.h>
#include <ti/drivers/UART.h>
//c header files
#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/* Board Header file */
#include "Board.h"
#define TASKSTACKSIZE 512
Task_Struct task0Struct;
Char task0Stack[TASKSTACKSIZE];
int noop(void) { return -1; }
size_t uartReadFx(void *cookie, char *buf, size_t n)
{
return n;
//return UART_read((UART_Handle)cookie, buf, n);
}
size_t uartWriteFx(void *cookie, const char *buf, size_t n)
{
return n;
//return UART_write((UART_Handle)cookie, buf, n);
}
cookie_io_functions_t uartcookievect =
{
(cookie_read_function_t*)&uartReadFx,
(cookie_write_function_t*)&uartWriteFx,
(cookie_seek_function_t*)&noop,
(cookie_close_function_t*)&noop
};
UART_Handle uart_handle;
UART_Params uartParams;
FILE* uartcookief;
/*
* ======== heartBeatFxn ========
* Toggle the Board_LED0. The Task_sleep is determined by arg0 which
* is configured for the heartBeat Task instance.
*/
Void heartBeatFxn(UArg arg0, UArg arg1)
{
while (1) {
Task_sleep((UInt)arg0);
GPIO_toggle(Board_LED0);
char s[] = "hii\n";
//UART_write(uart_handle, s, strlen(s));
fprintf(uartcookief, s);
fflush(uartcookief);
}
}
/*
* ======== main ========
*/
int main(void)
{
Task_Params taskParams;
/* Call board init functions */
Board_initGeneral();
Board_initGPIO();
Board_initUART();
Task_Params_init(&taskParams);
taskParams.arg0 = 1000;
taskParams.stackSize = TASKSTACKSIZE;
taskParams.stack = &task0Stack;
Task_construct(&task0Struct, (Task_FuncPtr)heartBeatFxn, &taskParams, NULL);
//setup uart io
UART_Params_init(&uartParams);
uartParams.baudRate = 115200;
uartParams.readEcho = UART_ECHO_OFF;
uart_handle = UART_open(Board_UART0, &uartParams);
uartcookief = fopencookie((void*) uart_handle, "w+", uartcookievect);
setlinebuf(uartcookief);
//setvbuf(uartcookief, NULL, _IOLBF, 128);
/* Turn on user LED */
GPIO_write(Board_LED0, Board_LED_ON);
/* Start BIOS */
BIOS_start();
return (0);
}