XDK API  39.00
Documentation
XDK Extension Bus User Guide

General Information


The extension bus allows the implementation of additional functionality to the XDK main board, like radios or sensors. This way, developers can use the hardware and software of XDK for testing out new components with minimal application effort.

Note
Extension bus documentation updated as per the XDK user Guide documentation section 4.2.5 Errata. This Documentation is applicable for XDK Gateway V1.0 extension board

Extension header pin assignment

Please find the mapping of the XDK extension connector in the following table.

pin on connector pin on MCU Suggested Usage Macro
A1 PA0 Timer0 compare operations EXTENSION_TIM0_CC0
A2 PC0 Timer0 compare operations EXTENSION_TIM0_CC1
A3 PC1 Timer0 compare operations EXTENSION_TIM0_CC2
A4 PC2 Timer0 Dead time insertion operations EXTENSION_TIM0_CDTI0
A5 PC3 Timer0 Dead time insertion operations EXTENSION_TIM0_CDTI1
A6 PC4 Timer0 Dead time insertion operations EXTENSION_TIM0_CDTI2
A7 PC8 Timer2 Capture operations EXTENSION_TIM2_CC0
A8 PC9 Timer2 Capture operations EXTENSION_TIM2_CC1
A9 PC10 Timer2 Capture operations EXTENSION_TIM2_CC2
A10 PD6 ADC0 operations EXTENSION_ADC0_CH5
A11 PD5 ADC0 operations EXTENSION_ADC0_CH6
A12 PA1 General purpose I/O EXTENSION_GPIO_IN_OUT_0
A13 PE2 General purpose I/O EXTENSION_GPIO_IN_OUT_1
B1 PB9 UART1_TX operations EXTENSION_UART1_TX
B2 PB10 UART1_RX operations EXTENSION_UART1_RX
B3 PB2 UART1_RTS operations EXTENSION_UART1_RTS
B4 PF6 UART1_CTS operations EXTENSION_UART1_CTS
B5 PB4 US2 MISO operations EXTENSION_US2_MISO
B6 PB3 US2 MOSI operations EXTENSION_US2_MOSI
B7 PB5 US2 clock operations EXTENSION_US2_SCK
B8 PD8 US2 chip select EXTENSION_US2_CS
B9 PB11 I2C1 data line EXTENSION_I2C1_SDA
B10 PB12 I2C1 clock line EXTENSION_I2C1_SCL
B11 2V5 Power Limit 100mA continuous/ peak -
B12 3V3 Power Limit 100mA continuous/ peak -
B13 GND Power -

The extension bus connector of XDK is a 26-pin male connector of type ERNI Male 054595. For your extension boards, please use the same connector and use the flat ribbon cable to connect your extension board to XDK.

The MCU pins refer to the Giant Gecko microcontroller on the XDK. For details on the configuration, please refer to the MCU datasheet and MCU Reference Manual.

Warning
I2C1 data pin (PB11) and I2C clock pin (PB12) have an internal pull up resistor of 3.32k and hence cannot be used as GPIO.
Note
Any pin that you want to use will have to be configured accordingly. Please refer to the GPIO_Driver and PTD_portDriver modules for doing so. All pins are assigned with default modes and values in file xdk110/HWconfig/HW_XDK_v1/PDC_pinDefaultConfig\PDC_pinDefaultConfig_cc.c. Please refer to the code for further information.

I2C sample application - Compatible to XDK workbench version V3.0.0 and above

This example outlines how to interface external I2C device to XDK via extension Bus

The below code snippet explains the c modules required.

The following example module is necessary to establish proper connection to hardware for interfacing external I2C device to XDK via extension bus.

/* Global Declarations and include required for this module*/
#include "em_gpio.h"
#include "em_cmu.h"
#include "BSP_I2C.h" /* Header file containing BSP interface */
/* Value defined is MCU driver specific do not change these below macros*/
#define I2C_EXT_BUS_IRQ_NUMBER (I2C1_IRQn)
#define I2C_EXT_BUS_IRQ_PRIORITY UINT32_C(5)
#define I2C_EXT_BUS_PORT I2C1
#define I2C_EXT_BUS_CLOCK (cmuClock_I2C1)
static I2C_IRQ_Callback_T EXT_I2CNode_ISRCallback;
struct MCU_I2C_Handle_S EXT_I2C_Handle;
#define I2C1_PORT_EXTENSION_SDA (gpioPortB)
#define I2C1_PIN_EXTENSION_SDA (11)
#define I2C1_MODE_EXTENSION_SDA (gpioModeWiredAnd)
#define I2C1_DOUT_EXTENSIO_SDA (1)
#define I2C1_PORT_EXTENSION_SCL (gpioPortB)
#define I2C1_PIN_EXTENSION_SCL (12)
#define I2C1_MODE_EXTENSION_SCL (gpioModeWiredAnd)
#define I2C1_DOUT_EXTENSION_SCL (1)
/* This API only put the I2C device pins configured/Connected but still not yet put into operation */
/* note: This API shall be called once during the initialization routine of the user application */
{
/* Configure the Route for the I2C */
CMU_ClockEnable(I2C_EXT_BUS_CLOCK, true);
I2C_EXT_BUS_PORT->ROUTE = I2C_ROUTE_SDAPEN | I2C_ROUTE_SCLPEN | I2C_ROUTE_LOCATION_LOC1;
CMU_ClockEnable(I2C_EXT_BUS_CLOCK, false);
return RETCODE_OK;
}
/* This API put the device pins in tristate/reset/disconnected state */
{
GPIO_PinModeSet(I2C1_PORT_EXTENSION_SDA, I2C1_PIN_EXTENSION_SDA, gpioModeDisabled, 0);
GPIO_PinModeSet(I2C1_PORT_EXTENSION_SCL, I2C1_PIN_EXTENSION_SCL, gpioModeDisabled, 0);
/* Configure the Route for the I2C */
CMU_ClockEnable(I2C_EXT_BUS_CLOCK, true);
I2C_EXT_BUS_PORT->ROUTE = _I2C_ROUTE_RESETVALUE;
CMU_ClockEnable(I2C_EXT_BUS_CLOCK, false);
return RETCODE_OK;
}
/* This API shall be called to get hardware I2C port reference to
HAL layer such that the read/write/configure is possible. Design is made in such a way that the I2C handle "MCU_I2C_Handle_S",
which is the forward declared struct at layer "Platform/HAL/include/mcu/efm32/BCDS_MCU_I2C_Handle.h"
is used by BSP, I2C application interface driver must fill Hardware related info in this structure */
/*note 1 HWHandle_T is the generic void pointer to hold address of the I2C handle
note 2 This API need to be called in I2C application interface driver before calling BSP_I2C_Enable() API */
{
}
/* This API is an I2C hardware ISR routine */
/* note Do not change the name of this API as this is specific to MCU */
void I2C1_IRQHandler(void)
{
if (NULL != EXT_I2C_Handle.IRQCallback)
{
/* All I2C interrupt processing is to be done at the MCU level */
}
}
/* This API puts the I2C device into operational state */
/* note After calling this API in user application,I2C read and I2C write operation shall be invoked from the application program */
void BSP_I2C_Enable(void)
{
CMU_ClockEnable(I2C_EXT_BUS_CLOCK, true);
if (NULL != EXT_I2C_Handle.IRQCallback)
{
EXT_I2CNode_ISRCallback = EXT_I2C_Handle.IRQCallback;
NVIC_EnableIRQ(I2C_EXT_BUS_IRQ_NUMBER);
}
I2C_Enable(I2C_EXT_BUS_PORT, true);
}
/* This API disables the I2C device from its operational state */
/* note after calling the BSP_I2C_Enable() API must be called if user would like to use I2C again */
void BSP_I2C_Disable(void)
{
NVIC_DisableIRQ(I2C_EXT_BUS_IRQ_NUMBER);
EXT_I2CNode_ISRCallback = NULL;
I2C_Enable(I2C_EXT_BUS_PORT, false);
CMU_ClockEnable(I2C_EXT_BUS_CLOCK, false);
}

