Entorno AURIX TC397 para construir retardo GPIO

Estudio de desarrollo AURIX ™

AURIX ™ Development Studio , un entorno de desarrollo completo, que incluye Eclipse IDE, compilador C, depurador de múltiples núcleos, controlador de bajo nivel Infineon (iLLD), sin restricciones de tiempo y tamaño de código, capaz de editar, compilar y depurar código de aplicación .

Después del registro, el enlace de descarga se enviará al buzón de correo. Descargué la AURIX-studio-setup_1.2.2_20201012-1308versión, el tamaño del 382MBdirectorio de instalación predeterminado C:\Infineon\AURIX-Studio-1.2.2, no cambiado.

La instalación principal AURIX™Development Studioy DAS64, verifique el acuerdo de consentimiento, el siguiente paso.

Importar proyecto

AURIX™ Development StudioPuede importar el último proyecto de ejemplo, que puede ser de Github Infineon
/ AURIX_code_examples
:

  • encender AURIX Development Studio

  • File -> Import...

  • Seleccione Infineon-> AURIX Development Studio Project, luego haga clic en Next:Inserte la descripción de la imagen aquí

  • Seleccione un proyecto de TC397 Blink (también puede seleccionar varios proyectos)), haga clic en Finalizar, si el clic no se mueve, puede haber una carpeta con el mismo nombre debajo del área de trabajo por defecto: 66

Nueva construcción

Lo anterior es cómo importar el proyecto de muestra, o puede crear un nuevo proyecto usted mismo:

  • File-> New-> New AURIX Project:55

  • Introduzca un nombre de proyecto TC397_Blink_LED, Next:44

  • Seleccione dispositivo y placa o Custom Board:33

  • A veces, al editar, la página del editor aparece atenuada, lo que indica que el proyecto donde se encuentra el archivo actual no es Actice. Haga clic con el botón derecho en el proyecto y seleccione Set Active Project:22

Abierto Cpu0_Main.c, el código predeterminado es el siguiente:

#include "Ifx_Types.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"

IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;

void core0_main(void)
{
    
    
    IfxCpu_enableInterrupts();
    
    /* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!
     * Enable the watchdogs and service them periodically if it is required
     */
    IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
    IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());
    
    /* Wait for CPU sync event */
    IfxCpu_emitEvent(&g_cpuSyncEvent);
    IfxCpu_waitEvent(&g_cpuSyncEvent, 1);
    
    while(1)
    {
    
    
    }
}

Hay 4 LED en la placa KIT_A2G_TC397_5V_TFT , que son:

Referencia ALFILER EN
D107 P13.0 0
D108 P13.1 0
D109 P13.2 0
D110 P13.3 0

Diagrama esquemático:

11

Ahora agregue algunas funciones de retardo e iluminación:

#include "Ifx_Types.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"
#include "Bsp.h"    //initTime();

IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;

void core0_main(void)
{
    
    
    IfxCpu_enableInterrupts();
    
    /* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!
     * Enable the watchdogs and service them periodically if it is required
     */
    IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
    IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());
    
    /* Wait for CPU sync event */
    IfxCpu_emitEvent(&g_cpuSyncEvent);
    IfxCpu_waitEvent(&g_cpuSyncEvent, 1);
    
    initTime(); /* Calculate iLLDs time constants   */
    IfxPort_setPinModeOutput(&MODULE_P13,0, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
    IfxPort_setPinHigh(&MODULE_P13,0);   //Switch OFF the LED (low-level active)

    while(1)
    {
    
    
        IfxPort_togglePin(&MODULE_P13,0);       /* Toggle the state of the LED*/
        waitTime(5 * TimeConst_100ms);          /* Wait 500 milliseconds*/
    }
}

Build Active Project:

Inserte la descripción de la imagen aquí

Los resultados son los siguientes:

Inserte la descripción de la imagen aquí

Conecte la placa y la computadora con un cable Micro-USB y confirme que no hay ningún problema con el controlador en el administrador de dispositivos:

Inserte la descripción de la imagen aquí

