I have tried the following code in a cpp file and a c file: In the c file it works but the cpp one it does not. I added code from my LED class to make it easier to test.
#include "TM4C129.h" // Device header
#define LED_NUM 4 /* Number of user LEDs */
void LED_Initialize(void);
void LED_On (uint32_t num);
void LED_Off (uint32_t num);
void LED_Out (uint32_t value);
void Delay (uint32_t dlyTicks);
const static uint32_t led_mask[] = { 1UL << 1, 1UL << 0, 1UL << 4, 1UL << 0 };
//static unsigned int ledState = 0;
volatile static uint32_t msTicks; /* counts 1ms timeTicks */
void Delay (uint32_t dlyTicks)
{
uint32_t curTicks;
curTicks = msTicks;
while ((msTicks - curTicks) < dlyTicks) { __NOP(); }
}
int main()
{
LED_Initialize();
SystemCoreClockUpdate(); /* Get Core Clock Frequency */
SysTick_Config(SystemCoreClock / 1000ul); /* Setup SysTick for 1 msec */
while(1)
{
LED_On(0);
Delay(5000);
LED_Off(0);
Delay(5000);
}
}
void SysTick_Handler(void)
{
msTicks++;
}
/*----------------------------------------------------------------------------
initialize LED Pins (GPION1, GPION0, GPIOF0, GPIOF4)
*----------------------------------------------------------------------------*/
void LED_Initialize (void) {
/* Enable clock and init GPIO outputs */
SYSCTL->RCGCGPIO |= (1UL << 12) | (1UL << 5); /* enable clock for GPIOs */
GPION->DIR |= led_mask[0] | led_mask[1]; /* PN1, PN0 is output */
GPION->DEN |= led_mask[0] | led_mask[1]; /* PN1, PN0 is digital func. */
GPIOF_AHB->DIR |= led_mask[2] | led_mask[3]; /* PF4, PF0 is output */
GPIOF_AHB->DEN |= led_mask[2] | led_mask[3]; /* PF4, PF0 is digital func. */
}
/*----------------------------------------------------------------------------
Function that turns on requested LED
*----------------------------------------------------------------------------*/
void LED_On (uint32_t num) {
if (num < LED_NUM) {
switch (num) {
case 0: GPION->DATA |= led_mask[num]; break;
case 1: GPION->DATA |= led_mask[num]; break;
case 2: GPIOF_AHB->DATA |= led_mask[num]; break;
case 3: GPIOF_AHB->DATA |= led_mask[num]; break;
}
}
}
/*----------------------------------------------------------------------------
Function that turns off requested LED
*----------------------------------------------------------------------------*/
void LED_Off (uint32_t num) {
if (num < LED_NUM) {
switch (num) {
case 0: GPION->DATA &= ~led_mask[num]; break;
case 1: GPION->DATA &= ~led_mask[num]; break;
case 2: GPIOF_AHB->DATA &= ~led_mask[num]; break;
case 3: GPIOF_AHB->DATA &= ~led_mask[num]; break;
}
}
}
/*----------------------------------------------------------------------------
Function that outputs value to LEDs
*----------------------------------------------------------------------------*/
void LED_Out(uint32_t value) {
int i;
for (i = 0; i < LED_NUM; i++) {
if (value & (1<<i)) {
LED_On (i);
} else {
LED_Off(i);
}
}
}