The following example module is necessary to establish I2C communication.

/*Global Declarations and include required for this module*/
#include "FreeRTOS.h"
#include "semphr.h"
#include "BCDS_MCU_I2C.h"
#include "HAL_I2C.h" /* Header file containing HAL interface*/
#include "BSP_I2C.h" /* Header file containing BSP interface*/
#define DATA_TRANSFER_TIMEOUT_MILLISEC UINT32_C(1000)
#define I2C_SENSORTRANSCEIVER_ERROR INT8_C(-1)
#define I2C_SENSORTRANSCEIVER_SUCCESS INT8_C(0)
bool initializationStatus = false; /*This variable can be used to avoid multiple initialization of the device connected on the same I2C bus*/
/* I2C handle for hardware I2C instance created for External I2C hardware */
static I2C_T I2CHandle = NULL;
/*
* This function will be called from I2C ISR context to handle I2C events
* Callback prototype see HAL MCU:
* typedef void (*MCU_I2C_Callback_T)(I2C_T i2c, struct MCU_I2C_Event_S event);
*/
static void HAL_I2C_Transceiver_AppCallback(I2C_T i2c, struct MCU_I2C_Event_S event);
/* This API is an interrupt service handler routine for application , note this call happens in interrupt context.
the I2C driver in HAL is completely interrupt driven this callback is invoked once after the requested read/Write operation is completed */
static void HAL_I2C_Transceiver_AppCallback(I2C_T i2c, struct MCU_I2C_Event_S event)
{
Retcode_T retcode = RETCODE_OK;
BaseType_t higherPriorityTaskWoken = pdFALSE;
if ((I2C_T) NULL == i2c)
{ /* Handle is not initialized */
}
else if (false == initializationStatus)
{ /* Transciever is not initialized */
}
else if (NULL == I2CBusSync)
{ /* I2C Bus lock not present */
}
if (RETCODE_OK == retcode)
{
if (UINT8_C(1) == event.TxComplete)
{
retcode = RETCODE_OK;
}
if (UINT8_C(1) == event.TransferError)
{
}
/* Give Semaphore even in case of transfer I2C errors or I2C Transfer gets completed */
if (pdTRUE == xSemaphoreGiveFromISR(I2CBusSync, &higherPriorityTaskWoken))
{
portYIELD_FROM_ISR(higherPriorityTaskWoken);
}
else
{
/* ignore... semaphore has already been given */
}
}
if (RETCODE_OK != retcode)
{
/*The below API can be used for Diagnostic purpose in case of error*/
}
}
/* This API initialize the I2C driver */
/* note This API has to be called first by the application code */
{
Retcode_T retcode = RETCODE_OK;
if (true == initializationStatus)
{
return RETCODE_OK;
}
/* binary semaphore for synchronization between the application task and the I2C interrupt */
I2CBusSync = xSemaphoreCreateBinary();
if (NULL == I2CBusSync)
{
}
if (RETCODE_OK == retcode)
{
retcode = BSP_I2C_Connect();
}
if (RETCODE_OK == retcode)
{
I2CHandle = BSP_I2C_GetHandle();
if (NULL != I2CHandle)
{
retcode = MCU_I2C_Initialize(I2CHandle, HAL_I2C_Transceiver_AppCallback);
}
else
{
}
if (RETCODE_OK == retcode)
{
}
}
if (RETCODE_OK == retcode)
{
initializationStatus = true;
}
return retcode;
}
/* This API is the implementation reading over I2C bus.*/
/* Return value for this function call can be user specific , int8_t is given for an example*/
int8_t HAL_I2C_Transceiver_Read(uint16_t I2Caddr, uint8_t RegisterAddr, uint8_t *RegData, uint32_t RxLen)
{
Retcode_T retcode = RETCODE_OK;
int8_t returnValue = I2C_SENSORTRANSCEIVER_SUCCESS;
if (UINT8_C(0) >= RxLen)
{
}
if ((NULL == RegData) || (NULL == I2CBusSync))
{
}
if (((I2C_T) 0 == I2CHandle) || (false == initializationStatus))
{
}
if (RETCODE_OK == retcode)
{
/* Depending on the type of I2C peripherals being interfaced, MCU_I2C_Receive() can be used , In this example register based read is given
as example*/
retcode = MCU_I2C_ReadRegister(I2CHandle, (uint16_t) I2Caddr, RegisterAddr, RegData, RxLen);
}
if (RETCODE_OK == retcode)
{
if (pdTRUE == xSemaphoreTake(I2CBusSync, (TickType_t) pdMS_TO_TICKS(DATA_TRANSFER_TIMEOUT_MILLISEC)))
{
/* We were able to obtain the semaphore and can now access the
shared resource. */
}
else
{
}
}
if (RETCODE_OK != retcode)
{
}
return returnValue;
}
/* This API is the implementation writing over I2C bus. */
/* Return value for this function call can be user specific , int8_t is given for an example*/
int8_t HAL_I2C_Transceiver_Write(uint16_t I2Caddr, uint8_t RegisterAddr, uint8_t *RegData, uint32_t TxLen)
{
Retcode_T retcode = RETCODE_OK;
int8_t returnValue = I2C_SENSORTRANSCEIVER_SUCCESS;
if (UINT8_C(0) >= TxLen)
{
}
if ((NULL == RegData) || (NULL == I2CBusSync) )
{
}
if (((I2C_T) 0 == I2CHandle) || (false == initializationStatus))
{
}
if (RETCODE_OK == retcode)
{
/* Depending on the type of I2C peripherals being interfaced, MCU_I2C_Send() can be used , In this example register based write is given
as example*/
retcode = MCU_I2C_WriteRegister(I2CHandle, (uint16_t) I2Caddr, RegisterAddr, RegData, TxLen);
}
if (RETCODE_OK == retcode)
{
if (pdTRUE == xSemaphoreTake(I2CBusSync, (TickType_t) pdMS_TO_TICKS(DATA_TRANSFER_TIMEOUT_MILLISEC)))
{
/* We were able to obtain the semaphore and can now access the
shared resource. */
}
else
{
}
}
if (RETCODE_OK != retcode)
{
}
return returnValue;
}
/* This API De-initialize the I2C driver */
{
Retcode_T retcode = RETCODE_OK;
if (((I2C_T) NULL == I2CHandle) || (false == initializationStatus))
{
}
if (RETCODE_OK == retcode)
{
retcode = MCU_I2C_Deinitialize(I2CHandle);
}
if (RETCODE_OK == retcode)
{
retcode = BSP_I2C_Disconnect();
}
if (RETCODE_OK == retcode)
{
if (NULL != I2CBusSync)
{
vSemaphoreDelete(I2CBusSync);
I2CBusSync = NULL;
}
initializationStatus = false;
I2CHandle = NULL;
}
return retcode;
}