Puede depurar o EJECUTAR, aquí está el último como ejemplo, AURIX™ Development Studiohaga clic derecho en Ejecutar como -> Ejecutar configuración:

Inserte la descripción de la imagen aquí

No encontré nada, haga clic derecho TASKING C/C++ Debugger-> New Configuration:

Inserte la descripción de la imagen aquí

Luego aparece la configuración con el mismo nombre del proyecto:

Inserte la descripción de la imagen aquí

Puede mantener el valor predeterminado, luego Ejecutar, La consola le indica Loading 'D:\CodeVarietyShop\AURIX-v1.2.2-workspace\TC397_Blink_LED\Debug\TC397_Blink_LED.elf'...que se ha descargado al microcontrolador, el programa no se ha ejecutado, presione el botón de reinicio S101 PORSTy descubrió que el LED azul D107 se enciende y apaga alternativamente a 500 ms.

Modifica el código:

    initTime(); /* Calculate iLLDs time constants   */
    IfxPort_setPinModeOutput(&MODULE_P13,0, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
    IfxPort_setPinModeOutput(&MODULE_P13,1, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
    IfxPort_setPinModeOutput(&MODULE_P13,2, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
    IfxPort_setPinModeOutput(&MODULE_P13,3, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
    IfxPort_setPinHigh(&MODULE_P13,0);   //Switch OFF the LED (low-level active)
    IfxPort_setPinHigh(&MODULE_P13,1);   //Switch OFF the LED (low-level active)
    IfxPort_setPinHigh(&MODULE_P13,2);   //Switch OFF the LED (low-level active)
    IfxPort_setPinHigh(&MODULE_P13,3);   //Switch OFF the LED (low-level active)

    while(1)
    {
    
    
        IfxPort_togglePin(&MODULE_P13,0);       /* Toggle the state of the LED*/
        IfxPort_togglePin(&MODULE_P13,1);
        IfxPort_togglePin(&MODULE_P13,2);
        IfxPort_togglePin(&MODULE_P13,3);
        waitTime(5 * TimeConst_100ms);          /* Wait 500 milliseconds*/
    }

Haga clic en el que tiene forma de martillo Build Active Projecty le indicará después de la compilación:

Inserte la descripción de la imagen aquí

Haga clic en Yes, descarga automática, aviso Re-loading 'D:\CodeVarietyShop\AURIX-v1.2.2-workspace\TC397_Blink_LED\Debug\TC397_Blink_LED.elf'..., presione el botón de reinicio, puede ver que 4 luces se encienden y apagan alternativamente al mismo tiempo durante 500 ms.

Retrasar

  • El archivo de encabezado contiene #include "Bsp.h"
  • inicialización initTime(); /* Calculate iLLDs time constants */
  • Retrasar waitTime(5 * TimeConst_100ms); /* Wait 500 milliseconds*/

Las constantes que también se pueden utilizar son:

#define TimeConst_0s    ((Ifx_TickTime)0)                           /**< \brief time constant equal to 1s */
#define TimeConst_10ns  (TimeConst[TIMER_INDEX_10NS])               /**< \brief time constant equal to 10ns */
#define TimeConst_100ns (TimeConst[TIMER_INDEX_100NS])              /**< \brief time constant equal to 100ns */
#define TimeConst_1us   (TimeConst[TIMER_INDEX_1US])                /**< \brief time constant equal to 1us */
#define TimeConst_10us  (TimeConst[TIMER_INDEX_10US])               /**< \brief time constant equal to 10us */
#define TimeConst_100us (TimeConst[TIMER_INDEX_100US])              /**< \brief time constant equal to 100us */
#define TimeConst_1ms   (TimeConst[TIMER_INDEX_1MS])                /**< \brief time constant equal to 1ms */
#define TimeConst_10ms  (TimeConst[TIMER_INDEX_10MS])               /**< \brief time constant equal to 10ms */
#define TimeConst_100ms (TimeConst[TIMER_INDEX_100MS])              /**< \brief time constant equal to 100ms */
#define TimeConst_1s    (TimeConst[TIMER_INDEX_1S])                 /**< \brief time constant equal to 1s */
#define TimeConst_10s   (TimeConst[TIMER_INDEX_10S])                /**< \brief time constant equal to 10s */
#define TimeConst_100s  (TimeConst[TIMER_INDEX_100S])               /**< \brief time constant equal to 100s */

Salida GPIO set push-pull

  • Establecer salida push-pull IfxPort_setPinModeOutput(&MODULE_P13,0, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);

Salida GPIO

  • Salida de alto nivel IfxPort_setPinHigh(&MODULE_P13,0);
  • Salida de bajo nivel IfxPort_setPinLow(&MODULE_P13,0);
  • Dar la vuelta IfxPort_togglePin(&MODULE_P13,0);

Lectura de nivel GPIO

Independientemente de si el pin está configurado como entrada o salida, el nivel se puede leer.

  • Prototipo de función: uint32 IfxPort_getGroupState(Ifx_P *port, uint8 pinIndex, uint16 mask)

  • Leer nivel P13.2: IfxPort_getGroupState(&MODULE_P13,2,1)

  • Leer nivel P33 [7: 0]: valor uint16 = IfxPort_getGroupState (& MODULE_P33, 0, 0xff);

		if(IfxPort_getGroupState(&MODULE_P13,2,1) == 1) {
    
    
            IfxPort_setPinLow(&MODULE_P13,3);
        } else {
    
    
            IfxPort_setPinHigh(&MODULE_P13,3);
        }

Código completo

Tenga en cuenta que después de que P13.2 invierta el nivel, se lee después de un retraso de 10ns . Si lee directamente, el estado de lectura es incorrecto. Por supuesto, cambie el orden de Alternar a P13.2, P13.1, P13.0, y luego También es posible leer el nivel P13.2.

#include "Ifx_Types.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"
#include "Bsp.h"    //initTime();

IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;

void core0_main(void)
{
    
    
    IfxCpu_enableInterrupts();
    
    /* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!
     * Enable the watchdogs and service them periodically if it is required
     */
    IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
    IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());
    
    /* Wait for CPU sync event */
    IfxCpu_emitEvent(&g_cpuSyncEvent);
    IfxCpu_waitEvent(&g_cpuSyncEvent, 1);
    
    initTime(); /* Calculate iLLDs time constants   */
    IfxPort_setPinModeOutput(&MODULE_P13,0, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
    IfxPort_setPinModeOutput(&MODULE_P13,1, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
    IfxPort_setPinModeOutput(&MODULE_P13,2, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
    IfxPort_setPinModeOutput(&MODULE_P13,3, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
    IfxPort_setPinHigh(&MODULE_P13,0);   //Switch OFF the LED (low-level active)
    IfxPort_setPinHigh(&MODULE_P13,1);   //Switch OFF the LED (low-level active)
    IfxPort_setPinHigh(&MODULE_P13,2);   //Switch OFF the LED (low-level active)
    IfxPort_setPinHigh(&MODULE_P13,3);   //Switch OFF the LED (low-level active)

    while(1)
    {
    
    
        IfxPort_togglePin(&MODULE_P13,0);       /* Toggle the state of the LED*/
        IfxPort_togglePin(&MODULE_P13,1);
        IfxPort_togglePin(&MODULE_P13,2);
        //IfxPort_togglePin(&MODULE_P13,3);
        waitTime(1 * TimeConst_10ns);   //wait for P13.3 State
        if(IfxPort_getGroupState(&MODULE_P13,2,1) == 1) {
    
    
            IfxPort_setPinLow(&MODULE_P13,3);
        } else {
    
    
            IfxPort_setPinHigh(&MODULE_P13,3);
        }
        waitTime(4 * TimeConst_100ms);          /* Wait 500 milliseconds*/
    }
}

referencia

Cuenta pública de WeChat

Bienvenido a escanear y seguir mi cuenta pública de WeChat para obtener los últimos artículos a tiempo:
Inserte la descripción de la imagen aquí

Supongo que te gusta

Origin blog.csdn.net/weifengdq/article/details/109292750
Recomendado
Clasificación