[En-Nut-Discussion] Problem with stdin on DBGU

Bernd Walter enut at cicely.de
Fri Jun 4 18:43:54 CEST 2010


Controller is AT91SAM7S321
Nut/OS is 4.9.8.

My main function starts with:
        // Initialize the console
        uint32_t cons_baud = 115200;
        NutRegisterDevice(&DEV_CONS, 0, 0);
        freopen(DEV_CONS_NAME, "w", stdout);
        if (freopen(DEV_CONS_NAME, "w", stderr) == NULL) {
                printf("open stderr failed\n");
        }
        if (freopen(DEV_CONS_NAME, "r", stdin) == NULL) {
                printf("open stdin failed\n");
        }
        _ioctl(_fileno(stdin), UART_SETSPEED, &cons_baud);

With:
#define DEV_CONS        devDebug
#define DEV_CONS_NAME   "dbgu"

Then after many successfull printf I have the following code:
        for(;;) {
                char *cp;
                static char buf[128];
                buf[0] = '\0';
                printf("ready!\n");
                fflush(stdout);
                NutThreadYield();
                if (fgets(buf, sizeof(buf), stdin) == 0) {
                        printf("<EOF>\n");
                        fflush(stdout);
                        NutThreadYield();
                        continue;
                }
                printf("<got something>\n");
                fflush(stdout);
                NutThreadYield();
                if ((cp = strchr(buf, '\r')) != 0) {
                        *cp = 0;
                }
                if ((cp = strchr(buf, '\n')) != 0) {
                        *cp = 0;
                }
                if (buf[0] == 0) {
                        continue;
                }

                if (strncmp(buf, "memory", strlen(buf)) == 0) {
                        printf("%u bytes RAM free\r\n", (u_int)NutHeapAvailable());
                        continue;
                }

                printf("List of commands follows\n");
                printf("memory\tQueries number of RAM bytes free\n");
        }

With fgets the system just restarts.
I've debugged it up to _read and it turned out that dev->dev_read is
NULL.
Not surprising that calling code at address 0 restarts the system.

-- 
B.Walter <bernd at bwct.de> http://www.bwct.de
Modbus/TCP Ethernet I/O Baugruppen, ARM basierte FreeBSD Rechner uvm.



More information about the En-Nut-Discussion mailing list