Sample application to interface I2C device to XDK extension bus

The following is an example application for interfacing I2C to XDK via extension bus.

Note
1 The sensor used here for the sample application is BMA250FB
2 Please refer xdk110/Apps/ExtensionBusI2C for interfacing I2C with XDK via extension bus.
/* system header files */
#include <stdio.h>
/* additional interface header files */
#include "FreeRTOS.h"
#include "timers.h"
#include "HAL_I2C.h" /*Header file containing HAL interfaces*/
#include "BSP_I2C.h" /*Header file containing BSP interfaces */
void appInitSystem(void * CmdProcessorHandle, uint32_t param2)
{
BCDS_UNUSED(CmdProcessorHandle);
BCDS_UNUSED(param2);
uint8_t RegData[2] = { 0x00, 0x28 };
uint16_t I2Caddr = 0x18; /*I2C address of the BMA250FB */
uint8_t RegisterAddr = { 0x00 };
Retcode_T returnVal = RETCODE_OK;
returnVal = HAL_I2C_Transceiver_Init();
if (returnVal == RETCODE_OK)
{
returnVal = HAL_I2C_Transceiver_Write(I2Caddr, RegisterAddr, &RegData[1], 1);
if (RETCODE_OK == returnVal)
{
/*Reading the chip id of BMA250FB sensor */
returnVal = HAL_I2C_Transceiver_Read(I2Caddr, RegisterAddr, &RegData[0], 1);
printf("I2C read and write successful \r\n");
}
}
if (RETCODE_OK != returnVal)
{
printf("I2C read/write failed \r\n");
}
}

SPI sample application - Compatible to XDK workbench version V3.0.0 and above

This example outlines how to interface external SPI device to XDK via extension Bus.

The below code snippet explains the c modules reqUired

The following example module is necessary to establish proper connection to hardware for interfacing external SPI device to XDK via extension bus.

