This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Porting MSP430F5529's intrinsic __delay_cyles() to MSP432P401R

Other Parts Discussed in Thread: MSP430F5529

I'm porting Pervasive Displays code for their Extension Kit, http://www.pervasivedisplays.com/kits/ext_kit, from MSP430F5529 to MSP432P401R.

MSP430 has an intrinsic __delay_cycles(). I looked for equivalent one in MSP432 but found none. Is there any ? If not what are the workarounds ?

One possible solution is use MSP432's intrinsic of sleep() and a timer but I want to avoid that because I don't want to use up the timers.

  • The TI ARM v5.2.x compiler does support a _delay_cycles() intrinsic, which I have used on other ARM devices such as a Cortex M4F Tiva device, so should work on a Cortex M4F MSP432 device.

    One issue I found was that on some ARM devices was that the actual delay could be several times that requested and could change according to the code alignment - see What is its unit of number of _delay_cycles()

    i.e. using _delay_cycles() can be difficult to generate a deterministic delay, even when no interrupts are occurring..

  • According to the documentation I have from the pre-announcement training last June, CCS supports the __delay_cycles() intrinsic. You need to #include "msp430dna.h"
  • Thanks, but forgive me for this rookie question: where is this "msp430dna.h" file? I am not using CCS. Thanks!
  • Tao,

    What compiler are you using? I think your intrinsics that you can use or need to use are going to vary with that. Do you IAR? Or maybe GCC?

    -Katie
  • I am using CCSv6 but use GCC tool chain: GNU v4.8.4 (Linaro).

    I am using GCC because it offers some features I need. But it cannot find this msp430dna.h. Do you know where it is?

    Thanks!

  • Hi Tao,

     We do not support this intrinsic in GNU(gcc) or IAR. So you will have to implement it yourself.

    This is what I use:

    #include <stdbool.h>
    #include <stdint.h>
    #include "driverlib.h"
    #include "demo_sysctl.h"
    
    //*****************************************************************************
    //
    //! Provides a small delay.
    //!
    //! \param ui32Count is the number of delay loop iterations to perform.
    //!
    //! This function provides a means of generating a delay by executing a simple
    //! 3 instruction cycle loop a given number of times.  It is written in
    //! assembly to keep the loop instruction count consistent across tool chains.
    //!
    //! It is important to note that this function does NOT provide an accurate
    //! timing mechanism.  Although the delay loop is 3 instruction cycles long,
    //! the execution time of the loop will vary dramatically depending upon the
    //! application's interrupt environment (the loop will be interrupted unless
    //! run with interrupts disabled and this is generally an unwise thing to do)
    //! and also the current system clock rate and flash timings (wait states and
    //! the operation of the prefetch buffer affect the timing).
    //!
    //! For best accuracy, a system timer should be used with code either polling
    //! for a particular timer value being exceeded or processing the timer
    //! interrupt to determine when a particular time period has elapsed.
    //!
    //! \return None.
    //
    //*****************************************************************************
    #if defined(ewarm) || defined(DOXYGEN)
    void
    SysCtlDelay(uint32_t ui32Count)
    {
        __asm("    subs    r0, #1\n"
              "    bne.n   SysCtlDelay\n"
              "    bx      lr");
    }
    #endif
    #if defined(codered) || defined(gcc) || defined(sourcerygxx)
    void __attribute__((naked))
    SysCtlDelay(uint32_t ui32Count)
    {
        __asm("    subs    r0, #1\n"
              "    bne     SysCtlDelay\n"
              "    bx      lr");
    }
    #endif
    #if defined(rvmdk) || defined(__ARMCC_VERSION)
    __asm void
    SysCtlDelay(uint32_t ui32Count)
    {
        subs    r0, #1;
        bne     SysCtlDelay;
        bx      lr;
    }
    #endif
    //
    // For CCS implement this function in pure assembly.  This prevents the TI
    // compiler from doing funny things with the optimizer.
    //
    #if defined(ccs)
    __asm("    .sect \".text:SysCtlDelay\"\n"
          "    .clink\n"
          "    .thumbfunc SysCtlDelay\n"
          "    .thumb\n"
          "    .global SysCtlDelay\n"
          "SysCtlDelay:\n"
          "    subs r0, #1\n"
          "    bne.n SysCtlDelay\n"
          "    bx lr\n");
    #endif
    

    Best regards,

      David

**Attention** This is a public forum