This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Generating a 1ms heartbeat timer on XMC4500.

Hi all. Just as the title says, I am trying to generate a 1ms heartbeat timer on my XMC4500 hexagon board, but I am running into an error which you can see here: http://imgur.com/o5TGwms .

You can see there at the bottom in Build Output that I am getting the L6200E Error. Now, the reason it says .\Flash\Blinky.axf in front of the error is because I simply opened up the example Blinky project and deleted the contents of Source Files folder and replaced it with the sysTick.c code.

Any help is much appreciated.

Parents
  • I think you'd want to review example materials from Infineon

    #include <stdio.h>
    #include <XMC4500.h>                    //SFR declarations of the selected device
    
    volatile uint32_t msTicks = 0; /* Variable to store millisecond ticks */
    
    void SysTick_Handler(void) // Entering every 1 ms (1 KHz)
    { /* SysTick interrupt Handler.
      msTicks++; See startup file startup_XMC4500.s for SysTick vector */
    
    // Pseudo-code
    
    // if (msTicks & 1) // 2ms period, 500 Hz on scope
    //   SetGPIOHigh();
    // else
    //   SetGPIOLow();
    }
    
    int main (void)
    {
      uint32_t returnCode;
    
    // Pseudo-code
    
    // EnableGPIOPeripheralClock();
    // EnableGPIOPin();
    
      returnCode = SysTick_Config(SystemCoreClock / 1000); /* Configure SysTick to generate an interrupt every millisecond */
    
      if (returnCode != 0) { /* Check return code for errors */
        // Error Handling
      }
    
      while(1);
    }
    

Reply
  • I think you'd want to review example materials from Infineon

    #include <stdio.h>
    #include <XMC4500.h>                    //SFR declarations of the selected device
    
    volatile uint32_t msTicks = 0; /* Variable to store millisecond ticks */
    
    void SysTick_Handler(void) // Entering every 1 ms (1 KHz)
    { /* SysTick interrupt Handler.
      msTicks++; See startup file startup_XMC4500.s for SysTick vector */
    
    // Pseudo-code
    
    // if (msTicks & 1) // 2ms period, 500 Hz on scope
    //   SetGPIOHigh();
    // else
    //   SetGPIOLow();
    }
    
    int main (void)
    {
      uint32_t returnCode;
    
    // Pseudo-code
    
    // EnableGPIOPeripheralClock();
    // EnableGPIOPin();
    
      returnCode = SysTick_Config(SystemCoreClock / 1000); /* Configure SysTick to generate an interrupt every millisecond */
    
      if (returnCode != 0) { /* Check return code for errors */
        // Error Handling
      }
    
      while(1);
    }
    

