[ECOS] EB40A (AT91) serial port oddness

Tom Lynn tom.lynn@hypertag.com
Thu Sep 30 06:53:00 GMT 2004

I'm getting some weird behaviour on an EB40A (AT91) serial port.
With the code below, which just tries to emit the 65 byte string
I'm reading bytes such as:


The AEIMQUY suggests jumps of 4, and the intermittent almost-
correct output (the 'A' is always missing) together make me think
that it's the debugging connection (running at 38400, i.e. 9600*4)
that's causing the problem.  I've played with all the switches I
can find and can't turn the damn thing off though.  Any ideas?

(Email me if you want to look at the config file I'm using.)


// test_serial.cpp

#include <pkgconf/system.h>
#include <cyg/infra/testcase.h> // test macros
#include <cyg/infra/cyg_ass.h>  // assertion macros
#include <pkgconf/kernel.h>
#include <cyg/kernel/kapi.h>
#include <cyg/io/io.h>
#include <cyg/io/serialio.h> // not to be confused with seraglio, which 
is more fun.
#include <pkgconf/io_serial.h> // yes, there really are io_serial.h and 
#include <cyg/io/config_keys.h> // magic values for prodding at io functions
#include <cyg/infra/diag.h>     // Defines diag_printf, for diagnostic 
#include <cyg/hal/hal_arch.h> // for CYGNUM_HAL_STACK_SIZE_TYPICAL

extern "C"
void  serialtest_main()
    cyg_io_handle_t  handle;
    cyg_io_lookup( "/dev/ser1", &handle ); // ignoring errors
    // Set serial port parameters to 9600-8-N-1
        cyg_serial_info_t  new_cfg;
        unsigned int len = sizeof(new_cfg);
        cyg_io_get_config( handle, CYG_IO_GET_CONFIG_SERIAL_INFO,
                           &new_cfg, &len );

        new_cfg.baud        = CYGNUM_SERIAL_BAUD_9600;
        new_cfg.word_length = CYGNUM_SERIAL_WORD_LENGTH_8;
        new_cfg.stop        = CYGNUM_SERIAL_STOP_1;
        new_cfg.parity      = CYGNUM_SERIAL_PARITY_NONE;
        new_cfg.flags       = CYGNUM_SERIAL_FLOW_NONE;
        cyg_io_set_config( handle, CYG_IO_SET_CONFIG_SERIAL_INFO,
                           &new_cfg, &len );
    while( 1 )
        const unsigned char testdata[] = 
        unsigned int sz = 65;
        cyg_io_write( handle, testdata, &sz );

// --- entrypoint boilerplate from here ---

static  unsigned char  stack[CYGNUM_HAL_STACK_SIZE_TYPICAL];
static  cyg_thread     thread_data;
static  cyg_handle_t   thread_handle;

extern "C"
void cyg_start()
    cyg_thread_create( 10, (cyg_thread_entry_t*)serialtest_main,
        0, "serialtest", &stack[0], CYGNUM_HAL_STACK_SIZE_TYPICAL,
        &thread_handle, &thread_data );

Tom Lynn, Software Engineer, Hypertag Ltd.
William Gates Building, JJ Thomson Avenue, Cambridge CB3 0FD

Tel: 01223 763710   Fax: 08714 335288   Web: www.hypertag.com

Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

More information about the Ecos-discuss mailing list