how to add library c and h files to new project - makefile errors

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

I'm trying to rewrite a bootloader without including any arduino headers as it always gets out of range errors.

I was trying to use arduino LCD lib to put notes n the LCD by the bootloader.

 

Instead, I  wanted to use the Davide Gironi i2c and lcd code from his avr_lib_lcdpcf8574_02.zip download.

 

I just added all the .c and .h files to my project, all in the same directory and corrected the .h references, removing the folders.

And added my code folder as an Include folder.

I get a build for them in the make file, but they all error compiling the.o files.

 

The only code I want to import is to write to the I2c 4x20 LCD, the rest is just my own USART and midi code.

All the added c files fail, only main compiles.

 

How do I correctly add his code to my project?

 

Thanks,

David

 

Severity    Code    Description    Project    File    Line
Error        recipe for target 'lcdpcf8574.o' failed    GreenbriarBootLoader    c:\Users\grnbr\Documents\Atmel Studio\7.0\GreenbriarBootLoader\GreenbriarBootLoader\Debug\Makefile    96

# AVR32/GNU C Compiler
./lcdpcf8574.o: .././lcdpcf8574.c
    @echo Building file: $<
    @echo Invoking: AVR/GNU C Compiler : 5.4.0
    $(QUOTE)F:\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE)  -x c -funsigned-char -funsigned-bitfields -DDEBUG  -I"F:\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\include" -I"C:\Users\grnbr\Documents\Atmel Studio\7.0\GreenbriarBootLoader\GreenbriarBootLoader"  -O1 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -mrelax -g2 -Wall -mmcu=atmega2560 -B "F:\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\gcc\dev\atmega2560" -c -std=gnu99 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)"   -o "$@" "$<" 
    @echo Finished building: $<

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

You DO NOT "add" header files. You #include them. 

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

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

grnbriar wrote:
Error        recipe for target 'lcdpcf8574.o' failed    GreenbriarBootLoader    c:\Users\grnbr\Documents\Atmel Studio\7.0\GreenbriarBootLoader\GreenbriarBootLoader\Debug\Makefile    96
Need more context - show the complete build output.

 

Also why on earth would you complicate a bootloader with LCD support anyway? A bootloader has to be small, simple and robust. It's the only thing that has to be 100% correct on day one as everything else can be replaced/fixed. But the bootloader cannot. So make it as simple as possible - forget the eye candy. It only runs once for 20 seconds every 6 months to a year or whatever your release cycle is. If the user needs to be "entertained" flash an LED at them or something.

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

Yes, I '#include' the headerfiles, but it still has to build the two c files that I downloaded and it fails.

 

I have only used my own code and standard avr includes before, not someone else's public code. On PC projects I've built other folks code as a lib and used it. Here, there was no project to build this as a lib, just source code, which I am apparaently not using correctly.

 

I need to tell users when to start the midi transmission and I have the lcd, so I was hoping to use it.

The rest of the bootloader is done.

 

This is also the first time I've ever used the Arduino IDE. It sped up project development for the main app,.

But for the bootloader, I figured out that as soon as I put the #include arduino.h in the project, the move to boot loader address was 'out of range'.

No out of range error with a new studio project, so I was looking for some code to access the I2C 4x20 lcd without having to reinvent everything.

 

David

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

grnbriar wrote:

I need to tell users when to start the midi transmission and I have the lcd, so I was hoping to use it.

The rest of the bootloader is done.

I'd tell them to start the MIDI transfer when the red LED flashes or something ;-)

 

Anyway either zip the whole project or at the very least show the complete built output.

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

I think I finally understand how to include them - I was adding the c files to my project and including the headers, did not work.

It seems odd to me, but by including everything, it now compiles.

And all the arduino addins it lets me set address to correct bootloader address - .text=$1F000 (for correct E000 byte address output in hex file).

 

Thanks for the help,

David

 

Working test app: with .text=$1F00 in FLASH memories and path to downloaded code folder

#include <avr/io.h>

#define F_CPU 16000000UL

#include <stdio.h>
#include <stdlib.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <util/delay.h>

#include "i2chw/i2cmaster.h"
#include "i2chw/twimaster.c"

#include "pcf8574/pcf8574.h"
#include "pcf8574/pcf8574.c"

#include "lcdpcf8574/lcdpcf8574.h"
#include "lcdpcf8574/lcdpcf8574.c"

int main(void)
{
    
    lcd_init(LCD_DISP_ON_BLINK);
    lcd_home();
    
    while(1)
    {
        //TODO:: Please write your application code 
    }
}

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

correction - and WITHOUT all the arduino addins it lets me set address to correct bootloader addrss.

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

edit the makefile to include all the missing *.c files, for example, if you have a source file called sensor.c,then you should somehowbe able to see/do something like this :

SRC_FILES += \ 

$(PROJ_DIR)/src/sensor.c \

 

Last Edited: Wed. Aug 14, 2019 - 12:25 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Removed the included c files and added them in a folder in the project as linked to their original location.

Then just had to add the F_CPU to the c files before including delay and now the project looks more normal.

 

Now back to working on the sysex bootloader part - very simple one - just binary bytes to nibbles and back.

 

Thanks

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

Is that the correct way to use these downloaded files in my own project?

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

Don't ever be tempted to #include .c files. It's never a great idea. Just build C code as Kernighan and Ritchie originally intended it to be done ;-)

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

I've never #included them before, but adding them to my project did not work. Not real sure what I was doing wrong, but got them working now with a link add.