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

porting app_timer on target STM32F2

Hi,

I work on nrf52832 with the serialization.

The nrf52832 connectivity part is load with S132 V6.0.0 (uart hci).

The stm32 will communicate with the 52832 throught uart hci.

I want to put the serialization uart hci on the stm32. The first interface needing is app_timer.

1/ What is the min time and the max time in ms that the timer have to support for the serialization and ble usage?

2/ Does the ble stack  need good precision on this timer?

3/ On nrf 52832, it uses rtc and SWI0. Do you think a simple timer can be used?

Best regards

Alex

  • HI Alexandre, 

    Q1: The RTC on the NRF52832 is 24-bit and runs of the LFCLK(32.768kHz) with a resolution of 30.517 μs.

    Q2: The application timer interface in only used by the application layer, i.e. it is not used by the BLE stack. Hence, no precision requirements from the BLE stack.

    Q3: This will depend on the example that is using the application timer interface. From the app_timer docs:

    The timer library (also referred to as app_timer) enables the application to create multiple timer instances based on the RTC1 peripheral. Checking for time-outs and invoking the user time-out handlers is performed in the RTC1 interrupt handler. List handling is done using a software interrupt (SWI0).

    So, if you want to run an example that requires multiple timer instances you will need to implement the app_timer interface as we have done, i.e. with a RTC and a Software interrupt. 

    Best regards

    Bjørn

  • Hi Bjorn,

    On Q1 : so the min is 30.517µs to 511 seconds. Are you  ok?

    On Q2 : If i don't use Software interrupt, and just RTC or a simple timer (just with autoreload). Do you think it's

    a good solution?

    Why do you use software interrupt?

    Best regards

    Alexandre

  • Q1: Yes, with no prescaler the min and max is 30.517µs and 511 seconds. The min and max will depend on the prescaler that is selected.

    Q2: I suggest that you take a look at the application timer implementation in our SDK(in the latest SDK version you'll find it in nRF5_SDK_15.0.0_a53641a\components\libraries\timer\app_timer.c). If you only need one timer instance then a simple timer should be fine, but if you need multiple instances you will need to do some more work. 

    Best regards

    Bjørn 

  • Q2 : Sorry, when I say simple timer, but I speak about the hardware.

    but it's alaways a multiple instances. I have ported the apptimer with only rtc STM32F2;

    based on timer server give by ST on STM32F152 (there is only the RTC timer, no software interrupt are used).

    Here is the create fonction :

    ret_code_t app_timer_create(app_timer_id_t const *      p_timer_id,
                                app_timer_mode_t            mode,
                                app_timer_timeout_handler_t timeout_handler)
    {
        eHAL_TIMER_TimerMode_t hal_timer_mode;
        eHAL_TIMER_ret_t ret;
        
        // Check state and parameters
        VERIFY_MODULE_INITIALIZED();

        if (timeout_handler == NULL)
        {
            return NRF_ERROR_INVALID_PARAM;
        }
        if (p_timer_id == NULL)
        {
            return NRF_ERROR_INVALID_PARAM;
        }

        // Select the mode
        if(mode == APP_TIMER_MODE_SINGLE_SHOT)
            hal_timer_mode = eTimerMode_SingleShot;
        else
            hal_timer_mode = eTimerMode_Repeated;        
        
        // Create the timer
        ret = HAL_TIMER_Create(*p_timer_id, hal_timer_mode, timeout_handler);
        
        if(ret == eTimerRet_Ok)    
            return NRF_SUCCESS;
        else if(ret == eTimerMode_AllTimerInUse)
            return NRF_ERROR_NO_MEM;
        else
            return NRF_ERROR_INTERNAL;
    }

    eHAL_TIMER_ret_t HAL_TIMER_Create(uint8_t *pTimerId, eHAL_TIMER_TimerMode_t eTimerMode, pf_HAL_TIMER_TimerCallBack_t pftimeout_handler)
    {
        uint8_t    ubLoop = 0;
        eHAL_TIMER_ret_t ret = eTimerRet_Ok;

        TIMER_ENTER_CRITICAL_SECTION;
        while(aTimerContext[ubLoop].eTimerStatus != eTimerID_Free)
        {
            if(ubLoop < (MAX_NBR_CONCURRENT_TIMER - 1))
                ubLoop++;
            else
            {
                ret = eTimerMode_AllTimerInUse;
                break;
            }
        }

        // timer available, status create
        if(ret == eTimerRet_Ok)
            aTimerContext[ubLoop].eTimerStatus = eTimerID_Created;
        
        TIMER_EXIT_CRITICAL_SECTION    ;

        // timer available, initialisation
        if(ret == eTimerRet_Ok)
        {
            aTimerContext[ubLoop].eTimerMode = eTimerMode;
            aTimerContext[ubLoop].pfTimerCallBack = pftimeout_handler;
            *pTimerId = ubLoop;
        }
        return ret;
    }

    Thanks.

    Alexandre PETIT

  • Ok, if they have wrapped their HAL_TIMER_Create in our  app_timer API then you should be good to go. 

Related