Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 3 months ago.
nRF51822 wait() hangs
Hi,
I'm working with nRF51822-EK for development, but in the product I won't use external 32kHz crystal and replace it with synthesized from 16MHz crystal 32kHz clock source. And here is a problem: if I use wait() function with external 32kHz crystal connected then it works, but if I disconnecting external crystal then my program hangs on wait() function. How did this function implemented for nRF51822? Here is example code:
#include "mbed.h" DigitalOut led1(LED1); DigitalOut led2(LED2); int main(void) { led1 = 1; wait(0.1); led2 = 1; while(1); }
Led1 is lit and led2 is never lit if there is wait() function.
Question relating to:
2 Answers
10 years, 3 months ago.
Hi,
Exactly the same, on my pcb with a chip version QFAACO, have you tried to have an external 32kHz crystal on?
Regards Klaus
10 years, 3 months ago.
Hi Nikita,
I got the similar situation. I have several nRF51822 boards. Some hang in wait() function, some are OK. It seems that TIMERs of some nRF51822 MCUs are broken . A hardware issue.
In the function - us_ticker_init() of us_ticker.c
US_TICKER_TIMER->POWER = 0; US_TICKER_TIMER->POWER = 1;
For these broken nRF51822 MCUs, US_TICKER_TIMER->POWER remains 0 after calling us_ticker_init() function : (
Best, Yihui
In the reference manual v2.1, there is no POWER register in the TIMER : ( TIMER->POWER related code should be removed... makes me crazy!
posted by 01 Sep 2014Use mbed-src to test the us ticker RTC implementation. It should not drive you crazy :)
posted by 01 Sep 2014Thanks, Yihui!
I forgot to check chip revision.
I have nRF51822-EK with QFAAGC chip revision and it works.
And I have my custom board with QFAAC0 revision and it hangs.
It seems that in mbed SDK there is code somewhere that is not adapted to the problems described in product anomaly notice.
For me mbed-src is not working, it hangs on wait() even with QFAAG0 chip. Though I'll try it one more time, maybe I mistook something and it actually works.
UPD:
Now mbed-src works on QFAAG0, there was duplicate app_timer in old nRF51822 library. That's fixed in this revision.
posted by 01 Sep 2014
Now I found mbed library source files and try to understand where does it hangs. But now I completely confused why my program even goes into main. I checked startup file, there is first called SystemInit and after this _start (main). So I looked into SystemInit and saw that inside it's trying to start external 32kHz crystal with this code:
But it should hang in while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0) loop infinitely in my case when I try to start my board without external 32kHz crystal.
How can it execute my code in main if it shouldn't get there?
Though I tried to change clock source from CLOCK_LFCLKSRC_SRC_Xtal to CLOCK_LFCLKSRC_SRC_RC (internal RC) but it didn't help with hanging in wait() problem.
UPD:
No, it seems I just don't understand how mbed libraries works. I thought if I rebuild mbed-src library with my changes and replace object files then this changes will be applied.
But now I just deleted system_nrf51822.o from the project and it still compiles without errors.
I'm at a loss.
UPD:
No, it's ok, I just needed to made some changes it main to trigger recompile.
UPD:
Ok, now I figured out what's what.
1. Previously I changed GCC_ARM object files, but by default mbed using files generated by keil ARM_STM. Now I changed object files from original mbed libary to the files with my changes and it works.
2. Original binary mbed library differs from the mbed-src version.
Original binary library in SystemInit start LFCLK source from internal RC or synthesized source so it doesn't hangs there, but in mbed-src version there is external LFCLK crystal trying to start.
3. Now I changed in SystemInit to start from internal RC LFCLK source, but it still hangs in the wait() function in the main as before.
So the question about wait() hang is still pending.
UPD:
Now situation is like this:
Last mbed library build from here works fine on my board with external 32kHz crystal.
Last mbed library source from here without any changes on my board with external 32kHz crystal hangs on wait() with this test code:
UPD:
Ok, last official build revision sources still works fine from here for board with external LFCLK crystal, but hangs without it.
posted by Nikita Polotnyanko 30 Aug 2014-DELETED-
posted by Nikita Polotnyanko 01 Sep 2014