승코딩당당당
[TC275] GPIO 입력으로 LED 제어 + OMR 레지스터 본문
이번 실습에서는 Infineon AURIX 기반 보드에서 GPIO 레지스터를 직접 제어하여 입력 스위치 상태에 따라 LED를 제어하는 방법을 구현해본다. 포트 입력 레지스터(P02_IN)를 통해 스위치의 상태를 읽고, 출력 레지스터(P10_OUT)를 이용해 Red LED와 Blue LED를 각각 On/Off 하도록 구성한다. 또한 IOCR 레지스터를 설정하여 입력 핀과 출력 핀의 동작 모드를 지정하고, Watchdog 비활성화 및 CPU 동기화 과정까지 포함하여 실제 Bare-Metal 환경에서 동작하는 전체 흐름을 확인한다.
본 실습은 Infineon AURIX TC275 보드에 Easy Module Shield V1을 장착한 환경에서 진행하였다. Easy Module Shield의 사용자 스위치와 LED 모듈을 활용하여, 별도의 외부 회로 구성 없이 GPIO 입력/출력 동작을 실습할 수 있도록 구성하였다.
이를 통해 GPIO 초기화 과정, 포트 비트 마스킹 방식, 입력 값에 따른 조건 분기 처리, 그리고 AURIX의 포트 제어 구조를 직접 이해할 수 있다.
- MCU : Infineon AURIX TC275
- IDE : AURIX Development Studio (ADS)
- Compiler : TASKING Compiler
- 방식 : Bare-Metal (레지스터 직접 제어)
- 라이브러리 : iLLD 기반
개발 화면

코드 (Cpu0_Main.c)
/**********************************************************************************************************************
* \file Cpu0_Main.c
* \copyright Copyright (C) Infineon Technologies AG 2019
*
* Use of this file is subject to the terms of use agreed between (i) you or the company in which ordinary course of
* business you are acting and (ii) Infineon Technologies AG or its licensees. If and as long as no such terms of use
* are agreed, use of this file is subject to following:
*
* Boost Software License - Version 1.0 - August 17th, 2003
*
* Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and
* accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute,
* and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the
* Software is furnished to do so, all subject to the following:
*
* The copyright notices in the Software and this entire statement, including the above license grant, this restriction
* and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all
* derivative works of the Software, unless such copies or derivative works are solely in the form of
* machine-executable object code generated by a source language processor.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*********************************************************************************************************************/
#include "Ifx_Types.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"
#define PCn_2_IDX 19
#define P2_IDX 2
#define PCn_1_IDX 11
#define P1_IDX 1
IfxCpu_syncEvent cpuSyncEvent = 0;
void initLED(void);
void initGPIO(void);
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(&cpuSyncEvent);
IfxCpu_waitEvent(&cpuSyncEvent, 1);
initGPIO();
while(1)
{
if((P02_IN.U & (0x1 << P1_IDX)) == 0)
{
P10_OUT.U |= (0x1 << P1_IDX);
P10_OUT.U &= ~(0x1 << P2_IDX);
}
else
{
P10_OUT.U |= (0x1 << P2_IDX);
P10_OUT.U &= ~(0x1 << P1_IDX);
}
}
}
void initLED(void)
{
P10_IOCR0.U &= ~(0x1F << PCn_2_IDX);
P10_IOCR0.U |= 0x10 << PCn_2_IDX;
}
void initGPIO(void)
{
// PC2.1
P02_IOCR0.U &= ~(0x1F << PCn_1_IDX);
P02_IOCR0.U |= 0x02 << PCn_1_IDX;
// PC10.2 Blue LED
P10_IOCR0.U &= ~(0x1F << PCn_2_IDX);
P10_IOCR0.U |= 0x10 << PCn_2_IDX;
// PC10.1 Red LED
P10_IOCR0.U &= ~(0x1F << PCn_1_IDX);
P10_IOCR0.U |= 0x10 << PCn_1_IDX;
}
결과
스위치를 누르지 않았을 때: Blue LED
스위치를 눌렀을 때: Red LED


+ 번외
OMR 레지스터를 이용하여 Red LED Toggle 해보기
/**********************************************************************************************************************
* \file Cpu0_Main.c
* \copyright Copyright (C) Infineon Technologies AG 2019
*
* Use of this file is subject to the terms of use agreed between (i) you or the company in which ordinary course of
* business you are acting and (ii) Infineon Technologies AG or its licensees. If and as long as no such terms of use
* are agreed, use of this file is subject to following:
*
* Boost Software License - Version 1.0 - August 17th, 2003
*
* Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and
* accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute,
* and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the
* Software is furnished to do so, all subject to the following:
*
* The copyright notices in the Software and this entire statement, including the above license grant, this restriction
* and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all
* derivative works of the Software, unless such copies or derivative works are solely in the form of
* machine-executable object code generated by a source language processor.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*********************************************************************************************************************/
#include "Ifx_Types.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"
#define PCn_1_IDX 11
#define P1_IDX 1
IfxCpu_syncEvent cpuSyncEvent = 0;
void initGPIO(void);
int 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(&cpuSyncEvent);
IfxCpu_waitEvent(&cpuSyncEvent, 1);
initGPIO();
while(1)
{
if ((P02_IN.U & (0x1 << P1_IDX)) == 0)
{
P10_OMR.U = (1 << (P1_IDX + 16)) | (1 << P1_IDX);
}
}
return (1);
}
void initGPIO(void){
P02_IOCR0.U &= ~(0x1F << PCn_1_IDX);
P02_IOCR0.U |= 0x02 << PCn_1_IDX;
P10_IOCR0.U &= ~(0x1F << PCn_1_IDX);
P10_IOCR0.U |= 0x10 << PCn_1_IDX;
}
이렇게 하면 스위치를 눌렀을 때만 Red LED가 켜지는 것을 확인할 수 있다.
OMR 레지스터를 사용하는 이유:
기존 방식은 다음과 같이 OUT 레지스터를 읽고 수정하는 방식이었다.
P10_OUT.U |= (1 << P1_IDX);
P10_OUT.U &= ~(1 << P1_IDX);
이 방식은 Read-Modify-Write 구조이기 때문에 인터럽트나 멀티코어 환경에서 예상치 못한 문제가 발생할 수 있다.
반면 OMR은 출력 비트를 Set / Reset 전용으로 수정하는 레지스터로, 하드웨어에서 원자적으로 처리되기 때문에 더 안전한 방법이다.
OMR 레지스터는 아래의 구조를 가진다.
- 하위 16비트 → Set
- 상위 16비트 → Reset
P10_OMR.U = (1 << (P1_IDX + 16)) | (1 << P1_IDX);
위 코드는 같은 비트를 Reset과 Set에 동시에 써서 토글 효과를 만든다.
'개발 > 임베디드' 카테고리의 다른 글
| [TC275] Multi-interrupt로 LED 제어 (Blue/Red) (0) | 2026.02.20 |
|---|---|
| [TC275] ERU 인터럽트로 LED 제어 (On/Off, Toggle) (0) | 2026.02.20 |
| [리눅스] 라즈베리파이 커널 모듈로 LED 제어하기 (0) | 2026.02.13 |
| [리눅스] 디바이스 드라이버의 이해 (0) | 2026.02.12 |
| [리눅스] 리눅스 커널: 예외처리와 인터럽트 (0) | 2026.02.12 |