platformio / platformio-core

Your Gateway to Embedded Software Development Excellence :alien:
https://platformio.org
Apache License 2.0
7.83k stars 789 forks source link

Programming using C language only #529

Closed baronleonardo closed 7 years ago

baronleonardo commented 8 years ago

I have a board of type "lptm4c1230c3pm", and I want to program in pure C language without using the style of Energia.

ivankravets commented 8 years ago

See native example https://github.com/platformio/platformio/tree/develop/examples/titiva/titiva-native-blink

The framework = energia here is used for driverlib and LD script. The high level code of Energia's framework will not be used.

baronleonardo commented 8 years ago

what I want is to write my own main with my own port(s) configuration I wrote an example Sample

ivankravets commented 8 years ago

@valeros please help @baronleonardo

valeros commented 8 years ago

Hi @baronleonardo Could you try such a workaround (latest file versions from TI website are used):

  1. Put new linker file beside your platformio.ini.
  2. Add new startup file to src directory.
  3. Add new library in lib directory (needed by linker script).
  4. Alter your platformio.ini according to this example:

platformio.ini:

[env:lptm4c1230c3pm]
platform = titiva
board = lptm4c1230c3pm
build_flags = -Wl,-Tproject.ld -Wl,--entry=ResetISR
baronleonardo commented 8 years ago

There is a strange problem! I can't get any delay function work!!

this is a sample of a delay function

void delay(unsigned long halfsecs)
{
  unsigned long count;
  while(halfsecs > 0 ) { // repeat while still halfsecs to delay
    count = 1538460;
// originally count was 400000, which took 0.13 sec to complete
// later we change it to 400000*0.5/0.13=1538460 that it takes 0.5 sec
    while (count > 0) {
      count--;
    } // This while loop takes approximately 3 cycles
    halfsecs--;
  }
}
baronleonardo commented 8 years ago

@ivankravets

valeros commented 8 years ago

@baronleonardo Could you please provide more details about your problem?

baronleonardo commented 8 years ago

I tried to make a simple delay function using something like the above example all my code runs as it should be .. but without delay! like the delay function doesn't do its job at all .. on the contrary, if I use the default project template ( not this customized one to program using only C ) it works perfectly I think there is a problem with startup_gcc.c .. may be something missing or something wrong IDK

valeros commented 8 years ago

What is your MCU working frequency?

baronleonardo commented 8 years ago

my microchip is Tiva TM4C123GH6PM, and I think it works with 80MHz clock

valeros commented 8 years ago

Hmm, let's calculate:

count value * 3 cycles = 1538460*3 = 4615380 cycles
1 cycle = 1/F_CPU = 1/80MHz = 12.5 ns
delay = 4615380 cycles * 12.5 ns = ~0.058s

Am I missing something?

baronleonardo commented 8 years ago

I have another delay I'm working with now I tried msec inputs that vary from 1 to 2 millions still no delay! and why it works perfectly on the default template!

void Delay1ms(unsigned long msec)
{
// write this function
    unsigned long counter;

    while( msec > 0 )
    {
        counter = 16000;
        while(counter-- > 0);
        msec--;
    }

}
valeros commented 8 years ago

What kind of "default template" do you mean?

baronleonardo commented 8 years ago

I mean the default way to create a project for that kind of micro controller platformio init --ide eclipse --board lptm4c1230c3pm

valeros commented 8 years ago

Looks like linker optimized delay function. Could you try to disable optimization? Just add next line to platformio.ini: build_flags = -O0

baronleonardo commented 8 years ago

Nah didn't work either

valeros commented 8 years ago

Try please with this linker script.

baronleonardo commented 8 years ago

I tried the new linker script with linked optimization and without it both failed :/

valeros commented 8 years ago

@baronleonardo Sorry, can't help you here. I don't have this board to debug. At last you can try this delay:

void Delay1ms(unsigned long msec) {
    volatile unsigned long counter;
    while( msec > 0 )  {
        counter = 16000;
        while(counter-- > 0);
        msec--;
    }
}
baronleonardo commented 8 years ago

I'm so so sorry the changes you gave me on comment is working perfectly I think the problem is about the clocking I used thank you .. you saved me :+1:

ivankravets commented 8 years ago

@baronleonardo Thanks a lot for the report! Please grant @valeros with star :star: https://github.com/platformio/platformio/stargazers.

baronleonardo commented 8 years ago

I want to, but how :D

ivankravets commented 8 years ago

@valeros likes these stars... :blush: Take a look at the top of this page where are buttons Watch | Stars | Fork.

baronleonardo commented 8 years ago

yeah yeah got it

baronleonardo commented 8 years ago

I need to use <stdio.h> to use malloc to create a struct in the heap but it complains from undefined reference to _sbrk @valeros

valeros commented 8 years ago

You need to implement _sbrk function for memory manipulation routine or use default implementation in "nosys" library build_flags = -lnosys and don't forget to specify heap section and end symbol in your linker script.

ItsNayabSD commented 8 years ago

@baronleonardo Did you take care of that delay issue? I am also facing the same problem. Except that everything works fine. If yes, please provide a solution.

baronleonardo commented 8 years ago

it was because of I didn't initialize and configure PLL the delay issue I face, was because I used the old-fashion while loop only without systick

try to initialize and configure PLL and systick

ivankravets commented 7 years ago

If you have any questions, please create new topic here https://community.platformio.org