This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Softdevice crashes with PPI

Hi

I've made a small application on a NRF51422 device. It's is loaded with the newest version of S320 and the newest API from you homepage.

In my application i need a couple of PWMs to trigger some external hardware. These PWMs are created using Timer2 and some PPI events/tasks Without the Softdevice enabled this works flawless. However, if the Softdevice is enabled the application crashes into a hard as soon as I set up the first CH it will jump into the HardFault handler.

I've stolen some code for setting up the Softdevice from one of the example projects (\Nordic\nrf51422\Board\nrf6310\s310\ble_app_hrs), so I'm pretty sure that part is correct - even though it's not really that platform I'm working on. I'm calling the function ble_stack_init() to initialize everything.

My set-up of the PPI channels is as so:

NRF_PPI->CH[0].EEP = (uint32_t)&NRF_TIMER2->EVENTS_COMPARE[0]; // event when reaching the duty cycle value
NRF_PPI->CH[0].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[0];
NRF_PPI->CH[1].EEP = (uint32_t)&NRF_TIMER2->EVENTS_COMPARE[1]; // event when reaching the max counter value
NRF_PPI->CH[1].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[0];

As far as I can see from the debugger the app will chrash as soon as i execute the first line above. I've tried changing the channel numbers around a bit, but I get the same result.

I've tried switching the order around, so I'll enable the Softdevice first, and then set the PPI channels. This appear to be working - atleast it doesn't chrash. However(!): If I then enable Timer2, as I need it for the PWM, during the PPI set-up (before enabling the SD) the SD enabling will throw the "NRF_ERROR_SDM_INCORRECT_INTERRUPT_CONFIGURATION" error.

So I guese my questions are: 1: Are there any kinds of rules I'm not aware of saying you are not allowed to change the PPI while the SD is enabled. 2: How do I fix the interrupt error thrown?

The hardware is one of Dynastreams eval boards, but I don't think it's an hardware issue.

Best regards

  • Hi,

    The PPI is a restricted peripheral (see the S310 spec for more details), which means that this has to be accessed by the softdevice API when the softdevice is enabled.

    You can configure the PPI prior to starting the softdevice, but you will have to make sure that any interrupts enabled at this point must be set to priority level '1' or '3', as these are the priority levels that the softdevice accepts.

    Most likely, it's the Timer2 (or GPIOTE) interrupt priority that gives you this error code. Try calling:

    NVIC_SetPriority(TIMER2_IRQHandler, 3);
    

    Before starting the softdevice.

    This library may be of interest to you: github.com/.../nrf51-pwm-library

    Best regards, Håkon

  • Hi Håkon

    I found the information regarding the IRQ priorities while waiting for you reply, but thanks anyway.

    I still don't understand the PPI stuff. I'm pretty confident that I'm not using any of the channels that are reserved according to the SD specifications. For some reason it works if I set it up before i start the softdevice. It's only if I set it up after I've started the SD that it chrashes. It's not really that important, but it's a little concerning i think. Any ideas?

    On another note while I have your attention. :) Do you have any idea if it's possible for me to get access to the S110/S120 SD instead of the S320? For some reason I only get access to some of the stuff with the Dynastream module I'm using. Seems a bit wasteful for me to order a NRF51422, that I don't really need, just to gain access.

    Thanks again.

  • Hi,

    Since the softdevice uses parts of the NRF_PPI peripheral, it protects the whole peripheral, so that the application cannot access it directly (if you try, you'll end up in HardFault). So, using this protection, the only way we're allowed to access it is through the nrf_soc API (sd_ppi-prefixed functions). If you set up the PPI before starting the softdevice, the softdevice will only care about the PPI channel it needs and leave the others untouched. BTW: I'll send you a PM regarding your last question:)

  • Hi Håkon. Follow up question.

    We tried changing the SD to S110-SD-v7 from S310 and updated the SDK to 6.0.0 by overwriting the /Source/ and /Include/ folders in our project folder. The IROM and RAM adresses has been updated as specified in the v7 migration guide.

    Now we get some wierd error when initializing the GAP. The init code is pretty much the same as the one in the gap_params_init(void) function in the nrf51-ble-app-lbs project on your github. But our sd_ble_gap_device_name_set() function returns BLE_ERROR_INVALID_ATTR_HANDLE (0x3001) and the program keeps rebooting as a result.

    Any ideas? We looked through all of the documentation, but there's no mention of anything we should be aware of in this regard.

Related