Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

XMC™ Forum Discussions

Not applicable
Hello everyone,

I'm still struggling with the UART(printf() style debugging).
I want to setup an UART connection using the XMClib( NO Dave APPS)
I found an UART example for the XMC1200 kit(UART_XMC_Lib_XMC12), i tried to adapt the example to the XMC4200 series but still there is no output.
Will i be able to see the output in dave or do i need another program(TeraTerm) to see the output?
In the example, the TX pin is configured as XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT7. i'm unable to use ALT7 so i used ALT4, does this makes any difference?

/* SFR declarations of the selected device */
#include
#include "GPIO.h"
#include
#include


#define UART_RX P1_4
#define UART_TX P1_5
#define LED1 P2_1
#define KNOP1 P14_7
#define TICKS_PER_SECOND 10000
#define TICKS_WAIT 1000
const uint8_t message[] = "hello world\n";



/*UART CONFIG*/
const XMC_UART_CH_CONFIG_t uart_config =
{
.data_bits = 8U,
.stop_bits = 1U,
.baudrate = 115200
};


unsigned long timingdelay, adc_result;

void ADC0_Init(void);
void Delay100US (unsigned long time);
void SysTick_Handler(void);

int main(void) {

/* Setup the system timer to tick every 100us */
SysTick_Config(SystemCoreClock / TICKS_PER_SECOND);

/*conf uart channel */
XMC_UART_CH_Init(XMC_UART0_CH0, &uart_config);
XMC_UART_CH_SetInputSource(XMC_UART0_CH0, XMC_UART_CH_INPUT_RXD, USIC0_C0_DX0_P1_4);

/*start uart channel*/
XMC_UART_CH_Start(XMC_UART0_CH0);

/*config pins */

XMC_GPIO_CONFIG_t configTX;
configTX.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT4;/*must be ALT7?????*/
XMC_GPIO_Init(UART_TX, &configTX);

XMC_GPIO_CONFIG_t configRX;
configRX.mode = XMC_GPIO_MODE_INPUT_TRISTATE;
XMC_GPIO_Init(UART_RX, &configRX);

/*XMC_GPIO_SetMode(UART_TX,XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT4); must be alt7???*/
/*XMC_GPIO_SetMode(UART_RX,XMC_GPIO_MODE_INPUT_TRISTATE );*/
/*XMC_GPIO_SetMode(LED1, XMC_GPIO_MODE_OUTPUT_PUSH_PULL);*/
/*XMC_GPIO_SetMode(P14_7,XMC_GPIO_MODE_INPUT_TRISTATE);*/ /*doesn't work for pushbutton?*/

XMC_GPIO_CONFIG_t configOUTPUT;
configOUTPUT.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL;
configOUTPUT.output_level = XMC_GPIO_OUTPUT_LEVEL_HIGH;
configOUTPUT.output_strength = XMC_GPIO_OUTPUT_STRENGTH_MEDIUM;
XMC_GPIO_Init(LED1,&configOUTPUT);

XMC_GPIO_CONFIG_t configINPUT;
configINPUT.mode = XMC_GPIO_MODE_INPUT_TRISTATE;
XMC_GPIO_Init(KNOP1, &configINPUT);

while(1)
{
/*loop*/

if(XMC_GPIO_GetInput(KNOP1)==0)
{
XMC_GPIO_ToggleOutput(LED1);
Delay100US(5000);
}
}

}


/*
*/
/**
* @brief Inserts a delay time based on system timer configuration\n
*
* @param[in] Time Specifies the delay time length, in 100 micro seconds multiples\n
* @return none\n
*
* Reentrancy: no

*
*/
void Delay100US (unsigned long time)
{
timingdelay = time;
while (timingdelay != 0); //timingdelay is modified upon a system timer overflow in SysTick_Handler routine
}

/**
* @brief SysTick_Handler is called after every System Timer overflow \n
*
* @param[in] none\n
* @return none\n
*
* Reentrancy: no

*
*/
void SysTick_Handler (void) // SysTick Interrupt Handler
{
uint32_t index;
static uint32_t ticks = 0;
ticks++;

if(ticks == TICKS_WAIT)
{
for(index = 0; index < sizeof(message) - 1; index++)
{
XMC_UART_CH_Transmit(XMC_UART0_CH0, message[index]);
}
ticks = 0;
}

if(timingdelay != 0x00){
timingdelay--; //Decrease the time counter timingdelay
}

}





