nrf Developer Academy SDK Intermediate Lesson 6 Exercise 3 access violation

Hi there,

When flashing my solution to Lesson 6 Exercise 3 using nrf52DK / nrf52832 - I kept getting an access violation when attempting to setup the timer.  I compared the solution to my app and noticed that the solution was slightly different to the steps listed in the exercise.  Step 3.2 in the exercise calls for:

const nrfx_timer_t timer_instance = NRFX_TIMER_INSTANCE(TIMER_INSTANCE_NUMBER);

but the solution does not have the const restriction.  I removed the const and all worked properly.

Cheers

  • Hello,

    You may have encountered this if you are using nrfx version 4.0. The exercise is maybe not updated to the new technical requirement yet, but the solution is. Basically, with nrfx version 4.0, the internal status has been moved into the driver's instance object (nrfx_timer_t) which is made in the code. Before, it used to be kept in a separate internal array. 

    In the code, when nrfx_timer_init() is run, first the driver tries to write initial settings into the timer_instance variable. The "const" label means the variable is saved as "read only" in the memory of the chip. So when the chip notices the driver writing to a "read-only" memory, the program stops and this leads to access violation to prevent errors. When you don't use "const", the driver can update the variable. 

    Hope this helps.

    Best Regards,

    Samruddhi

  • Hi,

    i ran into an access violation to when booting the device. I use the same HW setup.

    Removing the "const" in that line actually fixed it for me too.

    Thanks for the hint.

Related