Children
  • Hi, Pier. Where did you find this code, or did you come up with it yourself? I need some more information to help me make sense about what the commented-out pseudocode is doing.

  • I am especeially interested in knowing what the following pseudo-code is doing. Could you explain it a little more, Pier? How does 'msTicks & 1' generate a 2ms period and thus 500Hz?

    // Pseudo-code
    
    // if (msTicks & 1) // 2ms period, 500 Hz on scope
    //   SetGPIOHigh();
    // else
    //   SetGPIOLow();
    

  • msTicks gets incremented each ms.

    on odd tick, high is called.
    on even tick, low is called.

    so a high low cycle occurs with 2 of the msTicks

    so the frequency is 500ms

    easy. no?

  • Hi, sudo. I understand this, but how does 'msTicks & 1' get this done? To me '&' is just a bitwise AND operator.

  • EDIT:

    So lets say msTicks is 7, then 7 & 1 = 7. Which is odd, so signal to pin goes HIGH. Then lets say msTicks is 8, then 8 & 1 = 8. Which is even, so signal to pin goes LOW. This completes our 2ms/500Hz cycle.

    Is this how it works?

  • nearly.

    7 & 1 is 1
    8 & 1 is 0

    the & is a bitwise operator

    so, basically, you're just looking at the least significant bit of the count to determine whether it's odd or even.

  • Hi, sudo. So here is what I have: http://imgur.com/FzL2k8I .

    I knew I was going to get those errors. I simply have not declared the functions. How and where do you think should I declare these functions, because this could be done in several ways?

  • if you don't know where to declare a function, you'd better go back to the first lesson of programming in C.

  • Well I know how and where to declare a function, but I get the same errors: http://imgur.com/0dNfIEQ .

  • Not sure if you realize it, but I bet quite a number of people are doing what I'm doing - ignoring all your links to screen shots or whatever they may be.

    Anything wrong with posting the error messages as text? It has worked will for thousands of other people on this forum. Or maybe I'm just not part of the Youtube generation where the only way to learn seems to be by viewing Youtube videos.

  • The formatting gets messed up when I copy my code into here from uVision as you can see:

    #include "stdio.h"
    #include "XMC4500.h"                                                                                                  //SFR declarations of the selected device
    #include "xmc_gpio.h"
    
    
    uint32_t msTicks = 0;                                                                                                                                           /* Variable to store millisecond ticks */
    
    void SysTick_Handler(void) {                                                                                                                    /* SysTick interrupt Handler.*/
            msTicks++;                                                                                                                                                                                      /*See startup file startup_XMC4500.s for SysTick vector */
    
    
            if (msTicks & 1)                                                                                                                                                            // 2ms period, 500 Hz on scope
                    PORT3->OMR = 0x00000080UL;                                                                                                                                                           // 7 & 1 is 1; 8 & 1 is 0 -- bitwise operation, so basically we are just looking at the least
            else                                                                                                                                                                                                            // significant count to determine whether it's odd or even. If odd, signal to pin goes HIGH,
                    PORT3->OMR = 0x00800000UL;                                                                                                                                                           // if even, signal to pin goes LOW. This completes our 2ms/500Hz cycle.
    
    }
    int main (void) {
            uint32_t returnCode;
    
            EnableGPIOPeripheralClock(1);
      PORT3->OMR = 0x00000080UL;
    
            returnCode = SysTick_Config(SystemCoreClock / 1000);            /* Configure SysTick to generate an interrupt every millisecond */
            if (returnCode != 0) {                                                                                                                                  /* Check return code for errors */
                    // Error Handling
            }
            while(1);
    }
    

    My only remaining error is .\Objects\sadsadsa.axf: Error: L6218E: Undefined symbol EnableGPIOPeripheralClock (referred from maaaaaain.o). .

    I am still looking for a way to enable the gpio peripheral clock. I think this is much easier to follow: http://imgur.com/550uCUC .

  • Here is my code now:

    #include "stdio.h"
    #include "XMC4500.h"                                                                                                  //SFR declarations of the selected device
    #include "xmc_gpio.h"
    #include "xmc4_gpio.h"
    
    uint32_t msTicks = 0;                                                                                                                                           /* Variable to store millisecond ticks */
    
    void SysTick_Handler(void) {                                                                                                                    /* SysTick interrupt Handler.*/
            msTicks++;                                                                                                                                                                                      /*See startup file startup_XMC4500.s for SysTick vector */
    
    
            if (msTicks & 1)                                                                                                                                                            // 2ms period, 500 Hz on scope
                    PORT3->OMR = 0x00000080UL;                                                                                                           // 7 & 1 is 1; 8 & 1 is 0 -- bitwise operation, so basically we are just looking at the least
            else                                                                                                                                                                                                            // significant count to determine whether it's odd or even. If odd, signal to pin goes HIGH,
                    PORT3->OMR = 0x00800000UL;                                                                                                           // if even, signal to pin goes LOW. This completes our 2ms/500Hz cycle.
    
    }
    int main (void) {
            uint32_t returnCode;
    
            PORT3->IOCR[P3_7 >> 2U]
            P3_7_set_driver_strength(STRONG);
            PORT3->OMR = 0x00800000UL;
    
            returnCode = SysTick_Config(SystemCoreClock / 1000);            /* Configure SysTick to generate an interrupt every millisecond */
            if (returnCode != 0) {                               /* Check return code for errors */
                    // Error Handling
            }
            while(1);
    }
    
    

    but I am getting the error :

    maaaaaain.c(21): error:  #136: struct "<unnamed>" has no field "IOCR"
            PORT3->IOCR[P3_7 >> 2U]
    


    any ideas on how to fix this?

  • Maybe stop trial-and-error coding and spend some time reading through the available reference documentation?

    You may also read through the header files to see exactly what structures and functions that are mentioned.

    Copying random code will not do you any good. And you need to be way more careful too - that line doesn't even have any terminating ';'.

    How well will your:

    // Error Handling
    


    actually manage, in case there is an error? Why pretend to check the error code if you don't handle it anyway?

    I would suggest that you get a suitable book and walk through basic C programming on a PC before you return to embedded programming. Right now, you seem to have taken on a much too big task that you lack the required strategy to solve yourself.

  • I have done C many times in the past. I am just trying to delve into ARM programming. I have programmed many proprietary architectures before ARM where setting up a timer and GPIOs was much easier. I have looked at the Infineon manual for this specific MCU and it is very hard to follow.

  • I have done C many times in the past.

    I'd be interested to know what you did in C before.

    You didn't know about the simple concept of masking to determine odd or even and it appears that you didn't know where to add functions.

    It's even questionable as to whether any of what you've asked is specific to ARM.

    I can only conclude that those C projects you did must have been rather limited.

    You really should go back to basics.