Could somebody please help me solve this issue, i'm now already struggling for 3 weeks with this issue...
Thanks to everyone
0 Likes
5 Replies
jferreira
Employee
First like received 750 replies posted 500 replies posted
Employee
Hi,

Have a look at the examples included in the XMCLib, http://dave.infineon.com/Libraries/XMCLib/XMC_Peripheral_Library_v2.1.16.zip

Regards,
Jesus
0 Likes
Not applicable
Hello everyone,

after 3 weeks, i was able to resolve this issue by myself.
The alternative pin function had to be 2 instead of 4...
So this line of code had to be changed:

configTX.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT2;


There is little information about this...
The help from the infineon team isn't worth it at all.
Since they only say: have a look at the examples.
Since there was no UART example for the XMC4200, i started with the UART example from the XMC4500.
My error was hardware related and took me a lot of time to find out in the datasheets.
After all i did learn a lot from this error.
Thanks to everyone.
User15757
Level 1
First like received 5 replies posted First question asked
Level 1
Hey, can you guys please give guidance as how to configure the XMC 4200 for UART communication? The examples and documentation for seem to be for micro controllers other than the XMC 4200, how did you get this to run?

I am using the distance2go board with the XMC 4200 Microcontroller. When I tried this myself, upon compilation, i receive the error "J-Link GDB Server failed: Could not listen no the tcp port." Clearly some port definitions are wrong?

Appreciate any help!

Zain
DRubeša
Employee
First solution authored First like received
Employee
I´ve provided the answer to another thread you opened (I´ve made the example for the XMC4200 CPU board so you may need to change pin layout). The issue that you see with the J-Link is not caused by the UART example but by the J-Link itself so a cause can be more than one thing but I would suggest to see if you have installed SEGGER J-link driver at the first place and how does your debug configuration window looks like...it should be something like this below:

3279.attach

Best regards,
Deni
0 Likes
User17104
Level 1
First like received First question asked First reply posted
Level 1
Hi, reyntjensm

I was trying to use your code on my distance2go kit but unfortunately it does not work.
Did you have change anything else on your code?
this is my code:
#include "config_error.h"
#include "defines.h"
#include "fw_version.h"
#include "Protocol.h"

#include "EndpointRadarBase.h"
#include "EndpointRadarADCXMC.h"
#include "EndpointRadarDoppler.h"
#include "EndpointRadarIndustrial.h"
#include "EndpointCalibration.h"
#include "EndpointTargetDetection.h"
#include
#include

#define TICKS_PER_SECOND 1000
#define TICKS_WAIT 1000


const uint8_t message[] = "Hello world!!\n";
#define KNOP1 P14_7
#define LED1 P2_1
#define UART_TX P1_5
#define UART_RX P1_4
/*
uint16_t firmware_version[3] =
{
FW_VERSION_MAJOR,
FW_VERSION_MINOR,
FW_VERSION_REVISION
};

Firmware_Information_t firmware_information =
{
"Distance2Go BGT24MTR11 Demo Radar Board",
FW_VERSION_MAJOR,
FW_VERSION_MINOR,
FW_VERSION_REVISION
};
XMC_GPIO_CONFIG_t uart_tx =
{
.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT2,
.output_strength = XMC_GPIO_OUTPUT_STRENGTH_MEDIUM
};

XMC_GPIO_CONFIG_t uart_rx =
{
.mode = XMC_GPIO_MODE_INPUT_TRISTATE
};

XMC_GPIO_CONFIG_t led =
{
.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL,
.output_strength = XMC_GPIO_OUTPUT_STRENGTH_MEDIUM
};*/

XMC_UART_CH_CONFIG_t uart_config =
{
.data_bits = 8U,
.stop_bits = 1U,
.baudrate = 115200U
};

//====================== Radar Base API ============================

Radar_Handle_t h_radar_device;

Device_Info_t s_device_info;

Frame_Info_t s_frame_info;

