[En-Nut-Discussion] Problem with stdin on DBGU
Bernd Walter
enut at cicely.de
Fri Jun 4 20:05:21 CEST 2010
On Fri, Jun 04, 2010 at 07:58:51PM +0200, Bernd Walter wrote:
> On Fri, Jun 04, 2010 at 06:43:54PM +0200, Bernd Walter wrote:
> > 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.
>
> Oh - I've just notice in debug_at91.c that there really is no read
> function.
> That's very unexpected for me :-(
> Is there any special reason for this?
> I know that is hasn't some of the very special features that USART
> have and that it shares an interrupt, but otherwise it is very similar
> to USART.
> The reason I want to use this interface is that I already have a
> usecase for the USART and that the DBGU is already wired for flashing
> via SAM-BA.
>
> I also noticed devDbguAt91 - ist useable?
> There is a #define NUT_DEPRECATED at start - sounds not.
It compiles and work :-)
The NUT_DEPRECATED still irritates me though.
--
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