This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Serial Port on the Beagle Bone Black using SYS/BIOS

Hi Forum,

I am new to SYS/BIOS and trying to learn how to use it.  I have CCS5.5 and SYS/BIOS 6.35.04.50 and a Beagle Bone Black (Revision A5B) with JTAG connector and TI XDS100c2 usb emulator. 

I have the FTDI 3.3 TTL cable connected to the onboard serial port pins. 

I have successfully compiled the hello world example from CCS and run it on the BBB in debug.

On the serial port I constantly see uppercase C being echoed.

I wish to learn to use SYS/BIOS and configure the on board serial port so I can use the serial for both input and output.

I have looked at the SYS/BIOS website but able to determine how to do it.

Are there any examples of using SYS/BIOS to configure the serial port? 

Thanks


Joshua

  • Hi Forum,

    Following from my earlier question I have managed to setup UART0 so I can print single characters to the serial port. 

    I am now trying to use a HWI on UART0 so I can echo typed data back to the serial port.

    In the attached example I have tried to create a HWI for UART0 to be triggered each time a character is type (or printed I would assume) but I cannot get the HWI to trigger.

    I have tried both using XCONF and inline code (as in example) to get the HWI to work.

    Could someone give me a pointer as to what I have done incorrectly?  This is my first sys/bios project  so any guidance would most appreciated.

    Thanks

    Joshua

    XCONFG File

    var Defaults = xdc.useModule('xdc.runtime.Defaults');
    var Diags = xdc.useModule('xdc.runtime.Diags');
    var Error = xdc.useModule('xdc.runtime.Error');
    var Log = xdc.useModule('xdc.runtime.Log');
    var LoggerBuf = xdc.useModule('xdc.runtime.LoggerBuf');
    var Main = xdc.useModule('xdc.runtime.Main');
    var Memory = xdc.useModule('xdc.runtime.Memory')
    var SysMin = xdc.useModule('xdc.runtime.SysMin');
    var System = xdc.useModule('xdc.runtime.System');
    var Text = xdc.useModule('xdc.runtime.Text');
    
    var BIOS = xdc.useModule('ti.sysbios.BIOS');
    var Swi = xdc.useModule('ti.sysbios.knl.Swi');
    var Clock = xdc.useModule('ti.sysbios.knl.Clock');
    var Task = xdc.useModule('ti.sysbios.knl.Task');
    var Semaphore = xdc.useModule('ti.sysbios.knl.Semaphore');
    var Hwi = xdc.useModule('ti.sysbios.hal.Hwi');
    var HeapMem = xdc.useModule('ti.sysbios.heaps.HeapMem');
    
    /* 
     * Program.argSize sets the size of the .args section. 
     * The examples don't use command line args so argSize is set to 0.
     */
    Program.argSize = 0x0;
    
    /*
     * Uncomment this line to globally disable Asserts.
     * All modules inherit the default from the 'Defaults' module.  You
     * can override these defaults on a per-module basis using Module.common$. 
     * Disabling Asserts will save code space and improve runtime performance.
    Defaults.common$.diags_ASSERT = Diags.ALWAYS_OFF;
     */
    
    /*
     * Uncomment this line to keep module names from being loaded on the target.
     * The module name strings are placed in the .const section. Setting this
     * parameter to false will save space in the .const section.  Error and
     * Assert messages will contain an "unknown module" prefix instead
     * of the actual module name.
    Defaults.common$.namedModule = false;
     */
    
    /*
     * Minimize exit handler array in System.  The System module includes
     * an array of functions that are registered with System_atexit() to be
     * called by System_exit().
     */
    System.maxAtexitHandlers = 4;       
    
    /* 
     * Uncomment this line to disable the Error print function.  
     * We lose error information when this is disabled since the errors are
     * not printed.  Disabling the raiseHook will save some code space if
     * your app is not using System_printf() since the Error_print() function
     * calls System_printf().
    Error.raiseHook = null;
     */
    
    /* 
     * Uncomment this line to keep Error, Assert, and Log strings from being
     * loaded on the target.  These strings are placed in the .const section.
     * Setting this parameter to false will save space in the .const section.
     * Error, Assert and Log message will print raw ids and args instead of
     * a formatted message.
    Text.isLoaded = false;
     */
    
    /*
     * Uncomment this line to disable the output of characters by SysMin
     * when the program exits.  SysMin writes characters to a circular buffer.
     * This buffer can be viewed using the SysMin Output view in ROV.
    SysMin.flushAtExit = false;
     */
    
    /*
     * The BIOS module will create the default heap for the system.
     * Specify the size of this default heap.
     */
    BIOS.heapSize = 0x2000;
    
    /*
     * Build a custom SYS/BIOS library from sources.
     */
    BIOS.libType = BIOS.LibType_Custom;
    
    /* System stack size (used by ISRs and Swis) */
    Program.stack = 0x1000;
    
    /* Circular buffer size for System_printf() */
    SysMin.bufSize = 0x400;
    
    /* 
     * Create and install logger for the whole system
     */
    var loggerBufParams = new LoggerBuf.Params();
    loggerBufParams.numEntries = 32;
    var logger0 = LoggerBuf.create(loggerBufParams);
    Defaults.common$.logger = logger0;
    Main.common$.diags_INFO = Diags.ALWAYS_ON;
    
    System.SupportProxy = SysMin;
    var Cache = xdc.useModule('ti.sysbios.family.arm.a8.Cache');
    var Mmu = xdc.useModule('ti.sysbios.family.arm.a8.Mmu');
    
    // Enable the cache
    Cache.enableCache = true;
    
    // Enable the MMU (Required for L1/L2 data caching)
    Mmu.enableMMU = true;
    
    // Force peripheral section to be NON cacheable
    var peripheralAttrs = {
        type : Mmu.FirstLevelDesc_SECTION, // SECTION descriptor
        bufferable : false, // bufferable
        cacheable : false, // cacheable
        shareable : false, // shareable
        noexecute : true, // not executable
    };
    
    // Define the base address of the 1 Meg page
    // the peripheral resides in.
    var peripheralBaseAddr = 0x44e00000;
    
    // Configure the corresponding MMU page descriptor accordingly
    Mmu.setFirstLevelDescMeta(peripheralBaseAddr, peripheralBaseAddr, peripheralAttrs);

    Source Code

    #include <xdc/std.h>
    #include <xdc/runtime/System.h>
    #include <xdc/runtime/Error.h>
    
    #include <ti/sysbios/BIOS.h>
    #include <ti/sysbios/knl/Task.h>
    #include <ti/sysbios/family/arm/a8/intcps/Hwi.h>
    
    #include "soc_AM335x.h"
    #include "uart_irda_cir.h"
    #include "interrupt.h"
    #include "hw_cm_wkup.h"
    #include "hw_types.h"
    #include "hw_control_AM335x.h"
    
    void UARTInit();
    Bool UartOpen();
    void UARTPutChar(Char txChar);
    signed char UARTGetChar();
    Void UartClose();
    
    Hwi_Handle uart0HwiHandle = NULL;
    
    Void UART0Isr(UArg arg) {
        unsigned int i = 0;
    }
    
    #define BAUD_RATE_115200          (115200)
    #define UART_MODULE_INPUT_CLK     (48000000)
    
    void UARTInit() {
    
    	/* Wakeup UART0 */
    	HWREG(SOC_CM_WKUP_REGS + CM_WKUP_UART0_CLKCTRL) |= CM_WKUP_UART0_CLKCTRL_MODULEMODE_ENABLE;
    
    	while (CM_WKUP_UART0_CLKCTRL_MODULEMODE_ENABLE !=
    	   (HWREG(SOC_CM_WKUP_REGS + CM_WKUP_UART0_CLKCTRL) &
    		CM_WKUP_UART0_CLKCTRL_MODULEMODE));
    
    	while (CM_WKUP_CLKSTCTRL_CLKACTIVITY_UART0_GFCLK !=
    	   (HWREG(SOC_CM_WKUP_REGS + CM_WKUP_CLKSTCTRL) &
    		CM_WKUP_CLKSTCTRL_CLKACTIVITY_UART0_GFCLK));
    
    	while ((CM_WKUP_UART0_CLKCTRL_IDLEST_FUNC << CM_WKUP_UART0_CLKCTRL_IDLEST_SHIFT) !=
    	   (HWREG(SOC_CM_WKUP_REGS + CM_WKUP_UART0_CLKCTRL) &
    		CM_WKUP_UART0_CLKCTRL_IDLEST));
    
    	/* Pinumx */
    	HWREG(SOC_CONTROL_REGS + CONTROL_CONF_UART_RXD(0)) = CONTROL_CONF_UART0_RXD_CONF_UART0_RXD_PUTYPESEL | CONTROL_CONF_UART0_RXD_CONF_UART0_RXD_RXACTIVE;
    	HWREG(SOC_CONTROL_REGS + CONTROL_CONF_UART_TXD(0)) = CONTROL_CONF_UART0_TXD_CONF_UART0_TXD_PUTYPESEL;
    	HWREG(SOC_UART_0_REGS + UART_SYSC) |= (UART_SYSC_SOFTRESET);
    	while (!(HWREG(SOC_UART_0_REGS + UART_SYSS) & UART_SYSS_RESETDONE));
    
        /* Perform a module reset. */
        UARTModuleReset(SOC_UART_0_REGS);
    
        /* Perform FIFO configurations. */
        UARTFIFOConfig(SOC_UART_0_REGS,
    				   UART_FIFO_CONFIG(UART_TRIG_LVL_GRANULARITY_1,
    								UART_TRIG_LVL_GRANULARITY_1, 1, 1, 1, 1,
    								UART_DMA_EN_PATH_SCR,
    								UART_DMA_MODE_0_ENABLE));
    
        /* Switch to Configuration Mode B. */
        UARTRegConfigModeEnable(SOC_UART_0_REGS, UART_REG_CONFIG_MODE_B);
    
        /* Computing the Divisor Value. */
    	unsigned int divisor = UARTDivisorValCompute(UART_MODULE_INPUT_CLK,
    												 BAUD_RATE_115200,
    												 UART16x_OPER_MODE,
    												 UART_MIR_OVERSAMPLING_RATE_42);
    	/* Divisor Latches. */
    	UARTDivisorLatchWrite(SOC_UART_0_REGS, divisor);
    
    	/* Line Characteristics. */
    	UARTLineCharacConfig(SOC_UART_0_REGS,
    						 (UART_FRAME_WORD_LENGTH_8 | UART_FRAME_NUM_STB_1),
    						 UART_PARITY_NONE);
    
        /* Disable write access to Divisor Latches. */
        UARTDivisorLatchDisable(SOC_UART_0_REGS);
    
        /* Disable Break Control. */
        UARTBreakCtl(SOC_UART_0_REGS, UART_BREAK_COND_DISABLE);
    
        /* Switch to UART16x operating mode. */
        UARTOperatingModeSelect(SOC_UART_0_REGS, UART16x_OPER_MODE);
    }
    
    Bool UartOpen() {
        Hwi_Params hwiParams;
        Error_Block eb;
        int intNum;
    
    	if(uart0HwiHandle !=NULL)
    		return FALSE;
    
    	UARTInit();
    
        Hwi_Params_init(&hwiParams);
        Error_init(&eb);
    
        hwiParams.arg = 1;
        hwiParams.priority = 20;
        intNum = 72; //UART0Int
        uart0HwiHandle  = Hwi_create(intNum , UART0Isr , &hwiParams, &eb);
        if (Error_check(&eb)) {
        	uart0HwiHandle = NULL;
        	return FALSE;
        }
        Hwi_enableInterrupt(intNum);
    	return TRUE;
    }
    
    void UARTPutChar(Char txChar) {
    	UARTCharPut(SOC_UART_0_REGS, txChar);
    }
    
    signed char UARTGetChar() {
    	return (UARTCharGet(SOC_UART_0_REGS));
    }
    
    int main(int argc, char **argv ) {
    
    
        if (UartOpen()) {
        	UARTPutChar('B');
    	UARTPutChar('B');
    	UARTPutChar('B');
    	UARTPutChar('\r');
    	UARTPutChar('\n');
        }
        BIOS_start();
    }
    

  • Nothing jumps out, but I need to look at the set-up code more closely. Just to confirm: you see the "BBB\r\n" come out...correct?

    I'm assuming you let the program run and try to echo what is being sent from the terminal app within the Hwi. Which terminal app are you using (e.g. puTTY, TeraTerm, etc.)?

    Can you stop the program and look at Tools->ROV. Look at the BIOS tab. I'd like to know what it shows. You can look at the Hwi tab also to see the state of the Hwi.

    Todd

  • Todd,

    Yes I see the BBB\r\n on the serial console.   Before I start my program I see capital C being echoed on the serial console.cable after pressing the S2 switch on power up.

     I am using puTTY and FTDI 3.3 TTL USB 

    I have paused the program and I see the following under BIOS and HWI tabs the following. 

     I started with the BBB hello example from CCS5 and added to that.

    Joshua

  • Hi Forum

    I am still trying to get this to work.  Is there anything else to look at?  Any suggestions?

    Thanks

    Joshua

  • Hi Joshua


    Did you ever get this to work?

    I am trying something similar and facing the exact same issue and not sure where to go from here.

    Cheers

    Norris