Any idea about the error? (atmega328p - st7920 glcd lib instance declare)

Go To Last Post
38 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi there

I'm trying to implement st7920 lcd using m328p but having stupid error unbeatable!!

any suggestion?

P.S: code works well under arduino. but in atmel studio.

 

here is minimal code:

/*
 * GccApplication4.cpp
 *
 * Created: 2/17/2021 1:51:34 PM
 * Author : MJT
 */ 

#define F_CPU 8000000UL
#include <Arduino.h>
#include <avr/io.h>

#include <avr/pgmspace.h>
#include "ST7920_SPI.h"
#include "SPI.h"
#include "avrlibdefs.h"
#include "logo-contact.h"
// from PropFonts library
#include "c64enh_font.h"

ST7920_SPI lcd(PIND5);
int main(void)
{
    /* Replace with your application code */
    while (1) 
    {
    }
}

and error :

 

Severity    Code    Description    Project    File    Line
Error        ld returned 1 exit status    GccApplication4    collect2.exe    0
Error        recipe for target 'GccApplication4.elf' failed    GccApplication4    c:\users\mjt\Documents\Atmel Studio\7.0\GccApplication4\GccApplication4\Debug\Makefile    108
Error        undefined reference to `ST7920_SPI::ST7920_SPI(unsigned char)'    GccApplication4    c:\users\mjt\Documents\Atmel Studio\7.0\GccApplication4\GccApplication4\main.cpp    20
Warning        narrowing conversion of '-7' from 'int' to 'uint8_t {aka unsigned char}' inside { } is ill-formed in C++11 [-Wnarrowing]    GccApplication4    C:\Users\MJT\Documents\Atmel Studio\7.0\GccApplication4\GccApplication4\New folder\c64enh_font.h    123
Warning        extra tokens at end of #ifndef directive    GccApplication4    C:\Users\MJT\Documents\Atmel Studio\7.0\GccApplication4\GccApplication4\New folder\logo-contact.h    9
Warning        missing whitespace after the macro name    GccApplication4    C:\Users\MJT\Documents\Atmel Studio\7.0\GccApplication4\GccApplication4\New folder\logo-contact.h    10
Warning        non-static data member initializers only available with -std=c++11 or -std=gnu++11    GccApplication4    C:\Users\MJT\Documents\Atmel Studio\7.0\GccApplication4\GccApplication4\New folder\ST7920_SPI.h    122
Warning        non-static data member initializers only available with -std=c++11 or -std=gnu++11    GccApplication4    C:\Users\MJT\Documents\Atmel Studio\7.0\GccApplication4\GccApplication4\New folder\ST7920_SPI.h    123
Warning        non-static data member initializers only available with -std=c++11 or -std=gnu++11    GccApplication4    C:\Users\MJT\Documents\Atmel Studio\7.0\GccApplication4\GccApplication4\New folder\ST7920_SPI.h    124
Warning        non-static data member initializers only available with -std=c++11 or -std=gnu++11    GccApplication4    C:\Users\MJT\Documents\Atmel Studio\7.0\GccApplication4\GccApplication4\New folder\ST7920_SPI.h    146

error screen-atmel studio

 

and here is abbr working code from imported sketch:

#include <Arduino.h>
#include <avr/sfr_defs.h>



#include "ST7920_SPI.h"
#include "SPI.h"
#include "avrlibdefs.h"
#include "logo-contact.h"
// from PropFonts library
#include "c64enh_font.h"





ST7920_SPI lcd(PIND5);

.
.
.
.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

See this post https://www.avrfreaks.net/commen... - switch to the 'Output' window, instead of using that "Error list" view.

 

Do a clean & rebuild, then look at the very first error reported in the 'Output' window.

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well "undefined ref" means "I am seeing a call to foo() but nothing in all the linked files seems to be providing foo()"

 

In your case the error is:

undefined reference to `ST7920_SPI::ST7920_SPI(unsigned char)'  

So basically the file that contains the code of the ST7920_SPI class is probably not being presented to the build.

 

The other thing that may be going on is that there is no overload to match. Perhaps the ST7920_SPI class code is built but the only variants of the c'tor are:

ST7920_SPI() {
    // stuff
}

ST7920_SPI(double d) {
    // stuff
}

and what it is really telling you that it doesn't have a variant taking uchar (actually I think promotion rules might implicitly promote a uchar to double and use that one??).

 

PS as this in Arduino import it could simply be that the AS7 import process failed in some way and failed to recognise that the ST7920_SPI class code needed to be pulled into the build.

