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

cross mob
Level 2
Level 2
I encountered a problem with our project, when enabling Code Optimization (O1). Our ADC_initialize() Function causes the device to go to the default Handler.
The function only consists of XMC Library functions.

This is what the function looks like:

void ADC_initialize(void)
/* Global Init */
XMC_VADC_GLOBAL_Init(VADC, &ADC_Global_handle);

XMC_VADC_GLOBAL_BackgroundInit(VADC, &ADC_Background_handle);

/* Init Group 0: Channel and Backgroung Request*/
XMC_VADC_GROUP_Init(ADC_Group_0, &ADC_Group_handle);

XMC_VADC_GROUP_ChannelInit(ADC_Group_0, 7, &ADC_G0CH7_config);
XMC_VADC_GROUP_ChannelInit(ADC_Group_0, 6, &ADC_G0CH6_config);
XMC_VADC_GROUP_ChannelInit(ADC_Group_0, 5, &ADC_G0CH5_config);
XMC_VADC_GROUP_ChannelInit(ADC_Group_0, 4, &ADC_G0CH4_config);
XMC_VADC_GROUP_ChannelInit(ADC_Group_0, 3, &ADC_G0CH3_config);
XMC_VADC_GROUP_ChannelInit(ADC_Group_0, 0, &ADC_G0CH0_config);

XMC_VADC_GLOBAL_BackgroundAddChannelToSequence(VADC, 0, 0);
XMC_VADC_GLOBAL_BackgroundAddChannelToSequence(VADC, 0, 3);
XMC_VADC_GLOBAL_BackgroundAddChannelToSequence(VADC, 0, 4);
XMC_VADC_GLOBAL_BackgroundAddChannelToSequence(VADC, 0, 5);
XMC_VADC_GLOBAL_BackgroundAddChannelToSequence(VADC, 0, 6);
XMC_VADC_GLOBAL_BackgroundAddChannelToSequence(VADC, 0, 7);

/* Init Group 1: Channel and Backgroung Request */
XMC_VADC_GROUP_Init(ADC_Group_1, &ADC_Group_handle);

XMC_VADC_GROUP_ChannelInit(ADC_Group_1, 0, &ADC_G1CH0_config);
XMC_VADC_GROUP_ChannelInit(ADC_Group_1, 1, &ADC_G1CH1_config);
XMC_VADC_GROUP_ChannelInit(ADC_Group_1, 6, &ADC_G1CH6_config);

XMC_VADC_GLOBAL_BackgroundAddChannelToSequence(VADC, 1, 0);
XMC_VADC_GLOBAL_BackgroundAddChannelToSequence(VADC, 1, 1);
XMC_VADC_GLOBAL_BackgroundAddChannelToSequence(VADC, 1, 6);

/* Enable Background Conversion */

By leaving out single functions I could figure out that the function call XMC_VADC_GLOBAL_INIT() will cause the error, and inside this function the call to XMC_VADC_GLOBAL_EnableModule().

Without the code optimization the program works.
Also, when I go through the main step by step with a debugger and I step over the ADC_initialize function, the code works. This must be some kind of timing problem.

Is this an error by the XMC library? Any suggestions to fix this?

Edit: Okay fixed it. Problem was that we called an ADC function, some time after the initialization. But we have to wait 200us after initialization. Without code optimization it worked because the code took long enough.
I added a for loop which fixes the problem.
0 Replies