I have been tracing down a bug where we loose communications on our USB BULK_OUT pipe (in from PC host) after several transitions in and out of VLPS and RUN modes. I finally was able to catch it with a debugger and it seems that the code is getting stuck in a while loop waiting for the ADC COCO bit to be set.
The code is as follows:
volatile uint16_t dummyRead = ADC0_RA;
ADC0_SC1A = ADC_SC1_ADCH(channel) ; // start conversion
while(!(ADC0_SC1A & ADC_SC1_COCO_MASK));
dummyRead = ADC0_RA;
return dummyRead;
I had looked at the ADC registers and saw nothing suspicious.
So, I looked at the KL25 Reference Manual and I found a subsection under ADC that states the ADC is reset upon exit from Low Power Stop.
So, I made a new build that reinitialized the ADC after coming out of VLPS, but before reenabling interrupts.
I ran with this code, but it seems like it is still hanging. Has anyone had any similar problems before?
Thanks.