Last Edited: Wed. Feb 17, 2021 - 11:51 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
The other thing that may be going on is that there is no overload to match.

Wouldn't that give a compiler error, though?

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

amirdelta wrote:
imported sketch

Describe how you got the "sketch" imported into Atmel Microchip Studio.

 

clawson wrote:
it could simply be that the AS7 import process failed

Indeed - there's been a number of threads recently about the import process not working.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I would build the library example sketch(s) in the Arduino IDE.   Verify that everything is working.

 

Then import the example sketch into AS7.0

 

If you have trouble,   just quote the example sketch name,  library(s), ... from the Arduino build.

Then I will attempt to replicate your problem for myself.

I am not going to guess.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

See this post https://www.avrfreaks.net/commen... - switch to the 'Output' window, instead of using that "Error list" view.

 

Do a clean & rebuild, then look at the very first error reported in the 'Output' window.

 

 

hi

Thanks for the advice,

You may omit the output window posted above the error list in the first post. laugh

I've already familiar with the output window and checked the corresponding post you referred to.

but no success.sad

thanks again.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

Well "undefined ref" means "I am seeing a call to foo() but nothing in all the linked files seems to be providing foo()"

 

In your case the error is:

undefined reference to `ST7920_SPI::ST7920_SPI(unsigned char)'  

So basically the file that contains the code of the ST7920_SPI class is probably not being presented to the build.

 

The other thing that may be going on is that there is no overload to match. Perhaps the ST7920_SPI class code is built but the only variants of the c'tor are:

ST7920_SPI() {
    // stuff
}

ST7920_SPI(double d) {
    // stuff
}

and what it is really telling you that it doesn't have a variant taking uchar (actually I think promotion rules might implicitly promote a uchar to double and use that one??).

 

PS as this in Arduino import it could simply be that the AS7 import process failed in some way and failed to recognise that the ST7920_SPI class code needed to be pulled into the build.

 

 

hi
I think the problem lays behind something like this, but I can't understand why!
I've added a copy of the Arduino.h file with minor modification to minimize the code manipulation in lib, but
no success again.

there isn't any sketch ready to use, I imported the sample code was on a git and sorted out the modifications
needed, and import it to microchip studio(that I'm not using now), the result was just right and the code worked on my
own PCB as well.
but when I try to get rid of Arduino infrastructure...  no way

I think it would be better to attach the sample project for further checking.
may I ask you to kindly help and take a look at it?

br

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

amirdelta wrote:
imported sketch

Describe how you got the "sketch" imported into Atmel Microchip Studio.

 

 

hi
luckily mine works well and adopted the project without any problem.
but when I try to transfer the project from Arduino to AVR, the class does not declare in a correct way.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:

I would build the library example sketch(s) in the Arduino IDE.   Verify that everything is working.

 

Then import the example sketch into AS7.0

 

If you have trouble,   just quote the example sketch name,  library(s), ... from the Arduino build.

Then I will attempt to replicate your problem for myself.

I am not going to guess.

 

David.

hi David,
I did the overall process as you said.
everything works in the Arduino environment, even when the project is imported to the microchip studio.
but when I remove the Arduino core and try to adopt the project, the class seems to has the error.

I'm going to add the project file in the next post.
any helps is appreciated and welcomed.laugh

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here is the file

there could be obvious errors as I've never able to compile the code or pass this one.

please do not blame if there was any...

thanks

 

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

amirdelta wrote:
You may omit the output window posted above the error list in the first post

No, what you posted in #1 is not the Atmel Studio Output window - you've just copied & pasted the errors list.

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I connected a ST7920 module to Arduino Uno.   Ran the ST7920_SPI library examples via the Arduino IDE.

 

Then imported the same ST7920_SPI library examples into AS7.0.

Built and ran exactly the same as Arduino IDE.

 

It is a mystery why anyone would want to build code in AS7.0 when the Arduino IDE works 100%.

 

But once you have imported an Arduino sketch you can modify the code in AS7.0
You will still be using the "Arduino Core" that was originally imported.   i.e. all the regular Arduino functions like pinMode(), analogRead(), ...

 

You can even import extra Arduino libraries to this AS7.0 solution as required.

 

You can't run Arduino code without the Arduino Core functions.

Some Third Party Libraries might not use any Arduino functions at all.

However ST7920_SPI does use Arduino functions.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yeah
It was interesting to me too as I've never used arduino platform.
But Every thing works fine.

But there isn't any advance in error :-(((

I don't want to convert the library to c.
Any idea or test??

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I strongly recommend that you stick with Arduino.

 

There are libraries and example code for almost everything.

It is an excellent way to get a prototype running.

 

But it is also a very good way to get finished applications too.

 

And if you have any problems you can post Arduino code in the knowledge that everyone in any country in the world can help you.

 

Oh,  and cbm80amiga has some impressive examples.   The ST7920 works pretty well !!

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You know what "habit" means? laugh

I've been coding for a long time in the compactest way I was able to(using registers directly and defining them in my own way).

migrating to Arduino platform is almost impossible!!   laughsmiley

And I refer to Arduino example projects to extract what is needed case by case.

 

I used cbm80amiga lib to use st7920 LCD and works well.

I tried to adopt the library for use in as7, but mentioned error stopped me at the point I've told.

br

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

amirdelta wrote:
coding for a long time in the compactest (sic) way I was able to(using registers directly and defining them in my own way).

Depends how you define "compact" - things like Arduino can make your source code a lot more compact by not having to laboriously spell-out in detail all the  arcane details of every single register.

 

You know what "habit" means?

and you know that you can break habits, and learn new things?

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

amirdelta wrote:

You know what "habit" means? laugh

I've been coding for a long time in the compactest way I was able to(using registers directly and defining them in my own way).

You can still pick up tips from other people's code

 

amirdelta wrote:

migrating to Arduino platform is almost impossible!!   laughsmiley

And I refer to Arduino example projects to extract what is needed case by case.

You can create your own "helper functions"

 

amirdelta wrote:

I used cbm80amiga lib to use st7920 LCD and works well.

I tried to adopt the library for use in as7, but mentioned error stopped me at the point I've told.

Your AS7.0 project has not been designed correctly.    Learn how to import Arduino Core and add Arduino libraries correctly.

 

When you have everything working nicely in AS7.0 you can replace sections with your "home-grown" code.

 

Seriously.   cbm80amiga has done a good job.   I am sure that you can make some improvements in C++.    Or even re-write it all in C.

Most things in Arduino work pretty well.    But occasionally you will encounter some inefficient code.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

amirdelta wrote:
coding for a long time in the compactest (sic) way I was able to(using registers directly and defining them in my own way).

Depends how you define "compact" - things like Arduino can make your source code a lot more compact by not having to laboriously spell-out in detail all the  arcane details of every single register.

 

You know what "habit" means?

and you know that you can break habits, and learn new things?

 

I've to say yeah,

I believe that everyone had to break less useful habits in favor of more efficient options creates by the time.

but the transformation time, does not worth the price sometimes. (for example, I don't think it's a good idea to learn Arduino because I have to

use an uncommon LCD just for one of my projects based on there is a wonderful library already written in Arduino.

On the other hand, I don't think I'm going to create a serious project based on the Arduino platform in a long run.

Admittedly, I'll use the Arduino potentials and well-documented libraries where needed or to correct my weaknesses.

BR

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:

 

Your AS7.0 project has not been designed correctly.    Learn how to import Arduino Core and add Arduino libraries correctly.

 

When you have everything working nicely in AS7.0 you can replace sections with your "home-grown" code.

 

Seriously.   cbm80amiga has done a good job.   I am sure that you can make some improvements in C++.    Or even re-write it all in C.

Most things in Arduino work pretty well.    But occasionally you will encounter some inefficient code.

 

David.

 

Thanks, David

as I said in post #1, the uploaded project is my lightest possible code to point directly to the problem I call it weird.

And I've already completed the successful version of imported library in as7.

I think I'm able to do it again but I'm interested in this issue because it's uncommon to me.

 

Anyway, I'm going to write the class directly in as7 to face the problem alone! laugh

to discover where the evil hid laugh

Thanks to all contributors.

yes

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

amirdelta wrote:
the uploaded project is my lightest possible code to point directly to the problem I call it weird.

No, it's not weird at all: you've clearly made it too light by missing out a required library (binary or source).

 

clawson explained that in #3.

 

 

I'm interested in this issue because it's uncommon to me.

Actually, it is very common indeed - usually comes from including just a header without the necessary supporting source or binary code to complete the library.

 

Only yesterday: https://community.arm.com/develo...

 

and the day before: https://community.st.com/s/quest...

 

The above highlighting that it is nothing specifically to do with Atmel Microchip Studio - it is standard C (and C++) stuff.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

amirdelta wrote:
the uploaded project is my lightest possible code to point directly to the problem I call it weird.

No, it's not weird at all: you've clearly made it too light by missing out a required library (binary or source).

 

clawson explained that in #3.

 

 

I'm interested in this issue because it's uncommon to me.

Actually, it is very common indeed - usually comes from including just a header without the necessary supporting source or binary code to complete the library.

 

Only yesterday: https://community.arm.com/develo...

 

and the day before: https://community.st.com/s/quest...

 

The above highlighting that it is nothing specifically to do with Atmel Microchip Studio - it is standard C (and C++) stuff.

 

I've tried to bring everything needed to judge in a screenshot:

 

microchip studio 7 output window

 

you could see the error in the output window, solution explorer and included files and files open in IDE.

project files are ready to download in post #11

may I ask you to do me a favor and load the solution(of course if you have the IDE installed) to take a closer look?

BR

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That picture does not show ST7920_SPI.CPP within GccApplication4 so it's not part of the project being built!?!?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


clawson wrote:
That picture does not show ST7920_SPI.CPP within GccApplication4

what about:

 

 

I don't have Arduino installed, so I don't see it at all:

 

@amirdelta:   again, if you would include the entire 'Output' window content - copy and paste as text, not a screenshot - then we'd be able to see exactly what is being built.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


 

 

Andy,

 

That is in the Solution not the project. For example main.cpp is "below" the GccApplication4 entry which is the actual project.

 

To be honest I'm not actually sure what "Solution Items" are or how they got there? It's true that in VS2017 I often have "filters" outside of any actual project in the solution (the thing I work on has a heirarchy of about 30 configuration files and I keep a tree of those inside a separate "filter" alongside the projects for libs/dlls that actually make up the binary image. But AS7/MCS7 does not support such "filters" so the "Solution Items" there is a bit of a mystery to me. But anyway when MSBuild is told to "build GccApplication4" as one of the projects in the solution it will only be using things within that.

 

EDIT: OK so I see how that could have been created:

 

but I'm not sure why one would? And if this is like the other bits of AS7 this would actually create a directory on disk called "Solution Items" as I don't think it does "filters".

 

EDIT: oh now this is ODD. At the Project level you cannot create "filters" but it seems that at the Solution level this "new solution folder" is acting like a Visual Studio filter. It does not create an actual directory on disk at this level and then you can group items into it but, unlike projects, the default action of [add] is not to "copy to current folder then add" but the [Add] really does act like "Add as link".

 

 

When you "build solution" anything in such a solution folder is ignored completely - even .c or .cpp files. So it seems to be a way to "add stuff I might want look at or edit but is not part of any project in the solution"

 

If you had a hierarchy of config files or something like that then I guess this would be the place to put it. I just tried nesting...

 

 

For foo.c I used "Add new item" - the file was actually placed at the solution directory level.

Last Edited: Wed. Feb 24, 2021 - 11:20 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


I see.

 

They actually seem to be in a folder named "444":

 

 

So dunno why SPI.cpp does show up in my Solution, but ST7920_SPI.cpp doesn't ?

 

@amirdelta  - are you sure you attached the correct project file?

 

 

EDIT

 

If I add them to the Project:

 

 

I then get:

 

 

So the Include Paths are not correctly set in that Project

 

 

EDIT 2

 

The project has a hard-coded absolute path for OP's computer:

 

 

 

 

EDIT 3

 

If you add the paths via the browse button, and check 'Relative Path':

 

You won't get that problem:

 

 

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Wed. Feb 24, 2021 - 11:41 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

It is perfectly possible to just take the ST7920_SPI CPP and H files.

 

But this means that you have to provide all the necessary Arduino symbols, classes and functions to support them.  e.g.

 

SPI class.

digitalWrite(),  pinMode(), delay(), ... functions.

 

Yes,   I can write them.   You can write them.   They are not particularly difficult.

 

But writing them is a LOT more work than simply importing the Arduino Core.

 

Not only do you have to write the support files but you must learn where and how to add a file to an AS7.0 project.

 

We can probably help you with writing AS7.0 projects.    I suggest that you start with something that is much simpler.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Having done all that, the project does not build at all: F_CPU undefined; SPI pins undefined, isdigit() undefined.

 

So clearly that's not the complete project.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
We can probably help you with writing AS7.0 projects

 

Only last week: https://www.avrfreaks.net/forum/learning-atmel-studio-7

 

david.prentice wrote:
I suggest that you start with something that is much simpler.

Absolutely!

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

clawson wrote:
That picture does not show ST7920_SPI.CPP within GccApplication4

what about:

 

 

I don't have Arduino installed, so I don't see it at all:

 

@amirdelta:   again, if you would include the entire 'Output' window content - copy and paste as text, not a screenshot - then we'd be able to see exactly what is being built.

 

 

As you can see below, I've added the project dependency folder in the projects "directory" setting under the project properties window in the toolchain:

microchip studio 7 project properties window

 

and attached the output window content as a text file.

that's really kind of you.

I appreciate your efforts and the time you work on it.

BR

 

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Look the key thing is here:

"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-g++.exe" -o GccApplication4.elf  main.o   -Wl,-Map="GccApplication4.map"
-Wl,--start-group -Wl,-lm  -Wl,--end-group -Wl,--gc-sections -mmcu=atmega328p -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.132\gcc\dev\atmega328p"  

The *only* file being linked is main.o. What this should really look like is:

"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-g++.exe" -o GccApplication4.elf  main.o ST7920_SPI.o  -Wl,-Map="GccApplication4.map"
-Wl,--start-group -Wl,-lm  -Wl,--end-group -Wl,--gc-sections -mmcu=atmega328p -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.132\gcc\dev\atmega328p"  

ST7920_SPI.o does not appear in the list currently because it is NOT A FILE IN THE PROJECT.

 

I've already said that files to be built in the GccApplication4 project need to be listed in the Solution Explorer within the GccApplication4 project. Use "Add existing item" to make them appear there. The fact that the file also happens to be listed under "Solution Items" does NOT make it part of the build.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've to add some words:

I remember initially added the address relatively(I'm not sure really now, but I always do that this way).

static addressing is not a problem fortunately, as the project hosted on my own machine.

If you check the content of the Arduino.h file I added to the 444 folder, you will see that some modifications are done in order to minimize the usage of Arduino core

but I kept the file to minimize the incoming errors(almost defines left, everything else commented) to direct to the main problem.

 

All of the above modifications done in order to upload a lightweight version of what I've done to present the error.

BR

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@amirdelta:  You appear to have missed #26 ?

 

clawson wrote:
The *only* file being linked is main.o.

Indeed.

 

Also, earlier in the build output, the only file being compiled is main.cpp

 

@amirdelta:  that is presumably why none of the other build errors (see #26) showed up in your build - because your project is simply not building them at all

 

clawson wrote:
What this should really look like is:

"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-g++.exe" -o GccApplication4.elf  main.o ST7920_SPI.o  -Wl,-Map="GccApplication4.map"
-Wl,--start-group -Wl,-lm  -Wl,--end-group -Wl,--gc-sections -mmcu=atmega328p -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.132\gcc\dev\atmega328p"  

presumably also SPI.o ?

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

amirdelta wrote:
static addressing is not a problem fortunately, as the project hosted on my own machine.

But it makes it impossible to build it on any other machine!

 

If you want others to build your project, you need to make it portable.

 

All of the above modifications done in order to upload a lightweight version of what I've done to present the error.

Again, you've cut too much out - you are missing essential functions!

 

And, as clawson said, and I illustrated, your project is not correctly set up.

 

As David said, I think you need to spend some time on the basics of setting up a Microchip Studio Project.

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Wed. Feb 24, 2021 - 12:45 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

Look the key thing is here:

"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-g++.exe" -o GccApplication4.elf  main.o   -Wl,-Map="GccApplication4.map"
-Wl,--start-group -Wl,-lm  -Wl,--end-group -Wl,--gc-sections -mmcu=atmega328p -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.132\gcc\dev\atmega328p"  

The *only* file being linked is main.o. What this should really look like is:

"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-g++.exe" -o GccApplication4.elf  main.o ST7920_SPI.o  -Wl,-Map="GccApplication4.map"
-Wl,--start-group -Wl,-lm  -Wl,--end-group -Wl,--gc-sections -mmcu=atmega328p -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.132\gcc\dev\atmega328p"  

ST7920_SPI.o does not appear in the list currently because it is NOT A FILE IN THE PROJECT.

 

I've already said that files to be built in the GccApplication4 project need to be listed in the Solution Explorer within the GccApplication4 project. Use "Add existing item" to make them appear there. The fact that the file also happens to be listed under "Solution Items" does NOT make it part of the build.

 

You're right

let me build a new clean project and check again.

I hope to jump this barrier this time thanks to you.

P.S: unfortunately I'm not familiar with linker errorssad

TNX

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here is your project building OK (attached)

 

Note that in main.cpp I commented the line that includes c64enh_font.h because (a) it is not needed and (b) it contains a serious error.

 

The C compiler throws an error because of:

const uint8_t c64enh[] PROGMEM =
{
-7, 8, 32, '~'+1+18,   // -width, height, firstChar, lastChar
        0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  //  

what it says is:

		In file included from .././main.cpp:17:0:
D:\test\GccApplication4\GccApplication4\444\c64enh_font.h(123,1): error: narrowing conversion of '-7' from 'int' to 'uint8_t {aka unsigned char}' inside { } [-Wnarrowing]
		 };

That is because the PROGMEM data shouldn't just be an array of uint8_t but something like:

typedef {
    int8_t width;
    uint8_t height;
    uint8_t firstChar;
    uint8_t lastChar;
    uint8_t font_data[];
} font_t;

const font_t c64enh PROGMEM = {
    -7,
    8,
    32,
    '~' + 1 + 18,
    {
        0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  //  
        0x02, 0x5F, 0x5F, 0x00, 0x00, 0x00, 0x00, 0x00,  // !
        0x06, 0x07, 0x07, 0x00, 0x00, 0x07, 0x07, 0x00,  // "
        etc.        
    }
}

or something along these lines. The fact that the original author did not do it like this (with the data array proceeded by metadata in the header) makes me very suspicious about the provenance of this code!

Attachment(s): 

Last Edited: Wed. Feb 24, 2021 - 12:48 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

amirdelta wrote:
unfortunately I'm not familiar with linker errors

It's all very well saying that you don't want to use the Arduino stuff - but that means you're going to have to take on responsibility for understanding and managing the whole build process yourself.

 

This is all standard C (and C++) stuff - not really specific to Microchip Studio or AVRs

 

See this thread https://www.avrfreaks.net/forum/avr-gcc-compiling-linking-and-assembly for an overview of the full build process - preprocessor, compiler/assembler, linker, etc

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi

after working for an hour on the project and building it again from the beginning with some patient, I succeed to compile the project

finally.

I had to sort out about 164 errors laugh because I removed Arduino core files completely.

 

Let me tell you a story, last year I was working on a gsm controlled device to manage some hydraulic valves to do something...

I used AtXmega32A4u as the core controller and everything was fine until the last stages of development.

I decided to use uart for user-level maintenance and debug system(with a bunch of serial logs through the terminal).

then sudden restarts started to occur under the final tests when I was trying to send long config strings to the device(it was ok with short messages).

after investigating the roots, found out SRAM deficit causes the problem while after compilation I only used about 95% of SRAM.

a few days ago it occurred again with my new project even when I was using about 88% of Sram.

I keen to use st7920 LCD because of the affordable price in my market(around 5$)  and really well library(about 25 FPS using 1k SRAM in 8Mhz)

with ready-to-use graphics.

As the whole project was based on Arduino(for the first time), I started to optimize SRAM usage by migration from Arduino with no success at the end.

So I decided to turn the project into a bare AVR to optimize the use of Sram.

 

After all, it was a great lesson for me (thanks to your precious help).

Learned a lot about well-designed Arduino core, performance, libraries and why should not use it!  laugh

 

for example:

 

void digitalWrite(uint8_t pin, uint8_t val)
{
	uint8_t timer = digitalPinToTimer(pin);
	uint8_t bit = digitalPinToBitMask(pin);
	uint8_t port = digitalPinToPort(pin);
	volatile uint8_t *out;

	if (port == NOT_A_PIN) return;

	// If the pin that support PWM output, we need to turn it off
	// before doing a digital write.
	if (timer != NOT_ON_TIMER) turnOffPWM(timer);

	out = portOutputRegister(port);

	uint8_t oldSREG = SREG;
	cli();

	if (val == LOW) {
		*out &= ~bit;
	} else {
		*out |= bit;
	}

	SREG = oldSREG;
}

Equals:

sbi(buzzer_port,buzzer_pin_num);

Or:

reg |= (BV(bit));

angry

 

I know it designed to prevent primitive mistakes, but not for me. wink

 

its time for me to go back and learn more, starting:

 https://www.avrfreaks.net/forum/avr-gcc-compiling-linking-and-assembly

 

https://www.avrfreaks.net/forum/learning-atmel-studio-7

 

Please accept my apologies and Thank you for your support, guidance, and encouragement.

BR