#include "BSP_SPI.h"
#if BCDS_FEATURE_DMA
#include "BSP_DMA.h"
static SPI_DMA_Callback_T EXT_SPI_TxDmaCallback = NULL;
static SPI_DMA_Callback_T EXT_SPI_RxDmaCallback = NULL;
struct MCU_DMA_Channel_S EXT_SPI_DMA_TX_Channel;
struct MCU_DMA_Channel_S EXT_SPI_DMA_RX_Channel;
#endif
/* Put the type and macro definitions here */
struct MCU_SPI_Handle_S EXT_SPI_Handle;
static SPI_IRQ_Callback_T EXT_SPI_RxISRCallback;
static SPI_IRQ_Callback_T EXT_SPI_TxISRCallback;
#define EXT_SPI2_PORT USART2
#define EXT_SPI2_CLOCK (cmuClock_USART2)
#define EXT_SPI2_MISO_PIN (4)
#define EXT_SPI2_MISO_PORT (gpioPortB)
#define EXT_SPI2_MISO_MODE (gpioModeInput)
#define EXT_SPI2_MOSI_PIN (3)
#define EXT_SPI2_MOSI_PORT (gpioPortB)
#define EXT_SPI2_MOSI_MODE (gpioModePushPull)
#define EXT_SPI2_SCK_PIN (5)
#define EXT_SPI2_SCK_PORT (gpioPortB)
#define EXT_SPI2_SCK_MODE (gpioModePushPull)
#define EXT_SPI2_CS_PIN (8)
#define EXT_SPI2_CS_PORT (gpioPortD)
#define EXT_SPI2_CS_MODE (gpioModePushPull)
#define EXT_SPI2_TX_DMA_CHANNEL (3)
#define EXT_SPI2_RX_DMA_CHANNEL (2)
#define EXT_SPI_RX_IRQN USART2_RX_IRQn
#define EXT_SPI_TX_IRQN USART2_TX_IRQn
#define EXT_SPI_RX_INTERRUPT_PRIORITY UINT32_C(5)
#define EXT_SPI_TX_INTERRUPT_PRIORITY EXT_SPI_RX_INTERRUPT_PRIORITY
#define EXT_SPI2_PERCLK_FREQUENCY HSE_VALUE
#define EXT_SPI2_SPI_BAUDRATE UINT32_C(2000000)
/*
* enumeration of custom return codes
*/
{
};
#if BCDS_FEATURE_DMA
/* This API is for RX complete event while SPI driver is configured for DMA transport mode */
void BSP_SPI_RxDMAComplete(uint32_t channel, bool primary, void * user)
{
BCDS_UNUSED(channel);
BCDS_UNUSED(primary);
BCDS_UNUSED(user);
if (NULL != EXT_SPI_RxDmaCallback)
{
/* All UART interrupt processing is to be done at the MCU level */
EXT_SPI_RxDmaCallback((SPI_T) &EXT_SPI_Handle);
}
}
/* This API is for TX complete event while SPI driver is configured for DMA transport mode */
void BSP_SPI_TxDMAComplete(uint32_t channel, bool primary, void * user)
{
BCDS_UNUSED(channel);
BCDS_UNUSED(primary);
BCDS_UNUSED(user);
if (NULL != EXT_SPI_TxDmaCallback)
{
/* All UART interrupt processing is to be done at the MCU level */
EXT_SPI_TxDmaCallback((SPI_T) &EXT_SPI_Handle);
}
}
#endif
/* This API puts the device pins configured/Connected but still not yet put into operation */
/* note This API shall be called once during the initialization routine of the user application */
{
GPIO_PinModeSet(EXT_SPI2_CS_PORT, EXT_SPI2_CS_PIN, EXT_SPI2_CS_MODE, 1); /*It is assumed that CS active is "Logic Negative ", hence pin out value is 1 */
/* Set the routing for the External SPI pins TX,RX and clock */
/* Chip select (CS) pin will be controlled by software */
CMU_ClockEnable(EXT_SPI2_CLOCK, true);
EXT_SPI2_PORT->ROUTE = USART_ROUTE_RXPEN | USART_ROUTE_TXPEN | USART_ROUTE_CLKPEN | USART_ROUTE_LOCATION_LOC1;
CMU_ClockEnable(EXT_SPI2_CLOCK, false);
#if BCDS_FEATURE_DMA
EXT_SPI_DMA_TX_Channel.ChannelId = EXT_SPI2_TX_DMA_CHANNEL;
EXT_SPI_DMA_TX_Channel.Config.highPri = false;
EXT_SPI_DMA_TX_Channel.Config.enableInt = true;
EXT_SPI_DMA_TX_Channel.Config.select = DMAREQ_USART2_TXBL;
EXT_SPI_DMA_TX_Channel.CallBack.cbFunc = (DMA_FuncPtr_TypeDef) BSP_SPI_TxDMAComplete;
EXT_SPI_DMA_TX_Channel.CallBack.userPtr = &EXT_SPI_Handle;
EXT_SPI_DMA_RX_Channel.ChannelId = EXT_SPI2_RX_DMA_CHANNEL;
EXT_SPI_DMA_RX_Channel.Config.highPri = false;
EXT_SPI_DMA_RX_Channel.Config.enableInt = true;
EXT_SPI_DMA_RX_Channel.Config.select = DMAREQ_USART2_RXDATAV;
EXT_SPI_DMA_RX_Channel.CallBack.cbFunc = (DMA_FuncPtr_TypeDef) BSP_SPI_RxDMAComplete;
EXT_SPI_DMA_RX_Channel.CallBack.userPtr = &EXT_SPI_Handle;
EXT_SPI_Handle.Link1 = (void*)&EXT_SPI_DMA_TX_Channel;
EXT_SPI_Handle.Link2 = (void*)&EXT_SPI_DMA_RX_Channel;
#else
#endif
EXT_SPI_Handle.TxDefaultData = 0xff; /* This is the default dummy value to be transmitted for read only operation from SPI slave,This value can be changed as per the interfacing hardware*/
return RETCODE_OK;
}
/* This API puts the SPI device into operational state */
{
Retcode_T retcode = RETCODE_OK;
/* Dont enable if the callback has not been registered */
if (NULL == EXT_SPI_Handle.IrqRxCallback || NULL == EXT_SPI_Handle.IrqTxCallback)
{
}
/*enable the clock for the USART interface*/
CMU_ClockEnable(EXT_SPI2_CLOCK, true);
/* Setting baudrate */
/* Using synchronous (SPI) mode*/
EXT_SPI2_PORT->CTRL = USART_CTRL_SYNC;
/* Enabling master mode SPI */
EXT_SPI2_PORT->CMD = USART_CMD_MASTEREN;
/* Clearing old transfers/receptions, and disabling interrupts */
EXT_SPI2_PORT->CMD = USART_CMD_CLEARRX | USART_CMD_CLEARTX;
/* Set Most Significant Bit First */
EXT_SPI2_PORT->CTRL |= USART_CTRL_MSBF;
/* Reset interrupt enable register */
EXT_SPI2_PORT->IEN = 0;
/* Clear interrupt flags */
EXT_SPI2_PORT->IFC = _USART_IFC_MASK;
/* Set interrupt priorities */
/* clear pending interrupts */
NVIC_ClearPendingIRQ(EXT_SPI_RX_IRQN);
NVIC_ClearPendingIRQ(EXT_SPI_TX_IRQN);
/* Assign the callback */
EXT_SPI_RxISRCallback = EXT_SPI_Handle.IrqRxCallback;
EXT_SPI_TxISRCallback = EXT_SPI_Handle.IrqTxCallback;
#if BCDS_FEATURE_DMA
EXT_SPI_RxDmaCallback = EXT_SPI_Handle.DmaRxCallback;
EXT_SPI_TxDmaCallback = EXT_SPI_Handle.DmaTxCallback;
#endif
NVIC_EnableIRQ(EXT_SPI_RX_IRQN);
NVIC_EnableIRQ(EXT_SPI_TX_IRQN);
return retcode;
}
/* This API disables the SPI device from its operational state */
{
Retcode_T retcode = RETCODE_OK;
/* Disable the USART clock*/
CMU_ClockEnable(EXT_SPI2_CLOCK, false);
NVIC_DisableIRQ(EXT_SPI_RX_IRQN);
NVIC_DisableIRQ(EXT_SPI_TX_IRQN);
EXT_SPI_RxISRCallback = NULL;
EXT_SPI_TxISRCallback = NULL;
return retcode;
}
/* This API disconnects the SPI interface and its pin will be in disable state */
{
GPIO_PinModeSet(EXT_SPI2_MISO_PORT, EXT_SPI2_MISO_PIN, gpioModeDisabled, 0);
GPIO_PinModeSet(EXT_SPI2_MOSI_PORT, EXT_SPI2_MOSI_PIN, gpioModeDisabled, 0);
GPIO_PinModeSet(EXT_SPI2_SCK_PORT, EXT_SPI2_SCK_PIN, gpioModeDisabled, 0);
GPIO_PinModeSet(EXT_SPI2_CS_PORT, EXT_SPI2_CS_PIN, gpioModeDisabled, 0);
CMU_ClockEnable(EXT_SPI2_CLOCK, true);
EXT_SPI2_PORT->ROUTE = _USART_ROUTE_RESETVALUE;
CMU_ClockEnable(EXT_SPI2_CLOCK, false);
return RETCODE_OK;
}
/* This API shall be called to give hardware SPI port reference to
HAL layer such that the read/write/configure is possible. Design is made in such a way that the SPI handle "MCU_SPI_Handle_S",
which is the forward declared struct at layer "Platform/HAL/include/mcu/efm32/BCDS_MCU_SPI_Handle.h"
is used by BSP, SPI application interface driver must fill Hardware related info in this structure */
/* note 1 HWHandle_T is the generic void pointer to hold address of the I2C handle, it is defined in "BCDS_HAL.h" */
/* note 2 This API need to be called in <b>SPI application interface driver</b> before calling BSP_SPI_Enable() API */
{
/*
* Initialize the Handle and return it back to the caller
*/
}
/* This API is to set the CS pin to low */
/* note It is done in the application file before calling the write api.*/
void BSP_SPI_SetCSLow(void)
{
GPIO_PinOutClear(EXT_SPI2_CS_PORT, EXT_SPI2_CS_PIN);
}
/* This API is to set the CS pin to high */
/* note It is done in the application file after the read operation is done.*/
{
}
/* This API is an SPI TX hardware ISR routine */
/* note: Do not change the name of this API as this is specific to MCU */
{
if (NULL != EXT_SPI_Handle.IrqTxCallback)
{
/* All UART interrupt processing is to be done at the MCU level */
}
}
/* This API is an SPI RX hardware ISR routine */
/* note: Do not change the name of this API as this is specific to MCU */
{
if (NULL != EXT_SPI_Handle.IrqRxCallback)
{
/* All UART interrupt processing is to be done at the MCU level */
}
}

The following example module is necessary to establish I2C communication