/*
==============================================================================
3. MAIN METHOD
==============================================================================
*/
unsigned long timingdelay, adc_result;
void ADC0_Init(void);
void Delay100US (unsigned long time);
void SysTick_Handler(void);


int main(void)
{
DAVE_STATUS_t status;

dma_init(); // need to call before Dave_Init() to set DMA controller

//-------------------------------------------------------------------------------

status = DAVE_Init(); // Initialization of DAVE APPs

if(status != DAVE_STATUS_SUCCESS)
{
// Placeholder for error handler code. The while loop below can be replaced with an user error handler.

XMC_DEBUG("DAVE APPs initialization failed\n");

while(1U)
{

}
}
/* Setup the system timer to tick every 100us */
SysTick_Config(SystemCoreClock / TICKS_PER_SECOND);

/*conf uart channel */
XMC_UART_CH_Init(XMC_UART0_CH0, &uart_config);
XMC_UART_CH_SetInputSource(XMC_UART0_CH0, XMC_UART_CH_INPUT_RXD, USIC0_C0_DX0_P1_4);

/*start uart channel*/
XMC_UART_CH_Start(XMC_UART0_CH0);

/*config pins */

XMC_GPIO_CONFIG_t configTX;
configTX.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT2;
XMC_GPIO_Init(UART_TX, &configTX);

XMC_GPIO_CONFIG_t configRX;
configRX.mode = XMC_GPIO_MODE_INPUT_TRISTATE;
XMC_GPIO_Init(UART_RX, &configRX);

XMC_GPIO_CONFIG_t configOUTPUT;
configOUTPUT.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL;
configOUTPUT.output_level = XMC_GPIO_OUTPUT_LEVEL_HIGH;
configOUTPUT.output_strength = XMC_GPIO_OUTPUT_STRENGTH_MEDIUM;
XMC_GPIO_Init(LED1,&configOUTPUT);

XMC_GPIO_CONFIG_t configINPUT;
configINPUT.mode = XMC_GPIO_MODE_INPUT_TRISTATE;
XMC_GPIO_Init(KNOP1, &configINPUT);

while(1)
{
/*loop*/

if(XMC_GPIO_GetInput(KNOP1)==0)
{
XMC_GPIO_ToggleOutput(LED1);
Delay100US(5000);
}
}

/* Send a message via UART periodically */

while(1)
{

}
//-------------------------- open device and init radar base API ------------------------------

radar_open_device(0, &h_radar_device);

radar_get_device_info(h_radar_device, &s_device_info);

Endpoint_t endpoint_list[] =
{
EP_RADAR_BASE_ENDPOINT_LIST_ENTRY(h_radar_device),

EP_RADAR_ADCXMC_ENDPOINT_LIST_ENTRY(h_radar_device),

EP_RADAR_DOPPLER_ENDPOINT_LIST_ENTRY(h_radar_device),

EP_RADAR_INDUSTRIAL_ENDPOINT_LIST_ENTRY(h_radar_device),

EP_CALIBRATION_ENDPOINT_LIST_ENTRY(h_radar_device),

EP_TARGET_DETECTION_ENDPOINT_LIST_ENTRY(h_radar_device)
};

protocol_init(endpoint_list, sizeof(endpoint_list)/sizeof(Endpoint_t), SYSTIMER_GetTime, HOST_TIME_OUT, system_reset);

algo_init();

radar_start();

while(1U)
{
if (g_usb_init == true)
{
protocol_run();
}
else
{
usb_init(1);
}
}
}

void SysTick_Handlerr (void) // SysTick Interrupt Handler
{
uint32_t index;
static uint32_t ticks = 0;
ticks++;

if(ticks == TICKS_WAIT)
{
for(index = 0; index < sizeof(message) - 1; index++)
{
XMC_UART_CH_Transmit(XMC_UART0_CH0, message[index]);
}
ticks = 0;
}

if(timingdelay != 0x00){
timingdelay--; //Decrease the time counter timingdelay
}

}
void Delay100US (unsigned long time)
{
timingdelay = time;
while (timingdelay != 0); //timingdelay is modified upon a system timer overflow in SysTick_Handler routine
}

tnx'

Meni
0 Likes