static void uarts_init() { unsigned i; for( i = 0; i < NUM_UART; i ++ ) MAP_SysCtlPeripheralEnable(uart_sysctl[ i ]); // Special case for UART 0 // Configure the UART for 115,200, 8-N-1 operation. MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); MAP_UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), CON_UART_SPEED, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); #if defined( BUF_ENABLE_UART ) && defined( CON_BUF_SIZE ) // Enable buffering on the console UART buf_set( BUF_ID_UART, CON_UART_ID, CON_BUF_SIZE, BUF_DSIZE_U8 ); // Set interrupt handler and interrupt flag on UART IntEnable(INT_UART0); MAP_UARTIntEnable( uart_base[ CON_UART_ID ], UART_INT_RX | UART_INT_RT ); #endif }
/** * Hardware setup * Initializes pins, clocks, etc */ void HAL_setup(void){/*{{{*/ //Configure clock to run at 120MHz //configCPU_CLOCK_HZ = 120MHz //Needs to be set for FreeRTOS g_syshz = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000L); MAP_SysCtlMOSCConfigSet(SYSCTL_MOSC_HIGHFREQ); //Enable all GPIOs MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOP); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOQ); init_ethernet(); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); //Configure reset pin for XBD MAP_GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, RESET_PIN); //Reset XBD xbd_reset(true); //Configure UART MAP_GPIOPinConfigure(GPIO_PA0_U0RX); MAP_GPIOPinConfigure(GPIO_PA1_U0TX); MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); MAP_UARTConfigSetExpClk(UART0_BASE, g_syshz, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); // //Configure measurement stuff measure_setup(); //Configure xbd i2c comm i2c_comm_setup(); //Setup watchdog watchdog_setup(); //Unreset XBD xbd_reset(false); }/*}}}*/
u32 platform_uart_setup( unsigned id, u32 baud, int databits, int parity, int stopbits ) { u32 config; MAP_GPIOPinTypeUART(uart_gpio_base [ id ], uart_gpio_pins[ id ]); switch( databits ) { case 5: config = UART_CONFIG_WLEN_5; break; case 6: config = UART_CONFIG_WLEN_6; break; case 7: config = UART_CONFIG_WLEN_7; break; default: config = UART_CONFIG_WLEN_8; break; } config |= ( stopbits == PLATFORM_UART_STOPBITS_1 ) ? UART_CONFIG_STOP_ONE : UART_CONFIG_STOP_TWO; if( parity == PLATFORM_UART_PARITY_EVEN ) config |= UART_CONFIG_PAR_EVEN; else if( parity == PLATFORM_UART_PARITY_ODD ) config |= UART_CONFIG_PAR_ODD; else config |= UART_CONFIG_PAR_NONE; MAP_UARTConfigSetExpClk( uart_base[ id ], MAP_SysCtlClockGet(), baud, config ); MAP_UARTConfigGetExpClk( uart_base[ id ], MAP_SysCtlClockGet(), &baud, &config ); return baud; }
void rt_hw_console_init(void) { struct rt_lm3s_serial* serial; serial = &serial1; serial->parent.type = RT_Device_Class_Char; serial->hw_base = UART0_BASE; serial->baudrate = 115200; rt_memset(serial->rx_buffer, 0, sizeof(serial->rx_buffer)); serial->read_index = serial->save_index = 0; /* enable UART0 clock */ MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); /* set UART0 pinmux */ MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); /* Configure the UART for 115,200, 8-N-1 operation. */ MAP_UARTConfigSetExpClk(UART0_BASE, MAP_SysCtlClockGet(), serial->baudrate, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); serial->parent.init = rt_serial_init; serial->parent.open = rt_serial_open; serial->parent.close = rt_serial_close; serial->parent.read = rt_serial_read; serial->parent.write = rt_serial_write; serial->parent.control = rt_serial_control; serial->parent.user_data= RT_NULL; rt_device_register(&serial->parent, "uart1", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM); }
// Serial virtual void SerialBegin(int serialDevice, int baudrate) { if (serialDevice == 0) { MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); MAP_GPIOPinConfigure(GPIO_PA0_U0RX); MAP_GPIOPinConfigure(GPIO_PA1_U0TX); MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTStdioInit(0); UARTEnable(UART0_BASE); } }
static void uart_init(void) { MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // Configure PD0 and PD1 for UART MAP_GPIOPinConfigure(GPIO_PA0_U0RX); MAP_GPIOPinConfigure(GPIO_PA1_U0TX); MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); /*UARTConfigSetExpClk(UART1_BASE, SysCtlClockGet(), 115200, UART_CONFIG_WLEN_8| UART_CONFIG_STOP_ONE| UART_CONFIG_PAR_NONE);*/ UARTStdioInitExpClk(0, 115200); }
void configureUART(){ MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // // Set GPIO A0 and A1 as UART pins. // MAP_GPIOPinConfigure(GPIO_PA0_U0RX); MAP_GPIOPinConfigure(GPIO_PA1_U0TX); MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTStdioConfig(0,115200,MAP_SysCtlClockGet()); }
//***************************************************************************** // //! Configures the device pins for the customer specific usage. //! //! \return None. // //***************************************************************************** void PinoutSet(void) { // // Enable Peripheral Clocks // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // // Configure the GPIO Pin Mux for PA0 // for U0RX // MAP_GPIOPinConfigure(GPIO_PA0_U0RX); MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0); // // Configure the GPIO Pin Mux for PA1 // for U0TX // MAP_GPIOPinConfigure(GPIO_PA1_U0TX); MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_1); }
void ConfigUART(uint32_t baud) { // Enable the GPIO Peripheral used by the UART. MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // Enable UART0 MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); // Configure GPIO Pins for UART mode. MAP_GPIOPinConfigure(GPIO_PA0_U0RX); MAP_GPIOPinConfigure(GPIO_PA1_U0TX); MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // Use the internal 16MHz oscillator as the UART clock source. UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC); UARTStdioConfig(0, baud, 16000000); }
void GPS_init() { dbg_printf("Initializing GPS module..."); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART); MAP_GPIOPinConfigure(GPIO_PA0_U0RX); MAP_GPIOPinConfigure(GPIO_PA1_U0TX); MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); MAP_UARTConfigSetExpClk(UART_BASE, MAP_SysCtlClockGet(), UART_SPEED, UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE); MAP_UARTDisable(UART_BASE); MAP_UARTTxIntModeSet(UART_BASE, UART_TXINT_MODE_EOT); MAP_UARTIntEnable(UART_BASE, UART_INT_RX | UART_INT_TX); MAP_IntEnable(INT_UART); MAP_UARTEnable(UART_BASE); MAP_UARTFIFODisable(UART_BASE); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); // MAP_IntEnable(INT_GPIOG); // Настроить прерывания на PPS MAP_GPIOIntTypeSet(GPIO_PORTG_BASE, GPIO_PIN_7, GPIO_FALLING_EDGE); MAP_GPIOPinIntEnable(GPIO_PORTG_BASE, GPIO_PIN_7); // if (tn_task_create(&task_GPS_tcb, &task_GPS_func, TASK_GPS_PRI, &task_GPS_stk[TASK_GPS_STK_SZ - 1], TASK_GPS_STK_SZ, 0, TN_TASK_START_ON_CREATION) != TERR_NO_ERR) { dbg_puts("tn_task_create(&task_GPS_tcb) error"); goto err; } // Настроить прерывания на PPS //MAP_IntEnable(INT_GPIOG); //MAP_GPIOIntTypeSet(GPIO_PORTG_BASE, GPIO_PIN_7, GPIO_FALLING_EDGE); //MAP_GPIOPinIntEnable(GPIO_PORTG_BASE, GPIO_PIN_7); dbg_puts("[done]"); return; err: dbg_trace(); tn_halt(); }
//***************************************************************************** // This function sets up UART0 to be used for a console to display information // as the example is running. //***************************************************************************** void InitConsole(void) { MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); MAP_GPIOPinConfigure(GPIO_PA0_U0RX); MAP_GPIOPinConfigure(GPIO_PA1_U0TX); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); MAP_UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC); MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTStdioConfig(0, 115200, 16000000); }
void SetupStdio(void) { //Put these into variables because passing macros to macros isnt fun. const unsigned long srcClock = MAP_SysCtlClockGet(); const unsigned long baud = 115200; MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); MAP_UARTConfigSetExpClk(UART0_BASE, srcClock, baud, (UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_ONE | UART_CONFIG_WLEN_8)); MAP_UARTEnable(UART0_BASE); }
/** * Initializes the UART * * \param SysClkFreq - clock frequency of the system * * \param baudRate - baud rate of the UART e.g. 115200 to connect to PC * * \note UART is connected to the stellaris virtual serial port through the USB connection * * \note Configuration: * 8 data bits * one stop bit * no parity **/ void twe_initUART(uint32_t SysClkFreq, uint32_t baudRate) { MAP_SysCtlPeripheralEnable(TWE_UART_COMM_PERIPH); MAP_SysCtlPeripheralEnable(TWE_UART_COMM_GPIO_PERIPH); MAP_GPIOPinConfigure(TWE_UART_COMM_RX_PIN_CONFIG); MAP_GPIOPinConfigure(TWE_UART_COMM_TX_PIN_CONFIG); MAP_GPIOPinTypeUART(TWE_UART_COMM_GPIO_BASE, TWE_UART_COMM_RX_PIN | TWE_UART_COMM_TX_PIN); /* MAP_UARTConfigSetExpClk(TWE_UART_COMM_BASE, SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); MAP_UARTConfigSetExpClk(TWE_UART_COMM_BASE, SysClkFreq, 4608000, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); */ MAP_UARTConfigSetExpClk(TWE_UART_COMM_BASE, SysClkFreq, baudRate, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); }
/* * ======== EK_TM4C123GXL_initUART ======== */ void EK_TM4C123GXL_initUART(void) { // Enable and configure the peripherals used by the radio uart // MAP_SysCtlPeripheralEnable(INEEDMD_RADIO_SYSCTL_PERIPH_UART); // Configure the alternate function for UART RTS pin MAP_GPIOPinConfigure(INEEDMD_GPIO_UARTRTS); MAP_GPIOPinTypeUART(INEEDMD_RADIO_RTS_PORT, INEEDMD_RADIO_RTS_PIN); // Configure the alternate function for UART CTS pin MAP_GPIOPinConfigure(INEEDMD_GPIO_UARTCTS); MAP_GPIOPinTypeUART(INEEDMD_RADIO_CTS_PORT, INEEDMD_RADIO_CTS_PIN); // Configure the alternate function for UART TX and RX pins MAP_GPIOPinConfigure(INEEDMD_GPIO_UARTTX); MAP_GPIOPinConfigure(INEEDMD_GPIO_UARTRX); // Set the TX and RX pin type for the radio uart MAP_GPIOPinTypeUART(INEEDMD_GPIO_TX_PORT, INEEDMD_GPIO_TX_PIN); MAP_GPIOPinTypeUART(INEEDMD_GPIO_RX_PORT, INEEDMD_GPIO_RX_PIN); //Set the UART clock source to internal // // MAP_UARTClockSourceSet(INEEDMD_RADIO_UART, UART_CLOCK_PIOSC); //Config the uart speed, len, stop bits and parity // // MAP_UARTConfigSetExpClk( INEEDMD_RADIO_UART, INEEDMD_RADIO_UART_CLK, INEEDMD_RADIO_UART_BAUD, ( UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE )); //Enable and configure the peripherals used by the debug uart // MAP_SysCtlPeripheralEnable(DEBUG_SYSCTL_PERIPH_UART); // Configure the debug port pins MAP_GPIOPinConfigure(DEBUG_TX_PIN_MUX_MODE); MAP_GPIOPinConfigure(DEBUG_RX_PIN_MUX_MODE); // Set the debug uart pin types MAP_GPIOPinTypeUART(DEBUG_UART_PIN_PORT, DEBUG_TX_PIN); MAP_GPIOPinTypeUART(DEBUG_UART_PIN_PORT, DEBUG_RX_PIN); //Set the clock source for the debug uart // UARTClockSourceSet(DEBUG_UART, UART_CLOCK_PIOSC); /* Initialize the UART driver */ UART_init(); }
/* * @brief Initializes serial I/O. * * Enable the peripherals used by this example. * Enable processor interrupts. * Set GPIO A0 and A1 as UART pins. * Configure the UART for 115,200, 8-N-1 operation. * Enable the UART interrupt. * @returns void */ void serialInit() { // Enable the peripherals. MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // Set GPIO A0 and A1 as UART pins. MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // Configure the UART for 230,400, 8N1 operation. MAP_UARTConfigSetExpClk(UART0_BASE, SYSCTL_CLOCK_FREQ, SERIAL_BAUDRATE, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); // MAP_UARTFIFOEnable(UART0_BASE); // // set the fifos for 1/8 empty on transmit and 3/4 full on receive // MAP_UARTFIFOLevelSet(UART0_BASE, UART_FIFO_TX7_8, UART_FIFO_RX1_8); // Enable the UART interrupts (receive only). MAP_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT); MAP_UARTIntDisable(UART0_BASE, UART_INT_TX); // Enable the interrupt in the NVIC with the right priority for FreeRTOS // MAP_IntPrioritySet(INT_UART0, SYSTEM_INTERRUPT_PRIORITY); // MAP_IntEnable(INT_UART0); }
/* success. */ int BTPSAPI HCITR_COMOpen(HCI_COMMDriverInformation_t *COMMDriverInformation, HCITR_COMDataCallback_t COMDataCallback, unsigned long CallbackParameter) { int ret_val; /* First, make sure that the port is not already open and make sure */ /* that valid COMM Driver Information was specified. */ if((!HCITransportOpen) && (COMMDriverInformation) && (COMDataCallback)) { /* Initialize the return value for success. */ ret_val = TRANSPORT_ID; /* Note the COM Callback information. */ _COMDataCallback = COMDataCallback; _COMCallbackParameter = CallbackParameter; /* Initialize the UART Context Structure. */ BTPS_MemInitialize(&UartContext, 0, sizeof(UartContext_t)); UartContext.Base = HCI_UART_BASE; UartContext.IntBase = HCI_UART_INT; UartContext.ID = 1; UartContext.FlowInfo = UART_CONTEXT_FLAG_FLOW_CONTROL_ENABLED; UartContext.XOnLimit = DEFAULT_XON_LIMIT; UartContext.XOffLimit = DEFAULT_XOFF_LIMIT; UartContext.RxBufferSize = DEFAULT_INPUT_BUFFER_SIZE; UartContext.RxBytesFree = DEFAULT_INPUT_BUFFER_SIZE; UartContext.TxBufferSize = DEFAULT_OUTPUT_BUFFER_SIZE; UartContext.TxBytesFree = DEFAULT_OUTPUT_BUFFER_SIZE; /* Flag that the Rx Thread should not delete itself. */ RxThreadDeleted = FALSE; /* Check to see if this is the first time that the port has been */ /* opened. */ if(!Handle) { /* Configure the UART module and the GPIO pins used by the */ /* UART. */ MAP_SysCtlPeripheralEnable(HCI_UART_GPIO_PERIPH); MAP_SysCtlPeripheralEnable(HCI_UART_RTS_GPIO_PERIPH); MAP_SysCtlPeripheralEnable(HCI_UART_CTS_GPIO_PERIPH); MAP_SysCtlPeripheralEnable(HCI_UART_PERIPH); MAP_GPIOPinConfigure(HCI_PIN_CONFIGURE_UART_RX); MAP_GPIOPinConfigure(HCI_PIN_CONFIGURE_UART_TX); MAP_GPIOPinConfigure(HCI_PIN_CONFIGURE_UART_RTS); MAP_GPIOPinConfigure(HCI_PIN_CONFIGURE_UART_CTS); MAP_GPIOPinTypeUART(HCI_UART_GPIO_BASE, HCI_UART_PIN_RX | HCI_UART_PIN_TX); MAP_GPIOPinTypeUART(HCI_UART_RTS_GPIO_BASE, HCI_UART_PIN_RTS); MAP_GPIOPinTypeUART(HCI_UART_CTS_GPIO_BASE, HCI_UART_PIN_CTS); UARTFlowControlSet(UartContext.Base, UART_FLOWCONTROL_RX | UART_FLOWCONTROL_TX); /* Create an Event that will be used to signal that data has */ /* arrived. */ RxDataEvent = BTPS_CreateEvent(FALSE); if(RxDataEvent) { /* Create a thread that will process the received data. */ Handle = BTPS_CreateThread(RxThread, 1600, NULL); if(!Handle) { BTPS_CloseEvent(RxDataEvent); ret_val = HCITR_ERROR_UNABLE_TO_OPEN_TRANSPORT; } } else ret_val = HCITR_ERROR_UNABLE_TO_OPEN_TRANSPORT; } /* If there was no error, then continue to setup the port. */ if(ret_val != HCITR_ERROR_UNABLE_TO_OPEN_TRANSPORT) { /* Configure UART Baud Rate and Interrupts. */ MAP_UARTConfigSetExpClk(UartContext.Base, MAP_SysCtlClockGet(), COMMDriverInformation->BaudRate, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); /* SafeRTOS requires RTOS-aware int handlers to be priority */ /* value 5 or greater */ MAP_IntPrioritySet(UartContext.IntBase, 6 << 5); MAP_IntEnable(UartContext.IntBase); MAP_UARTIntEnable(UartContext.Base, UART_INT_RX | UART_INT_RT); UartContext.Flags |= UART_CONTEXT_FLAG_RX_FLOW_ENABLED; /* Clear any data that is in the Buffer. */ FlushRxFIFO(UartContext.Base); /* Bring the Bluetooth Device out of Reset. */ MAP_GPIOPinWrite(HCI_RESET_BASE, HCI_RESET_PIN, HCI_RESET_PIN); /* Check to see if we need to delay after opening the COM Port.*/ if(COMMDriverInformation->InitializationDelay) BTPS_Delay(COMMDriverInformation->InitializationDelay); /* Flag that the HCI Transport is open. */ HCITransportOpen = 1; } } else ret_val = HCITR_ERROR_UNABLE_TO_OPEN_TRANSPORT; return(ret_val); }
//***************************************************************************** // // The main function sets up the peripherals for the example, then enters // a wait loop until the DMA transfers are complete. At the end some // information is printed for the user. // //***************************************************************************** int main(void) { unsigned long ulIdx; // // Set the clocking to run directly from the PLL at 50 MHz. // MAP_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Initialize the console UART and write a message to the terminal. // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); MAP_GPIOPinConfigure(GPIO_PA0_U0RX); MAP_GPIOPinConfigure(GPIO_PA1_U0TX); MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTStdioInit(0); UARTprintf("\033[2JMemory/UART scatter-gather uDMA example\n\n"); // // Configure UART1 to be used for the loopback peripheral // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1); // // Configure the UART communication parameters. // MAP_UARTConfigSetExpClk(UART1_BASE, MAP_SysCtlClockGet(), 115200, UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE); // // Set both the TX and RX trigger thresholds to one-half (8 bytes). This // will be used by the uDMA controller to signal when more data should be // transferred. The uDMA TX and RX channels will be configured so that it // can transfer 8 bytes in a burst when the UART is ready to transfer more // data. // MAP_UARTFIFOLevelSet(UART1_BASE, UART_FIFO_TX4_8, UART_FIFO_RX4_8); // // Enable the UART for operation, and enable the uDMA interface for both TX // and RX channels. // MAP_UARTEnable(UART1_BASE); MAP_UARTDMAEnable(UART1_BASE, UART_DMA_RX | UART_DMA_TX); // // This register write will set the UART to operate in loopback mode. Any // data sent on the TX output will be received on the RX input. // HWREG(UART1_BASE + UART_O_CTL) |= UART_CTL_LBE; // // Enable the UART peripheral interrupts. Note that no UART interrupts // were enabled, but the uDMA controller will cause an interrupt on the // UART interrupt signal when a uDMA transfer is complete. // MAP_IntEnable(INT_UART1); // // Enable the uDMA peripheral clocking. // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); // // Enable the uDMA controller. // MAP_uDMAEnable(); // // Point at the control table to use for channel control structures. // MAP_uDMAControlBaseSet(sControlTable); // // Configure the UART TX channel for scatter-gather // Peripheral scatter-gather is used because transfers are gated by // requests from the peripheral // UARTprintf("Configuring UART TX uDMA channel for scatter-gather\n"); #ifndef USE_SGSET_API // // Use the original method for configuring the scatter-gather transfer // uDMAChannelControlSet(UDMA_CHANNEL_UART1TX, UDMA_SIZE_32 | UDMA_SRC_INC_32 | UDMA_DST_INC_32 | UDMA_ARB_4); uDMAChannelTransferSet(UDMA_CHANNEL_UART1TX, UDMA_MODE_PER_SCATTER_GATHER, g_TaskTableSrc, &sControlTable[UDMA_CHANNEL_UART1TX], 6 * 4); #else // // Use the simplified API for configuring the scatter-gather transfer // uDMAChannelScatterGatherSet(UDMA_CHANNEL_UART1TX, 6, g_TaskTableSrc, 1); #endif // // Configure the UART RX channel for scatter-gather task list. // This is set to peripheral s-g because it starts by receiving data // from the UART // UARTprintf("Configuring UART RX uDMA channel for scatter-gather\n"); #ifndef USE_SGSET_API // // Use the original method for configuring the scatter-gather transfer // uDMAChannelControlSet(UDMA_CHANNEL_UART1RX, UDMA_SIZE_32 | UDMA_SRC_INC_32 | UDMA_DST_INC_32 | UDMA_ARB_4); uDMAChannelTransferSet(UDMA_CHANNEL_UART1RX, UDMA_MODE_PER_SCATTER_GATHER, g_TaskTableDst, &sControlTable[UDMA_CHANNEL_UART1RX], 7 * 4); #else // // Use the simplified API for configuring the scatter-gather transfer // uDMAChannelScatterGatherSet(UDMA_CHANNEL_UART1RX, 7, g_TaskTableDst, 1); #endif // // Fill the source buffer with a pattern // for(ulIdx = 0; ulIdx < 1024; ulIdx++) { g_ucSrcBuf[ulIdx] = ulIdx + (ulIdx / 256); } // // Enable the uDMA controller error interrupt. This interrupt will occur // if there is a bus error during a transfer. // IntEnable(INT_UDMAERR); // // Enable the UART RX DMA channel. It will wait for data to be available // from the UART. // UARTprintf("Enabling uDMA channel for UART RX\n"); MAP_uDMAChannelEnable(UDMA_CHANNEL_UART1RX); // // Enable the UART TX DMA channel. Since the UART TX will be asserting // a DMA request (since the TX FIFO is empty), this will cause this // DMA channel to start running. // UARTprintf("Enabling uDMA channel for UART TX\n"); MAP_uDMAChannelEnable(UDMA_CHANNEL_UART1TX); // // Wait for the TX task list to be finished // UARTprintf("Waiting for TX task list to finish ... "); while(!g_bTXdone) { } UARTprintf("done\n"); // // Wait for the RX task list to be finished // UARTprintf("Waiting for RX task list to finish ... "); while(!g_bRXdone) { } UARTprintf("done\n"); // // Verify that all the counters are in the expected state // UARTprintf("Verifying counters\n"); if(g_ulDMAIntCount != 2) { UARTprintf("ERROR in interrupt count, found %d, expected 2\n", g_ulDMAIntCount); } if(g_uluDMAErrCount != 0) { UARTprintf("ERROR in error counter, found %d, expected 0\n", g_uluDMAErrCount); } // // Now verify the contents of the final destination buffer. Compare it // to the original source buffer. // UARTprintf("Verifying buffer contents ... "); for(ulIdx = 0; ulIdx < 1024; ulIdx++) { if(g_ucDstBuf[ulIdx] != g_ucSrcBuf[ulIdx]) { UARTprintf("ERROR\n @ index %d: expected 0x%02X, found 0x%02X\n", ulIdx, g_ucSrcBuf[ulIdx], g_ucDstBuf[ulIdx]); UARTprintf("Checking stopped. There may be additional errors\n"); break; } } if(ulIdx == 1024) { UARTprintf("OK\n"); } // // End of program, loop forever // for(;;) { } }
//***************************************************************************** // // Configue UART in internal loopback mode and tranmsit and receive data // internally. // //***************************************************************************** int main(void) { #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) uint32_t ui32SysClock; #endif uint8_t ui8DataTx[NUM_UART_DATA]; uint8_t ui8DataRx[NUM_UART_DATA]; uint32_t ui32index; // // Set the clocking to run directly from the crystal. // #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_OSC), 25000000); #else MAP_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); #endif // // Enable the peripherals used by this example. // UART0 : To dump information to the console about the example. // UART7 : Enabled in loopback mode. Anything transmitted to Tx will be // received at the Rx. // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART7); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // // Set GPIO A0 and A1 as UART pins. // GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Internal loopback programming. Configure the UART in loopback mode. // UARTLoopbackEnable(UART7_BASE); // // Configure the UART for 115,200, 8-N-1 operation. // #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) MAP_UARTConfigSetExpClk(UART0_BASE, ui32SysClock, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); MAP_UARTConfigSetExpClk(UART7_BASE, ui32SysClock, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); #else MAP_UARTConfigSetExpClk(UART0_BASE, MAP_SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); MAP_UARTConfigSetExpClk(UART7_BASE, MAP_SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); #endif // // Print banner after clearing the terminal. // UARTSend(UART0_BASE, (uint8_t *)"\033[2J\033[1;1H", 10); UARTSend(UART0_BASE, (uint8_t *)"\nUART Loopback Example ->", strlen("\nUART Loopback Example ->")); // // Prepare data to send over the UART configured for internal loopback. // ui8DataTx[0] = 'u'; ui8DataTx[1] = 'a'; ui8DataTx[2] = 'r'; ui8DataTx[3] = 't'; // // Inform user that data is being sent over for internal loopback. // UARTSend(UART0_BASE, (uint8_t *)"\n\n\rSending : ", strlen("\n\n\rSending : ")); UARTSend(UART0_BASE, (uint8_t*)ui8DataTx, NUM_UART_DATA); // // Send the data, which was prepared above, over the UART configured for // internal loopback operation. // for(ui32index = 0 ; ui32index < NUM_UART_DATA ; ui32index++) { UARTCharPut(UART7_BASE, ui8DataTx[ui32index]); } // // Wait for the UART module to complete transmitting. // while(MAP_UARTBusy(UART7_BASE)) { } // // Inform user that data the loopback data is being received. // UARTSend(UART0_BASE, (uint8_t *)"\n\rReceiving : ", strlen("\n\rReceiving : ")); // // Read data from the UART's receive FIFO and store it. // for(ui32index = 0 ; ui32index < NUM_UART_DATA ; ui32index++) { // // Get the data received by the UART at its receive FIFO // ui8DataRx[ui32index] = UARTCharGet(UART7_BASE); } // // Display the data received, after loopback, over UART's receive FIFO. // UARTSend(UART0_BASE, (uint8_t*)ui8DataRx, NUM_UART_DATA); // // Return no errors // return(0); }
/* * initialize tm4c */ void init_satellite() { FPUEnable(); FPULazyStackingEnable(); /* * init clock */ MAP_SysCtlClockSet(SYSCTL_SYSDIV_3 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); //66.6..MHz MAP_IntMasterEnable(); /* * Enable peripherals */ MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); //for LED indication MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); //for UART MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); //for IRQ and SW_EN MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); //for SPI /* * configure */ MAP_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3); MAP_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, SIGNAL_LOW); //off MAP_GPIOPinConfigure(GPIO_PA0_U0RX); MAP_GPIOPinConfigure(GPIO_PA1_U0TX); MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTStdioConfig(UART_PORT, UART_BAUDRATE, SysCtlClockGet()); MAP_GPIOIntDisable(GPIO_PORTB_BASE, SIGNAL_HIGH); //interrupt disable MAP_GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_2); //IRQ as input MAP_GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); MAP_GPIOIntTypeSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_FALLING_EDGE); //enable interrupt MAP_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_5); //sw enable MAP_GPIODirModeSet(GPIO_PORTB_BASE, GPIO_PIN_5, GPIO_DIR_MODE_OUT); MAP_GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_5, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPD); MAP_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5, SIGNAL_LOW); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); MAP_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_0); MAP_GPIOPadConfigSet(GPIO_PORTE_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); MAP_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_0, SIGNAL_HIGH); //chip select MAP_GPIOIntEnable(GPIO_PORTB_BASE, GPIO_PIN_2); //enable interrupt for WLAN_IRQ pin SpiCleanGPIOISR(); //clear interrupt status MAP_IntEnable(INT_GPIOB); //spi init_worker(); setState(READY); }
//***************************************************************************** void PortFunctionInit(void) { // // Enable Peripheral Clocks // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // // Enable pin PA7 for GPIOInput // MAP_GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_7); // // Enable pin PA6 for GPIOInput - SPI Current Word is Header Word // MAP_GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_6); // // Enable pin PF2 for GPIOInput // MAP_GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_2); // // Enable pin PF3 for GPIOInput // MAP_GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_3); // // Enable pin PF1 for GPIOOutputOD // MAP_GPIOPinTypeGPIOOutputOD(GPIO_PORTF_BASE, GPIO_PIN_1); // // Enable pin PA5 for SSI0 SSI0TX // MAP_GPIOPinConfigure(GPIO_PA5_SSI0TX); MAP_GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_5); // // Enable pin PA4 for SSI0 SSI0RX // MAP_GPIOPinConfigure(GPIO_PA4_SSI0RX); MAP_GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_4); // // Enable pin PA2 for SSI0 SSI0CLK // MAP_GPIOPinConfigure(GPIO_PA2_SSI0CLK); MAP_GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_2); // // Enable pin PA3 for SSI0 SSI0FSS // MAP_GPIOPinConfigure(GPIO_PA3_SSI0FSS); MAP_GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_3); // // Enable pin PA0 for UART0 U0RX // MAP_GPIOPinConfigure(GPIO_PA0_U0RX); MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0); // // Enable pin PA1 for UART0 U0TX // MAP_GPIOPinConfigure(GPIO_PA1_U0TX); MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_1); // // Enable pin PD4 for USB0 USB0DM // MAP_GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_4); // // Enable pin PD5 for USB0 USB0DP // MAP_GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_5); }