TMS320F280049C learning note 4 LED ﹣ EX1 ﹣ blinky and initialization function

Preface

Take the last learning note, and this time start to run the routine. Every learning of a new DSP starts from lighting, this time is no exception. TI's official help document [1] can be found in C: \ TI \ c2000ware ﹣ 2 ﹣ 01 ﹣ device ﹣ support \ f28004x \ docs \ f28004x ﹣ dev ﹣ user ﹣ guidepdf. It provides the novice with a guide to step by step and instructions for all routines. TI provides two sets of routines, among which the routine of register programming is in C: \ TI \ c2000ware ﹣ 2 ﹣ 00 ﹣ device ﹣ support \ f28004x, and the routine of library function programming is in C: \ TI \ c2000ware ﹣ 2 ﹣ 00 ﹣ driverlib \ f28004x \ examples. The routine referred to in this experiment is led ﹣ EX1 ﹣ blinky. In the future, you can follow this step to learn other types of DSP.

About conditional compilation

This is described in [1]
The corresponding settings in CCS9.3 are:
The purpose of this setting is to match different hardware. For the two processors 28379D and 280049C, TI released the ControlCARD and LaunchPad respectively, with different crystal oscillator and pin configuration. Routine is developed for ControlCARD. If you want to apply it to LaunchPad, you need to change the pin mapping naturally. The specific code can be found in devices.h. some screenshots are as follows:
It should be noted that if you define the pin completely from scratch and develop the program, you do not need to pay attention to this part of conditional compilation instructions.

routine

This section gives two routines of Led flicker experiment from the official folder. The first is library function programming version, and the second is register programming. You can see that there is a significant difference in the call part of the initialization function.

Library function version:

#include "driverlib.h"
#include "device.h"

# define LOOP_COUNT 10

void main(void)
{
    // Initialize device clock and peripherals
    Device_init();

    // Initialize GPIO and configure the GPIO pin as a push-pull output
    Device_initGPIO();
    GPIO_setPadConfig(DEVICE_GPIO_PIN_LED1, GPIO_PIN_TYPE_STD);  // Push-pull output or floating input
    GPIO_setDirectionMode(DEVICE_GPIO_PIN_LED1, GPIO_DIR_MODE_OUT);

    // Initialize PIE and clear PIE register, turn off CPU interrupt
    // Initialize PIE and clear PIE registers. Disables CPU interrupts. 
    Interrupt_initModule();

    // Initialize PIE vector table
    // Initialize the PIE vector table with pointers to the shell Interrupt
    // Service Routines (ISR).
    Interrupt_initVectorTable();

    // Enable Global Interrupt (INTM) and realtime interrupt (DBGM)
    EINT;
    ERTM;

    // Loop Forever
    for(;;)
    {
        // Turn on LED
        // The hardware circuit design is GPIO output low power level LED is on
        GPIO_writePin(DEVICE_GPIO_PIN_LED1, 0);

        // Delay for a bit
        DEVICE_DELAY_US(500000);

        // Turn off LED
        GPIO_writePin(DEVICE_GPIO_PIN_LED1, 1);

        // Delay for a bit.
        DEVICE_DELAY_US(500000);
    }
}

Register version:

#include "F28x_Project.h"

#define DEVICE_GPIO_PIN_LED1    31


void main(void)
{
    // Initialize device clock and peripherals
    InitSysCtrl();

    // Initialize GPIO and configure the GPIO pin as a push-pull output
    InitGpio();
    GPIO_SetupPinMux(DEVICE_GPIO_PIN_LED1, GPIO_MUX_CPU1, 0);
    GPIO_SetupPinOptions(DEVICE_GPIO_PIN_LED1, GPIO_OUTPUT, GPIO_PUSHPULL);

    // Initialize PIE and clear PIE registers. Disables CPU interrupts. 
    DINT;
    InitPieCtrl();
    IER = 0x0000;
    IFR = 0x0000;

    // Initialize the PIE vector table with pointers to the shell Interrupt
    // Service Routines (ISR).
    InitPieVectTable();

    // Enable Global Interrupt (INTM) and realtime interrupt (DBGM)
    EINT;
    ERTM;

    // Loop Forever
    for(;;)
    {
        // Turn on LED
        GPIO_WritePin(DEVICE_GPIO_PIN_LED1, 0);

        // Delay for a bit.
        DELAY_US(500000);

        // Turn off LED
        GPIO_WritePin(DEVICE_GPIO_PIN_LED1, 1);

        // Delay for a bit.
        DELAY_US(500000);
    }
}

InitSysCtrl() initialization function

There are many articles about register programming, which are summarized with reference to [4].
The first statement after the second code main function is InitSysCtrl(), which initializes the chip. The function is declared in f28004x_sysctrl.c.

Watchdog

The first sentence of the initialization function is to close the watchdog. The specific code is as follows:

void DisableDog(void)
{
    volatile Uint16 temp;
    EALLOW;

    //
    // Grab the clock config so we don't clobber it
    //
    temp = WdRegs.WDCR.all & 0x0007;
    WdRegs.WDCR.all = 0x0068 | temp;
    EDIS;
}

This code is written much better than the previous version. It does not directly assign values, but uses or to avoid damaging other clock settings.
EALLOW is discussed in Section 3.1 of [5].
In section 3.14.23.4, a detailed explanation is given for each bit of the register

According to the manual, the binary corresponding to the closed watchdog is 0000 0000 0110 1000, that is, 0068 in hex

Other

The rest is to initialize Flash, PLL and other contents, and various peripheral clocks. At the current level, this part of the code is still relatively difficult to skip.
In this part, 280049C will involve a term called DCC, full name is dual clock comparator, which is mainly to enhance the reliability of clock signal. It is discussed in Chapter 6 of [5].

Reference

  1. F28004x Firmware Development Package USER'S GUIDE
  2. F28377D Learning Series (I)
  3. Understanding of EINT DINT ERTM DRTM EALLOW EDIS ESTOP0
  4. TMS320F28069 learning --- InitSysCtrl();
  5. TMS320F28004x Microcontrollers Technical Reference Manual
  6. 2. TMS320F28069 learning GPIO output flow lamp
415 original articles published, 30 praised, 420000 visitors+
His message board follow

Tags: Programming shell REST

Posted on Fri, 13 Mar 2020 01:09:00 -0400 by AshrakTheWhite