/*Global Declarations and include required for this module*/
#include "FreeRTOS.h"
#include "semphr.h"
#include "timers.h"
#include "BCDS_MCU_SPI.h"
#include "BCDS_Assert.h"
#include "BCDS_Wlan.h"
#define SPI_DATA_TRANSFER_TIMEOUT_MILLISEC UINT32_C(5000)
#define EXT_SPI_RW_SUCCESS INT8_C(0)
#define EXT_SPI_RW_FAILED INT8_C(-1)
/* semaphore unblocking completion of frame transmission*/
/* This API is an interrupt service handler routine for application , note this call happens in interrupt context.
the SPI driver in HAL is completely interrupt driven this callback is invoked once after the requested read/Write operation is completed */
static void HAL_SPI_AppCallback(SPI_T spi, struct MCU_SPI_Event_S event)
{
if (spiCompleteSync != NULL)
{
if ( (event.TxComplete) || (event.RxComplete) )
{
if (xSemaphoreGiveFromISR(spiCompleteSync, &xHigherPriorityTaskWoken) == pdTRUE)
{
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
}
}
else
{
}
if ((SPI_T) 0 == spi)
{
}
if (event.RxError)
{
}
if (event.TxError)
{
}
if (event.DataLoss)
{
}
}
/* This API initialize the SPI interface driver */
/* note This API has to be called first by the application code */
{
ret = BSP_SPI_Connect();
if (RETCODE_OK == ret)
{
if (NULL == spiCompleteSync)
{
spiCompleteSync = xSemaphoreCreateBinary();
if (NULL == spiCompleteSync)
{
}
}
if (NULL != spiCompleteSync)
{
spiHandle = BSP_SPI_GetHandle();
if (NULL != spiHandle)
{
ret = MCU_SPI_Initialize(spiHandle, HAL_SPI_AppCallback);
}
else
{
}
if (RETCODE_OK == ret)
{
ret = BSP_SPI_Enable();
}
}
}
return ret;
/* This API is the implementation reading over SPI bus. */
/* Return value for this function call can be user specific , int8_t is given for an example*/
int8_t HAL_SPI_Transfer_Read(uint8_t *pBuff, uint32_t len)
{
assert(pBuff != NULL);
int8_t UserRet = EXT_SPI_RW_FAILED;
if ((len > 0) && (spiCompleteSync != NULL))
{
ret = MCU_SPI_Receive(spiHandle, pBuff, len);
if (RETCODE_OK == ret)
{
if (pdFALSE == xSemaphoreTake(spiCompleteSync, SPI_DATA_TRANSFER_TIMEOUT_MILLISEC))
{
}
}
if (RETCODE_OK != ret)
{
UserRet = EXT_SPI_RW_FAILED;
}
else
{
UserRet = EXT_SPI_RW_SUCCESS;
}
}
return (UserRet);
}
/* This API is the implementation writing over SPI bus. */
/* Return value for this function call can be user specific , int8_t is given for an example*/
int8_t HAL_SPI_Transfer_Write(uint8_t *pBuff, uint32_t len)
{
assert(pBuff != NULL);
int8_t UserRet = EXT_SPI_RW_FAILED;
if ((len > 0) && (spiCompleteSync != NULL))
{
ret = MCU_SPI_Send(spiHandle, pBuff, len);
if (RETCODE_OK == ret)
{
if (pdFALSE == xSemaphoreTake(spiCompleteSync, SPI_DATA_TRANSFER_TIMEOUT_MILLISEC))
{
}
}
if (RETCODE_OK != ret)
{
UserRet = EXT_SPI_RW_FAILED;
}
else
{
UserRet = EXT_SPI_RW_SUCCESS;
}
}
return (UserRet);
}
/* This API is the implementation the de-initialization of SPI interface driver */
{
Retcode_T retcode = RETCODE_OK;
if (((SPI_T) NULL == spiHandle))
{
}
if (RETCODE_OK == retcode)
{
retcode = MCU_SPI_Deinitialize(spiHandle);
}
if (RETCODE_OK == retcode)
{
retcode = BSP_SPI_Disconnect();
}
if (RETCODE_OK == retcode)
{
if (NULL != spiCompleteSync)
{
vSemaphoreDelete(spiCompleteSync);
spiCompleteSync = NULL;
}
spiHandle = NULL;
}
return retcode;
}

Sample application to interface SPI device to XDK extension bus

The following is an example application for interfacing I2C with XDK via extension bus.

Note
1 The sensor used here for the sample application is BMA250FB
2 Please refer xdk110/Apps/ExtensionBusSPI for interfacing SPI with XDK via extension bus.
/* system header files */
#include <stdio.h>
/* additional interface header files */
#include "FreeRTOS.h"
#include "timers.h"
#include "HAL_SPI.h" /*Header file containing HAL interfaces*/
#include "BSP_SPI.h" /*Header file containing BSP interfaces */
void appInitSystem(void * CmdProcessorHandle, uint32_t param2)
{
BCDS_UNUSED(CmdProcessorHandle);
BCDS_UNUSED(param2);
uint8_t pBuff[2]={0x80,0xff};
Retcode_T returnVal = RETCODE_OK;
int8_t UserRet = EXT_SPI_RW_FAILED;
returnVal= HAL_SPI_Init();
if (returnVal == RETCODE_OK)
{
UserRet = HAL_SPI_Transfer_Write(&pBuff[0], 1);
if (EXT_SPI_RW_SUCCESS == UserRet)
{
/*Reading of chip id for BMA250FB sensor */
UserRet = HAL_SPI_Transfer_Read(&pBuff[1],1);
printf("SPI write and read successful \r\n");
}
if (EXT_SPI_RW_FAILED == UserRet)
{
printf("SPI write failed \r\n");
}
else
{
/* CS pin is set to high after read operation is complete */
}
}
else
{
printf("initialization of SPI failed \r\n");
}
}

UART sample application - Compatible to XDK workbench version V3.0.0 and above

This example outlines how to interface external UART device to XDK via extension Bus.

The below code snippet explains the c modules reqired

The following example module is necessary to establish proper connection to hardware for interfacing external UART device to XDK via extension bus.

/*Global Declarations and include required for this module*/
#include "em_gpio.h"
#include "em_cmu.h"
#include "BSP_UART.h" /* Header file containing BSP interface */
#define EXT_SERIAL_UART_PORT UART1
#define EXT_SERIAL_UART_CLOCK (cmuClock_UART1)
#define EXT_SERIAL_UART_RX_IRQN UART1_RX_IRQn
#define EXT_SERIAL_UART_TX_IRQN UART1_TX_IRQn
#define EXT_UART_RX_INTERRUPT_PRIORITY UINT32_C(5)
#define EXT_UART_TX_INTERRUPT_PRIORITY EXT_UART_RX_INTERRUPT_PRIORITY
#define EXT_UART_RX_PORT (gpioPortB)
#define EXT_UART_RX_PIN (10)
#define EXT_UART_RX_MODE (gpioModeInput)
#define EXT_UART_TX_PORT (gpioPortB)
#define EXT_UART_TX_PIN (9)
#define EXT_UART_TX_MODE (gpioModePushPullDrive)
static UART_IRQ_Callback_T EXT_UART_RxISRCallback;
static UART_IRQ_Callback_T EXT_UART_TxISRCallback;
struct MCU_UART_Handle_S EXT_UART_Handle;
/*
* enumeration of custom return codes
*/
{
};
/* This API shall only put the device pins configured/Connected but still not yet put into operation */
/* note This API shall be called once during the initialization routine of the user application */
{
CMU_ClockEnable(EXT_SERIAL_UART_CLOCK, true);
EXT_SERIAL_UART_PORT->ROUTE = UART_ROUTE_RXPEN | UART_ROUTE_TXPEN | UART_ROUTE_LOCATION_LOC2;
CMU_ClockEnable(EXT_SERIAL_UART_CLOCK, false);
return RETCODE_OK;
}
/* This API shall put the UART device into operation */
{
Retcode_T retcode = RETCODE_OK;
/* Dont enable if the callback has not been registered */
if (NULL == EXT_UART_Handle.IrqRxCallback || NULL == EXT_UART_Handle.IrqTxCallback)
{
}
if (RETCODE_OK == retcode)
{
/*
* Enable the UART MCU resource
*/
CMU_ClockEnable(EXT_SERIAL_UART_CLOCK, true);
/*
* Clear Pending Interrupt flags
*/
/* clear interrupt flags */
EXT_SERIAL_UART_PORT->IFC = _USART_IF_MASK;
/*
* Enable receive interrupt flags
*/
/* Enable the UART RX Not Empty Interrupt */
EXT_SERIAL_UART_PORT->IEN = USART_IEN_RXDATAV | USART_IEN_RXFULL | USART_IEN_RXOF | USART_IEN_FERR;
/*
* Associate the ISR callbacks
*/
EXT_UART_RxISRCallback = EXT_UART_Handle.IrqRxCallback;
EXT_UART_TxISRCallback = EXT_UART_Handle.IrqTxCallback;
/*
* Set the priority for the UART interface
*/
/*
* Clear Pending interrupt requests
*/
NVIC_ClearPendingIRQ(EXT_SERIAL_UART_RX_IRQN);
NVIC_ClearPendingIRQ(EXT_SERIAL_UART_TX_IRQN);
/*
* Enable the interrupt requests
*/
NVIC_EnableIRQ(EXT_SERIAL_UART_RX_IRQN);
NVIC_EnableIRQ(EXT_SERIAL_UART_TX_IRQN);
/* Enable the UART */
/*Enable transmitter and receiver*/
EXT_SERIAL_UART_PORT->CMD = (USART_CMD_RXEN | USART_CMD_TXEN);
/*
* Check if the USART has been enabled
*/
if (((EXT_SERIAL_UART_PORT->STATUS & _USART_STATUS_RXENS_MASK) == 0) || ((EXT_SERIAL_UART_PORT->STATUS & _USART_STATUS_TXENS_MASK) == 0))
{
}
}
return retcode;
}
/* This API disables the UART device operation */
{
Retcode_T retcode = RETCODE_OK;
/* Disable USART interface */
EXT_SERIAL_UART_PORT->CMD = USART_CMD_RXDIS | USART_CMD_TXDIS | USART_CMD_MASTERDIS;
/*
* Check if the USART has been disabled
*/
if (((EXT_SERIAL_UART_PORT->STATUS & _USART_STATUS_RXENS_MASK) != 0) || ((EXT_SERIAL_UART_PORT->STATUS & _USART_STATUS_TXENS_MASK) != 0))
{
}
if (RETCODE_OK == retcode)
{
NVIC_DisableIRQ(EXT_SERIAL_UART_RX_IRQN);
NVIC_DisableIRQ(EXT_SERIAL_UART_TX_IRQN);
EXT_UART_RxISRCallback = NULL;
EXT_UART_TxISRCallback = NULL;
}
return retcode;
}
/* This API disconnects the UART device from its operation */
{
GPIO_PinModeSet(EXT_UART_RX_PORT, EXT_UART_RX_PIN, gpioModeDisabled, 0);
GPIO_PinModeSet(EXT_UART_TX_PORT, EXT_UART_TX_PIN, gpioModeDisabled, 0);
CMU_ClockEnable(EXT_SERIAL_UART_CLOCK, true);
EXT_SERIAL_UART_PORT->ROUTE = _UART_ROUTE_RESETVALUE;
CMU_ClockEnable(EXT_SERIAL_UART_CLOCK, false);
return RETCODE_OK;
}
/* This API shall be called to give hardware UART port reference to
HAL layer such that the read/write/configure is possible. Design is made in such a way that the UART handle "MCU_UART_Handle_S",
which is the forward declared struct at layer "Platform/HAL/include/mcu/efm32/BCDS_MCU_UART_Handle.h"
is used by BSP, UART application interface driver must fill Hardware related info in this structure */
/* note 1 HWHandle_T is the generic void pointer to hold address of the UART handle, it is defined in "BCDS_HAL.h"/
/* note 2 This API need to be called in UART application interface driver before calling BSP_UART_Enable() API */
{
EXT_UART_Handle.Uart_ptr = UART1;
}
/*This API is an UART TX hardware ISR routine */
{
if (NULL != EXT_UART_Handle.IrqTxCallback)
{
/* All UART interrupt processing is to be done at the MCU level */
}
}
/* This API is an UART RX hardware ISR routine */
{
if (NULL != EXT_UART_Handle.IrqRxCallback)
{
/* All UART interrupt processing is to be done at the MCU level */
}
}

The following example module is necessary to establish UART communication

/* Global Declarations and include required for this module*/
#include "FreeRTOS.h"
#include "semphr.h"
#include "task.h"
#include "BCDS_HAL.h"
#include "BCDS_MCU_UART.h"
#include "em_gpio.h"
#include "em_cmu.h"
#include "HAL_UART.h" /*Header file containing HAL interface*/
#include "BSP_UART.h" /*Header file containing BSP interface*/
#define UART_SEMAPHORE_TAKE_TIMEOUT_IN_MS UINT32_C(1000)
#define EXT_UART_TX_RX_SUCCESS INT8_C(0)
#define EXT_UART_TX_RX_FAILED INT8_C(-1)
/* UART Handle used by the UART driver in HAL/MCU */
/* currently received byte */
static uint8_t receivedByte;
/*
* This function will be called from UART ISR context to handle UART events
* Callback prototype see HAL MCU:
* typedef void (*MCU_UART_Callback_T)(UART_T uart, struct MCU_UART_Event_S event);
*/
static void HAL_UART_Events(UART_T uart, struct MCU_UART_Event_S event);
/* semaphore unblocking completion of frame transmission*/
/*
* enumeration of custom return codes
*/
{
};
/* This API handles the event from the HAL/UART in this driver */
static void HAL_UART_Events(UART_T uart, struct MCU_UART_Event_S event)
{
Retcode_T retcode = RETCODE_OK;
BCDS_UNUSED(uart);
int datareceived;
if (event.RxComplete)
{
/* In this example the data received is just collected , user can process the data in which ever way he wants.
* For an instance the user can use ring buffer to collect data and trigger the registered user callback on completing the
* reception */
datareceived = receivedByte;
}
if (event.TxComplete) /* data has been sent */
{
BaseType_t higherPriorityTaskWoken = pdFALSE;
if (NULL != TxSendSync)
{
if (pdTRUE == xSemaphoreGiveFromISR(TxSendSync, &higherPriorityTaskWoken))
{
portYIELD_FROM_ISR(higherPriorityTaskWoken);
}
else
{
/* ignore... semaphore has already been given */
}
}
else
{
}
}
#ifndef NDEBUG
else if (event.RxError)
{
}
if (RETCODE_OK != retcode)
{
}
#else /* #ifndef NDEBUG */
BCDS_UNUSED(retcode);
#endif /* #ifndef NDEBUG */
}
/* This API initialize the UART interface driver */
/* note This API has to be called first by the application code */
{
Retcode_T retcode = RETCODE_OK;
TxSendSync = xSemaphoreCreateBinary();
if (NULL == TxSendSync)
{
}
/*assuming BSP_Board_Initialize() having been called appropriately before
Establish physical connection */
retcode = BSP_UART_Connect();
if (RETCODE_OK == retcode)
{
/*Get the serial uart handle*/
UartHandle = BSP_UART_GetHandle();
if (0 != UartHandle)
{
retcode = MCU_UART_Initialize(UartHandle, HAL_UART_Events);
}
else
{
}
}
return retcode;
}
/* This API is the implementation the de-initialization of UART interface driver */
{
Retcode_T retcode = RETCODE_OK;
if (NULL == UartHandle)
{
}
if (RETCODE_OK == retcode)
{
retcode = MCU_UART_Deinitialize(UartHandle);
}
if (RETCODE_OK == retcode)
{
retcode = BSP_UART_Disconnect();
}
if (RETCODE_OK == retcode)
{
if (NULL != TxSendSync)
{
vSemaphoreDelete(TxSendSync);
TxSendSync = NULL;
}
UartHandle = NULL;
}
return retcode;
}
/* This API is the implementation for enabling the UART for receiving */
{
rc = BSP_UART_Enable();
if (RETCODE_OK == rc)
{
/* start the receive process, this will enable UART interrupts and trigger a callback on receiving each byte on serial UART line */
rc = MCU_UART_Receive(UartHandle, &receivedByte, 1UL);
}
return rc;
}
/* This API is the implementation for enabling the UART for receiving */
Retcode_T HAL_UART_Tx_Data(uint8_t* data, uint16_t dataLength)
{
uint32_t writtenBytes = 0;
if (NULL == data)
{
}
else if (0 < dataLength)
{
if (0 != UartHandle)
{
rc = MCU_UART_Send(UartHandle, data, dataLength);
if (RETCODE_OK == rc)
{
{
/* see Event TxComplete in EXT_UART_Events (HAL ISR user callback) */
writtenBytes = dataLength;
}
else
{
}
}
}
else
{
}
}
else
{
}
return rc;
}

Sample application to interface UART device to XDK extension bus

The following is an example application for interfacing UART to XDK via extension bus for echoing the data.

Note
Please refer xdk110/Apps/ExtensionBusUART for interfacing UART with XDK via extension bus.
/* system header files */
#include <stdio.h>
/* additional interface header files */
#include "BCDS_HAL.h"
#include "FreeRTOS.h"
#include "timers.h"
#include "HAL_UART.h" /*Header file containing HAL interfaces*/
#include "BSP_UART.h" /*Header file containing BSP interfaces */
#include "BCDS_Assert.h"
static void processUartrxData(void * param1, uint32_t recvStatus)
{
Retcode_T returnVal = RETCODE_OK;
BCDS_UNUSED(recvStatus);
returnVal = HAL_UART_Tx_Data((uint8_t*) param1, 1);
if (returnVal != RETCODE_OK)
{
printf("Enabling the UART for receiving failed \r\n");
}
}
void processdata1(uint8_t*process)
{
uint8_t data = *process;
Retcode_T returnValue = RETCODE_OK;
returnValue = CmdProcessor_enqueueFromIsr(AppCmdProcessorHandle, processUartrxData, &data, 1);
if (RETCODE_OK != returnValue)
{
printf("Enqueuing for receive UART data callback failed \r\n");
}
}
void appInitSystem(void * CmdProcessorHandle, uint32_t param2)
{
if (CmdProcessorHandle == NULL)
{
printf("Command processor handle is null \r\n");
assert(false);
}
AppCmdProcessorHandle = (CmdProcessor_T *) CmdProcessorHandle;
BCDS_UNUSED(param2);
Retcode_T returnVal = RETCODE_OK;
if (returnVal == RETCODE_OK)
{
returnVal = HAL_UART_Enable_Rx();
}
if (returnVal != RETCODE_OK)
{
printf("Enabling the UART for receiving failed \r\n");
}
}

User guide for extension GPIO - Compatible to XDK workbench version V3.0.0 and above

This section give an example on the usage of the GPIO's avaiable in the extension Bus

Currently the implementation is availabe in the module BSP/source/BSP_Extension_Gpio.c.and its interface in file Essentials/include/bsp/BCDS_BSP_Extension_Gpio.h
But this implementation is not extendable to add new GPIO support, so the user has to do the changes as described below if they want to configure the GPIO according to their requirement.

The below example describes the usage of confguring Extension Bus GPIO PA1(Port A - Pin 1) as Input and GPIO PE2 (Port E - Pin 2) as output.

Example application for extension GPIO

The implementation uses these pins defined above in the application layer by using the apis from Essentials/include/mcu/BCDS_MCU_GPIO.h and from Essentials/include/bsp/BCDS_BSP_Extension_Gpio.h for establishing the connections as well as for varying the level of the pins.

The sample application explains the usage of the api's from Essentials/include/bsp/BCDS_BSP_Extension_Gpio.h and Essentials/include/mcu/BCDS_MCU_GPIO.h.

void appInitSystem(void * CmdProcessorHandle, uint32_t param2)
{
BCDS_UNUSED(CmdProcessorHandle);
BCDS_UNUSED(param2);
MCU_GPIO_PinState_T gpiolevel =0;
/* initialize local variables */
Retcode_T ReturnValue = RETCODE_OK;
/* Set the mode and value for a GPIO pin */
ReturnValue = BSP_Extension_Gpio_Connect(BSP_GPIO_EXT_GPIO_PA1_INPUT);/* for enabling the Extension GPIO Pins based on the id */
if (ReturnValue != RETCODE_OK)
{
printf("Enabling of the Extension GPIO pin PA1 failed \r\n");
}
ReturnValue = BSP_Extension_Gpio_Connect(BSP_GPIO_EXT_GPIO_PE2_OUTPUT);/* for enabling the Extension GPIO Pins based on the id */
if (ReturnValue != RETCODE_OK)
{
printf("Enabling of the Extension GPIO pin PE2 failed \r\n");
}
/* Set data out register for the pin to 1 */
ReturnValue = MCU_GPIO_WritePin((GPIO_T) &BSP_Extension_GPIO_PortE_Pin2, MCU_GPIO_PIN_STATE_HIGH);/* modifies the output level of a GPIO pin from the GPIO perspective */
if (ReturnValue != RETCODE_OK)
{
printf("Data out register not set to 1 \r\n");
}
/*reading the pin */
ReturnValue = MCU_GPIO_ReadPin((GPIO_T) &BSP_Extension_GPIO_PortA_Pin1, &gpiolevel );
if (ReturnValue != RETCODE_OK)
{
printf("Reading of input pin failed \r\n");
}
}

Software example

Led Blink sample application - Compatible to XDK workbench version V2.0.1 and below

This example outlines, how to realize LED blinking functionality on the XDK Extension Bus.

void extensionLedTask(void)
{
/* initialize local variables */
int count = 0;
const TickType_t xDelay = 1000; /* portTICK_PERIOD_MS */
/* Initialization activities for PTD driver */
PTD_portInit();
/* Set the mode and value for a GPIO pin */
PTD_pinModeSet(PTD_PORT_EXTENSION_GPIO_IN_OUT_0, PTD_PIN_EXTENSION_GPIO_IN_OUT_0,PTD_MODE_EXTENSION_GPIO_IN_OUT_0, PTD_DOUT_EXTENSION_GPIO_IN_OUT_0);
/* blinking functionality */
while(count < 10)
{
/* Set data out register for the pin to 1 */
PTD_pinOutSet(PTD_PORT_EXTENSION_GPIO_IN_OUT_0, PTD_PIN_EXTENSION_GPIO_IN_OUT_0);
vTaskDelay( xDelay ); // use suitable delay API. This delay API is for demo only.
/* Set data out register for the pin to 0 */
PTD_pinOutClear(PTD_PORT_EXTENSION_GPIO_IN_OUT_0,PTD_PIN_EXTENSION_GPIO_IN_OUT_0);
vTaskDelay( xDelay ); // use suitable delay API. This delay API is for demo only.
count++;
}
}

UART sample application - Compatible to XDK workbench version V2.0.1 and below

This example outlines, how to configure the UART on the extension bus of XDK.

The following steps are needed to configure in the software after External Hardware setup done.

1) UART1 Module Clock has to be enabled before calling SER_serialInit API as shown in the example below.

2) Initialize the Serial UART init parameters as given in the below example Please note that these structure members hwType,hwDevicePort,protocol and routeLocation values must not to be changed by the user

3) TX buffer size and RX buffer size has to be modified as per the need of the application.Violating this may lead to undesired behaviour

Note
GPIO pin configuration details can be found at "PTD_portDriver_ph.h" under the installed path C:-Workbench\SDK\Common\config\HW_XDK_v1\PTD_portDriver_ph.h.
/* Initializing serial init parameters */
static SER_init_t uartInit =
{
.hwType = SER_HWTYPE_UART,
.hwDevicePort = SER_UART1,
.protocol = SER_UART_PROTOCOL,
.baudRate = 115200,
.hasHwFlowControl = false,
.txBuf_p = ser2TxBuf_ma,
.txBufSize = 20,
.rxBuf_p = ser2RxBuf_ma,
.rxBufSize = 20,
.parity = SER_PARITY_NONE,
.dataBits = SER_DATABITS_8,
.stopBits = SER_STOPBITS_ONE,
.routeLocation = SER_ROUTE_LOCATION2,
.txCallback = NULL,
.rxCallback = NULL,
.rtsPort = 0,
.rtsPin = 0,
.rtspolarity = SER_activeLow,
.ctsPort = 0,
.ctsPin = 0,
.ctspolarity = SER_activeLow
};
void ExtensionUARTTask(void)
{
(void) (xTimer);
/* Initialize the local variables */
uint8_t writeBuf[TX_BUFFER_SIZE];
uint8_t readBuf[RX_BUFFER_SIZE];
uint32_t reminingBytes;
/* Enable the UART clock */
CMU_ClockEnable(cmuClock_UART1, true);
/* Set the mode for a GPIO pin for UART control Signals */
PTD_pinModeSet(PTD_GET_PORT_PIN_MODE_DOUT(EXTENSION_UART1_TX));
PTD_pinModeSet(PTD_GET_PORT_PIN_MODE_DOUT(EXTENSION_UART1_RX));
/* Initialize the Serial UART with the Configured parameters */
SER_serialInit((SER_device_t*) &uartHandle,(SER_init_t*) &uartInit);
while (1)
{
readBuf[0] = 0; //This buffer is for clearing the previous data
/* Reading back the data form the readbuffer */
SER_serialRead(&uartHandle, &reminingBytes, readBuf, 1);
if (readBuf[0] == 'S') /* Enter character 'S' from the Hterm side */
{
/* Writing some data into the buffer */
sprintf(writeBuf, "Print 'S'for success \r\n");
SER_serialWrite(&uartHandle, NULL, writeBuf, 20);
}
if (readBuf[0] == 'F') /* Enter character 'F' from the Hterm side */
{
/* Writing some data into the buffer */
sprintf(writeBuf, "Print 'F' for failure\r\n");
SER_serialWrite(&uartHandle, NULL, writeBuf, 20);
}
}
}

SPI sample application - Compatible to XDK workbench version V2.0.1 and below

This example outlines, how to configure the SPI on the extension bus of XDK.

The following steps are needed to configure SPI in the software after external Hardware setup done.

1) Initialize the SPI init parameters as given in the below example Please note that these structure members portNumber and routeLocation values must not to be changed by the user

2) TX buffer size and RX buffer size has to be modified as per the need of the application.Violating this may lead to undesired behaviour

Note
GPIO pin configuration details can be found at "PTD_portDriver_ph.h" under the installed path C:-Workbench\SDK\Common\config\HW_XDK_v1\PTD_portDriver_ph.h.
void ExtensionSPITask(void)
{
/* Initialize local variables */
SPI_initParams_t initParams;
SPI_device_t spiHandle;
uint8_t txBuf[50] = { 0 };
uint8_t rxBuf[50] = { 0 };
uint8_t writeBuf[50] = { 0 };
uint8_t readBuf[50];
/* Set the mode for a GPIO pin for SPI control Signals */
PTD_pinModeSet(PTD_GET_PORT_PIN_MODE_DOUT(EXTENSION_US2_MOSI));
PTD_pinModeSet(PTD_GET_PORT_PIN_MODE_DOUT(EXTENSION_US2_MISO));
PTD_pinModeSet(PTD_GET_PORT_PIN_MODE_DOUT(EXTENSION_US2_CS));
PTD_pinModeSet(PTD_GET_PORT_PIN_MODE_DOUT(EXTENSION_US2_SCK));
/* Selecting the SPI Port number, Clock mode, Route location and Baudrate */
initParams.portNumber = SPI2; /* SPI port number */
initParams.clockMode = SPI_CLOCK_MODE_CPOL0_CPHA0; /* SPI mode configuration */
initParams.routeLocation = SPI_ROUTE_LOCATION1; /* SPI Route location fixed */
initParams.txBuf_p = txBuf; /* Pointer to the buffer that is to be used as the serial device's holds bytes that are to be transmitted.*/
initParams.rxBuf_p = rxBuf; /* Pointer to the circular buffer that holds the bytes received by the driver */
initParams.txBufSize = 50; /* Capacity in bytes of the transmit buffer */
initParams.rxBufSize = 50; /* Capacity in bytes of the Receive buffer */
initParams.baudrate = 2000000; //here setting the baudrate to 2Mhz
/* Initialize the SPI with valid parameters */
SPI_init(&spiHandle, &initParams);
/* Functionality to explain the write and read with External hardware */
while (1)
{
readBuf[0] = 0; /* This buffer is for clearing the Previous data */
/* Writing some data into the buffer */
writeBuf[0] = 0x80;
/* Enabling the SPI Chip select */
PTD_pinOutClear(PTD_PORT_EXTENSION_US2_CS, PTD_PIN_EXTENSION_US2_CS);
SPI_write(&spiHandle, writeBuf, 1, 1); /* Transmitting the data */
SPI_read(&spiHandle, readBuf, 1); /* Reading the Corresponding data */
/* Disabling the SPI Chip select */
PTD_pinOutSet(PTD_PORT_EXTENSION_US2_CS, PTD_PIN_EXTENSION_US2_CS);
}
}

All rights reserved. The use is subject to the XDK SDK EULA by Bosch Connected Devices and Solutions GmbH.
This documentation file has been automatically generated on Thu Sep 7 2017 01:13:11 by doxygen 1.8.8