Fatal error opening dependency file dep main o d no such file or directory

Патчим WinAVR :: Совместимость WinAVR и Windows 10 При компиляции кода в WinAVR-20100110, установленном в Windows 10, в окне вывода сообщений компилятора (Output), можно увидеть подобный текст: >»make.exe» all 0 [main] sh 5408 sync_with_child: child 2268(0x174) died before initialization with status code 0xC0000142 53538 [main] sh 5408 sync_with_child: *** child state waiting for longjmp /usr/bin/sh: […]
При компиляции кода в WinAVR-20100110, установленном в Windows 10, в окне вывода сообщений компилятора (Output), можно увидеть подобный текст:

>»make.exe» all
0 [main] sh 5408 sync_with_child: child 2268(0x174) died before initialization with status code 0xC0000142
53538 [main] sh 5408 sync_with_child: *** child state waiting for longjmp
/usr/bin/sh: fork: Resource temporarily unavailable
0 [main] sh 4940 sync_with_child: child 3648(0x174) died before initialization with status code 0xC0000142
28181 [main] sh 4940 sync_with_child: *** child state waiting for longjmp
/usr/bin/sh: fork: Resource temporarily unavailable

——— begin ———
avr-gcc (WinAVR 20100110) 4.3.3
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Compiling C: my_test.c
avr-gcc -c -mmcu=atmega8 -I. -gdwarf-2 -DF_CPU=1000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wundef -Wa,-adhlns=obj/my_test.lst -std=gnu99 -Wundef -MD -MP -MF .dep/my_test.o.d my_test.c -o obj/my_test.o
my_test.c:31: fatal error: opening dependency file .dep/my_test.o.d: No such file or directory
compilation terminated.
make.exe: *** [obj/my_test.o] Error 1

> Process Exit Code: 2
> Time Taken: 00:05

Устраняем ошибки работы
WinAVR в Windows 10

Ошибка компиляции происходит из-за проблем с DLL Cygwin, которая реализует стандарт POSIX в Windows-системах. Cygwin является средством для портирования UNIX-программ в OS Windows и представляет собой библиотеку, которая обеспечивает интерфейс POSIX на основе системных вызовов Windows.

myROBOT WinAVR Patch устраняет проблему совместимости WinAVR с Windows 10, Windows 8.1.

Патч ничего не меняет и не затрагивает в операционной системе, а лишь исправляет неправильную работу одного из файлов в самой WinAVR.

Кроме того, патч устраняет ошибку обработки функций, присутствовавших в WinAVR до версии 20050214 (подробнее в статье «AVR-GCC :: СОВМЕСТИМОСТЬ КОДА»). Позволяет использовать любые примеры кода, существующие в интернет.

Источник

Linux: Makefile: fatal error: opening dependency file

Q-1. What is the difference between the below compilation errors in using Makefiles?

fatal error: opening dependency file : Input/output error

fatal error: opening dependency file : Permission denied

fatal error: opening dependency file : No such file or directory

Q-2. How do we correct each of them?

1 Answer 1

I agree with @larks/ sounds like a homework question but important thing is «learning something». I will write answers but read them carefully and Google it next time.

For understanding the error types, you should read the error code. Differences of error types are quite clear.

Input/Output errors during filesystem access attempts mostly mean hardware issues. But sometimes missing libraries can cause this error type as well.

Permission denied is error type that you do not have permission to write related file or directory. That means you should add the permission to your current user or access root permissions.

No such file or directory is self descripted. This program tries to write or read a file that doesn’t exist. For solving this problem you should check your env options or create manually (not recommended way).

Источник

fatal error: opening dependency file

I am trying to use ECC library on contiki os.
But I got a error for dependency. I think the problem is with my Makefile but I am not sure where is wrong.

I downloaded from the source https://github.com/nist-emntg/ecc-light-certificate, but I had problem using git submodule update after I git clone from the source, so I manually download and paste the contiki file into the contiki folder.
Could this be the problem?

This is my makefile

1 Answer 1

but I had problem using git submodule update after I git clone from the source, so I manually download and paste the contiki file into the contiki folder.

You cannot then just download any contiki file, since the idea of a submodule is to reference an exact SHA1 of another repo.

Try again to clone the main repo, this time with —recursive (and make sure to use the latest Git 2.11.1)

However, looking at its commit page 7a493c4, you can see it does not belong to any branch or tag: it is a commit still kept in the GitHub remote repo, but not fetch by default (because, again, no branch or tag includes it)

You need to open an issue on nist-emntg/ecc-light-certificate/issues project to alert them on that non-existing commit reference for the submodule contiki.

If you look for that commit message, you will find commit 1396dfd from the native fix-native-build branch:

This is typical of a cherry-picked commit.

To solve your current situation, directly checkout the right commit:

Источник

CodeLite IDE

./Debug/main.cpp.o.d: No such file or directory

./Debug/main.cpp.o.d: No such file or directory

Post by ravenspoint » Wed Oct 18, 2017 9:30 pm

When I try to build hello world I get:

C:Windowssystem32cmd.exe /C C:/TDM-GCC-64/bin/mingw32-make.exe -j4 SHELL=cmd.exe -e -f Makefile
«———-Building project:[ test1 — Debug ]———-»
mingw32-make.exe[1]: Entering directory ‘C:/Users/James/code/codelite_test1/test1’
: fatal error: opening dependency file ./Debug/main.cpp.o.d: No such file or directory
compilation terminated.
mingw32-make.exe[1]: *** [Debug/main.cpp.o.d] Error 1
mingw32-make.exe[1]: *** Waiting for unfinished jobs.
test1.mk:99: recipe for target ‘Debug/main.cpp.o.d’ failed
Access is denied.
mingw32-make.exe[1]: *** [Debug/.d] Error 1
mingw32-make.exe: *** [All] Error 2
test1.mk:88: recipe for target ‘Debug/.d’ failed
mingw32-make.exe[1]: Leaving directory ‘C:/Users/James/code/codelite_test1/test1’
Makefile:4: recipe for target ‘All’ failed
====1 errors, 0 warnings====

If I try from a command prompt

C:UsersJamescodecodelite_test1>C:Windowssystem32cmd.exe /C C:/TDM-GCC-64/bin/mingw32-make.exe -j4 SHELL=cmd.exe -e -f Makefile
«———-Building project:[ test1 — Debug ]———-»
mingw32-make.exe[1]: Entering directory ‘C:/Users/James/code/codelite_test1/test1’
‘makedir’ is not recognized as an internal or external command,
operable program or batch file.
test1.mk:88: recipe for target ‘Debug/.d’ failed

Re: ./Debug/main.cpp.o.d: No such file or directory

Post by eranif » Wed Oct 18, 2017 10:09 pm

Re: ./Debug/main.cpp.o.d: No such file or directory

Post by ravenspoint » Wed Oct 18, 2017 10:20 pm

Fails is a different way

C:UsersJamescodecodelite_test1test1>C:Windowssystem32cmd.exe /C C:/TDM-GCC-64/bin/mingw32-make.exe -j4 SHELL=cmd.exe -e -f Makefile
mingw32-make.exe: Makefile: No such file or directory
mingw32-make.exe: *** No rule to make target ‘Makefile’. Stop.

However, if i go up one «cd ..» then it fails in the same way.

Re: ./Debug/main.cpp.o.d: No such file or directory

Post by eranif » Thu Oct 19, 2017 9:21 am

Yes, you need to run it from the exact same folder as CodeLite, which is the «Workplace» level

Can you paste the *entire* content of the error message + the generated makfile (that one with the .mk file, not the one named «Makefile»)

Re: ./Debug/main.cpp.o.d: No such file or directory

Post by ravenspoint » Thu Oct 19, 2017 5:51 pm

I pasted the entire error message in my original post

Here is the mk file

##
## Auto Generated makefile by CodeLite IDE
## any manual changes will be erased
##
## Debug
ProjectName :=test1
ConfigurationName :=Debug
WorkspacePath :=C:/Users/James/code/codelite_test1
ProjectPath :=C:/Users/James/code/codelite_test1/test1
IntermediateDirectory :=./Debug
OutDir := $(IntermediateDirectory)
CurrentFileName :=
CurrentFilePath :=
CurrentFileFullPath :=
User :=James
Date :=18/10/2017
CodeLitePath :=»C:/Program Files/CodeLite»
LinkerName :=C:/TDM-GCC-64/bin/g++.exe
SharedObjectLinkerName :=C:/TDM-GCC-64/bin/g++.exe -shared -fPIC
ObjectSuffix :=.o
DependSuffix :=.o.d
PreprocessSuffix :=.i
DebugSwitch :=-g
IncludeSwitch :=-I
LibrarySwitch :=-l
OutputSwitch :=-o
LibraryPathSwitch :=-L
PreprocessorSwitch :=-D
SourceSwitch :=-c
OutputFile :=$(IntermediateDirectory)/$(ProjectName)
Preprocessors :=
ObjectSwitch :=-o
ArchiveOutputSwitch :=
PreprocessOnlySwitch :=-E
ObjectsFileList :=»test1.txt»
PCHCompileFlags :=
MakeDirCommand :=makedir
RcCmpOptions :=
RcCompilerName :=C:/TDM-GCC-64/bin/windres.exe
LinkOptions :=
IncludePath := $(IncludeSwitch). $(IncludeSwitch).
IncludePCH :=
RcIncludePath :=
Libs :=
ArLibs :=
LibPath := $(LibraryPathSwitch).

##
## Common variables
## AR, CXX, CC, AS, CXXFLAGS and CFLAGS can be overriden using an environment variables
##
AR := C:/TDM-GCC-64/bin/ar.exe rcu
CXX := C:/TDM-GCC-64/bin/g++.exe
CC := C:/TDM-GCC-64/bin/gcc.exe
CXXFLAGS := -g -O0 -Wall $(Preprocessors)
CFLAGS := -g -O0 -Wall $(Preprocessors)
ASFLAGS :=
AS := C:/TDM-GCC-64/bin/as.exe

##
## User defined environment variables
##
CodeLiteDir:=C:Program FilesCodeLite
Objects0=$(IntermediateDirectory)/main.cpp$(ObjectSuffix)

##
## Main Build Targets
##
.PHONY: all clean PreBuild PrePreBuild PostBuild MakeIntermediateDirs
all: $(OutputFile)

$(OutputFile): $(IntermediateDirectory)/.d $(Objects)
@$(MakeDirCommand) $(@D)
@echo «» > $(IntermediateDirectory)/.d
@echo $(Objects0) > $(ObjectsFileList)
$(LinkerName) $(OutputSwitch)$(OutputFile) @$(ObjectsFileList) $(LibPath) $(Libs) $(LinkOptions)

MakeIntermediateDirs:
@$(MakeDirCommand) «./Debug»

$(IntermediateDirectory)/.d:
@$(MakeDirCommand) «./Debug»

##
## Objects
##
$(IntermediateDirectory)/main.cpp$(ObjectSuffix): main.cpp $(IntermediateDirectory)/main.cpp$(DependSuffix)
$(CXX) $(IncludePCH) $(SourceSwitch) «C:/Users/James/code/codelite_test1/test1/main.cpp» $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/main.cpp$(ObjectSuffix) $(IncludePath)
$(IntermediateDirectory)/main.cpp$(DependSuffix): main.cpp
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/main.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/main.cpp$(DependSuffix) -MM main.cpp

$(IntermediateDirectory)/main.cpp$(PreprocessSuffix): main.cpp
$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/main.cpp$(PreprocessSuffix) main.cpp

-include $(IntermediateDirectory)/*$(DependSuffix)
##
## Clean
##
clean:
$(RM) -r ./Debug/

Источник

Fatal error opening dependency file dep no such file or directory

Создаю файл вручную — пишет то же самое о других файлах и так далее. На 8.1 работало без проблем. Что это может означать?

Добавлено after 32 minutes 16 seconds:
Уже нашёл на зарубежных форумах — надо кинуть в папку utils/bin вот эту библиотеку (распаковать из архива) с заменой.

Вложения:
msys-1.0.zip [378.91 KiB]
Скачиваний: 960

_________________
Иногда мой питомец уходит в такую спячку, что разбудить его можно только щелчком по первой ноге.

I am trying to adapt a makefile (that I found here) that automatically generates dependencies. However, when I run make I get the following error message:

t@t-XPS-13-9365:~/pf/test$ make
g++ -MT .o/test_resamplers.o -MD -MP -MF .d/test_resamplers.Td -std=c++11 -g -Wall -Wextra -pedantic -I/usr/local/include/UnitTest++ -I/usr/include/eigen3 -I../include -c -o .o/test_resamplers.o test_resamplers.cpp
test_resamplers.cpp:155:1: fatal error: opening dependency file .d/test_resamplers.Td: No such file or directory
 }
 ^
compilation terminated.
Makefile:66: recipe for target '.o/test_resamplers.o' failed
make: *** [.o/test_resamplers.o] Error 1

Perhaps I am using the wrong DEPFLAGS variable in my makefile. I did switch the compiler from clang++ in the example to g++. Here’s my makefile:

# output binary
BIN := run_tests

# source files
SRCS := 
    main.cpp test_cf_filters.cpp test_resamplers.cpp test_rv_eval.cpp 
    test_rv_samp.cpp test_utils.cpp

# intermediate directory for generated object files
OBJDIR := .o
# intermediate directory for generated dependency files
DEPDIR := .d

# object files, auto generated from source files
OBJS := $(patsubst %,$(OBJDIR)/%.o,$(basename $(SRCS)))

# compilers (at least gcc and clang) don't create the subdirectories automatically
$(shell mkdir -p $(dir $(OBJS)) >/dev/null)

# C++ compiler
CXX := g++
# linker
LD := g++

# C++ flags
CXXFLAGS := -std=c++11
# C/C++ flags
CPPFLAGS := -g -Wall -Wextra -pedantic -I/usr/local/include/UnitTest++ -I/usr/include/eigen3 -I../include
# linker flags
LDFLAGS := "-L../bin" "-L/usr/local/lib"
# flags required for dependency generation; passed to compilers
DEPFLAGS = -MT $@ -MD -MP -MF $(DEPDIR)/$*.Td
# libraries
LDLIBS := -lpf -lUnitTest++

# compile C++ source files
COMPILE.cc = $(CXX) $(DEPFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c -o $@
# link object files to binary
LINK.o = $(LD) $(LDFLAGS) $(LDLIBS) -o $@
# precompile step
PRECOMPILE =
# postcompile step
POSTCOMPILE = mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d

all: $(BIN)

.PHONY: clean
clean:
    $(RM) -r $(OBJDIR) $(DEPDIR)

.PHONY: help
help:
    @echo available targets: all dist clean distclean install uninstall check

$(BIN): $(OBJS)
    $(LINK.o) $^

$(OBJDIR)/%.o: %.c
$(OBJDIR)/%.o: %.c $(DEPDIR)/%.d
    $(PRECOMPILE)
    $(COMPILE.c) $<
    $(POSTCOMPILE)

$(OBJDIR)/%.o: %.cpp
$(OBJDIR)/%.o: %.cpp $(DEPDIR)/%.d
    $(PRECOMPILE)
    $(COMPILE.cc) $<
    $(POSTCOMPILE)

$(OBJDIR)/%.o: %.cc
$(OBJDIR)/%.o: %.cc $(DEPDIR)/%.d
    $(PRECOMPILE)
    $(COMPILE.cc) $<
    $(POSTCOMPILE)

$(OBJDIR)/%.o: %.cxx
$(OBJDIR)/%.o: %.cxx $(DEPDIR)/%.d
    $(PRECOMPILE)
    $(COMPILE.cc) $<
    $(POSTCOMPILE)

.PRECIOUS = $(DEPDIR)/%.d
$(DEPDIR)/%.d: ;

-include $(DEPS)

asked Sep 5, 2018 at 19:21

Taylor's user avatar

You create the object directory with this line:

$(shell mkdir -p $(dir $(OBJS)) >/dev/null)

but you don’t create the DEPDIR anywhere, so when the compiler tries to create a file there it fails.

You could add this line to make the dependency directory:

$(shell mkdir -p $(DEPDIR))

Or, add it into the previous shell function.

answered Sep 5, 2018 at 19:36

MadScientist's user avatar

MadScientistMadScientist

89.1k9 gold badges105 silver badges130 bronze badges

Nowadays Arduino is the platform of choice for programming AVR
microcontrollers and for good reasons. But there are times when you want to
have full control over what is added to your code. 

For example Arduino is enabling by default Timer0 for use in millis function
and other functions and includes some interrupt routines that perhaps your
project is not using and so adding to the code size or perhaps those
interrupts can interfere with your code.Two main alternatives are WinAVR and Atmel Studio. This tutorial covers WinAVR because it’s simpler to use for a beginner.

What you will need:

  • ATmega328P (used in this tutorial as an example)
  • USBTinyISP programmer 
  • WinAVR software (more on this later)

What you can learn:

  • how to program an AVR microcontroller using an In-System Programmer such as
    USBTinyISP and WinAVR
  • some bitwise operations for handling the registers

There are two main ways to program a microcontroller:

— ISP (In System Programming) using SPI protocol and a ISP programmer

— With a bootloader using UART protocol and a USB to Serial programmer. Some microcontrollers come with a bootloader already pre-programmed on them.

This tutorial will cover the ISP programming way.

Programming software

There are many tools for programming an AVR microcontroller such as Atmel
Studio, PlatformIO, Eclipse with an AVR plugin, etc but the simplest and
light weight solution that I found is using WinAVR.

Programming hardware

Apart from development software there is also the need of a hardware
programmer that the software uses to communicate with the microcontroller
and upload the code to it. Searching online for ‘avr programmer
reveals lots of options. The most popular I believe is the
USBTinyISP and is very cheap. There is also Atmel-ICE from Atmel. A
bit more expensive but it has the benefit of being able to debug and see in
real time what happens inside the microcontroller.

WinAVR and USBTinyISP - Getting started with AVR

WinAVR is a free suite of executable open source software development tools
for the Atmel AVR series for Windows. WinAVR contains all the tools for
developing on the AVR such as avr-gcc compiler, avrdude for
uploading the code

and avr-gdb for debugging.

To download WinAVR visit the project homepage at
http://winavr.sourceforge.net and in the download section you will find the link
https://sourceforge.net/projects/winavr/files
and on that page click on download the latest version. Some users reported that the installation affected their system PATH. All I can say is that I have installed WinAVR on Windows 10 many times and didn’t encounter any problem with it.

Updating WinAVR to the latest AVR-GCC and AVRDude

Scrolling down you should find a link called ‘AVR 8-bit Toolchain v3.62 – Windows‘ which is a zip file. Now in that zip file there should be a folder containing other folders such as ‘avr, bin, doc, lib, etc…’ Select all these folders and drag them where WinAVR is installed and replace the existing ones. By default WinAVR is installed on C:WinAVR-20100110.

Now for AVRDude follow this link http://download.savannah.gnu.org/releases/avrdude and download ‘avrdude-6.3-mingw32.zip‘ or newer version then extract the two files from the AVRDude zip file to C:WinAVR-20100110bin.

After installation search on windows start for WinAVR and you should see
Programmer’s Notepad app.

Programmers Notepad

Programmer’s Notepad does everything for you. Is calling the make utility,
which executes your makefile, which in turn calls the compiler, linker, and
other utilities used to build your software. You just need to write the code
and click Make then Program. 

Starting first WinAVR project

Inside Programmer’s Notepad click File -> New ->
Project. Choose a name for the project then navigate to a folder
where you want to put the project files. I named mine Blink LED.

Programmer's Notepad make project folder

Now you should see the project in the left side panel. Here you can also
make/rename a project group.

Programmers Notepad adding project files

Now to add a file first add some code and save the file as main.c in
the folder where you saved the project file. The name must be
main and the extension can be .c for C or .cpp for C++ languages.
Bellow is a code template that I made for my future projects.




/*************************************************************
	INCLUDES
**************************************************************/
#include <avr io.h>
#include <util delay.h>
#include <avr interrupt.h>


/*************************************************************
	DEFINES
**************************************************************/



/*************************************************************
	GLOBAL VARIABLES
**************************************************************/



/*************************************************************
	FUNCTION PROTOTYPES
**************************************************************/
 
 
 
/*************************************************************
	MAIN FUNCTION
**************************************************************/
int main(void){
	
	
	while(1){
	

		}
	}
}

/*************************************************************
	FUNCTIONS
**************************************************************/



/*************************************************************
	ISR Handlers
**************************************************************/

By right clicking on the project name use Add Files to add the main.c file
to the project.

To display the line numbers go to View -> Line Numbers.

Make file 

Now it is time to setup the make file. This file tells WinAVR what
microcontroller do we use, what CPU frequency, what programmer, on
what port, etc. For this, search like before for WinAVR but this time open
MFile [WinAVR]. Then select Makefile -> MCU type ->
ATmega -> atmega328p

make file select mcu type

From Port select usb. Then on the bottom click
Enable Editing of Makefile. Now from Programmer choose your
programmer. If you use USBTinyISP and it doesn’t appear in the list simply
pick a random one and then change it with usbtiny.

The last setting is the CPU frequency. Scroll up in the file until you see
F_CPU and put your CPU frequency. For ATmega328 use 8000000 which
means 8MHz — 8 with 6 zeros or 16000000 if you have a 16MHz crystal.

 

Makefile F_CPU frequency

Finally save the file as Makefile (without any extension) inside the
project folder. Later it can be open and edited using Programmers
Notepad.

The following section talks about configuring a port, bitwise and binary operations. If you are already familiar with this, skip to this section uploading the code to the microcontroller.

Learning AVR programming by blinking a LED using ATmega328P

On page 12 you can find the pinout. Say you want to connect the LED to pin
28 of the 28 PDIP package. Near the pin number 28, PC5 indicates that this
pin belongs to port C and has the port pin number 5. By looking at the other
pins we notice that there are 3 ports: B, C and D each one having 8 pins (0
to 7) except port C that has only from 0 to 6. Inside the parenthesis are shown what other functions the pin can have, like ADC for example (Analog to
Digital Converter).

To setup the pins we use the defines


#define LED_DDR			DDRC
#define LED_PORT		PORTC
#define LED_PIN			PC5

After #define any name can be used. Then press TAB a few times to
make the lines look nice and readable and then write the values.

DDRx stands for Data Direction Register and selects the direction of
the pin — input or output. You want it to be an output when driving an LED
or transistor and an input when reading a button press. The x after DDR is
the port and in our case is C.

*A register in an 8 bit microcontroller like this one is just a set of 8
bits that holds a number and the microcontroller uses the bit values to
configures itself.

Configuring ATmega328 port pins — this can replace Arduino digitalWrite to increase the speed

Configuring a pin as a digital output

DDRC |= 1 << PC5

Let’s analyze the above line. Somewhere in the avr_io.h included file, PC5
is associated with the value 5 and so PC5 will be replaced with 5. So is the
case with the defines. When we write 

LED_DDR |= 1 << LED_PIN 

the pre-processor will replace LED_DDR with DDRC and LED_PIN with PC5.

<< is called the left shift and makes part of the bitwise
operations. 1 << 5 is saying move the binary representation of 1, 5
times to the left.

In binary 1 is 0b00000001 and after it has been shifted 5 times to the left
is 0b00100000

We can also write it like this:

The 8 bits represents our DDRC register
and each bit is the pin. 

Pin 0 is 0b00000001

Pin 1 is 0b00000010

Pin 2 is 0b00000100

Pin 3 is 0b00001000

Pin 4 is 0b00010000

Pin 5 is 0b00100000

Pin 6 is 0b01000000

Pin 7 is 0b10000000

By putting 1 on that bit position we set the DDR (direction) of the pin to
be an output. Leaving it or setting it to 0 will make it as an input.

So what is with the | symbol? It is called a bitwise or operator.

0b00100000 | 0b00000010 = 0b00100010

because as the name suggests 

0 or 1 = 1

1 or 1 = 1

0 or 0 = 0

In a bitwise operation two bytes are compared against each other bit by bit.
Notice the colors: red (bit 0) is compared to the other red, blue (bit 1),
green (bit 2) and so on.

The purpose of the or | operator is to change our desired pin but leave the
others the same as before.

If we have some other pin controlling a motor for example PC1 and we change
pin 5 (PC5)

DDRC before is 0b00000010 — PC1 is 1 (output)

DDRC |= 1 << PC5

DDRC after is 0b00100010

Notice that the use of the or operator, left the PC1 bit unchanged.

To practice or to solve bitwise operations there is this nice website
http://bitwisecmd.com/

The browser’s search bar can also be used without pressing enter.

Setting a digital output pin HIGH

After setting the pin as an output, let’s make it HIGH to drive the LED.

PORTC |= 1 << PC5

This leaves the other pins unchanged. To make only this pin high and the
rest low (0) we could write:

PORTC = 1 << PC5

Setting a digital output pin LOW

PORTC &= ~(1 << PC5)

Now the pin is connected to ground.

Configuring a pin as a digital input

As before but instead of 1 we write 0 to the specific pin

DDRC &=  ~(1 << PC5)

~ is the not operator so 0b00100000 becomes 0b11011111

DDRC before is 0b00100000

DDRC &= 0b11011111 (after not operation)

DDRC after is 0b00000000

because with & bitwise operator both values must be 1

1 and 1 is 1

1 and 0 is 0

0 and 1 is 0

When a pin is set as an input and we write this

PORTC |= 1 << PC5

then the internal pull-up resistor is activated. Now we could add a push
button between the pin and ground and when the button is pressed the pin
will be pulled to ground and when the button is not pressed the pin will be
high due to the pull-up resistor. This is how we can read if a button is
pressed.

if(PINC & (1 << PIN5))

PINC represents all the pins of port C and by some bitwise operations we
check only if pin 5 in 1 or 0.

Toggling a pin

DDRC ^= 1 << PC5

If the pin is low (0) will be made high (1) and vice versa.

In summary to set a bit in a register to 1 use

DDRC |= 1 << PC5

and to set a bit to 0 use

DDRC &= ~(1 << PC5)

Another way is to use the _BV() macro function that means bit value.
So the lines above can be replaced by

DDRC |= _BV(PC5)

DDRC &= ~_BV(PC5)

Now finally let’s blink that LED with the following code:

int main(void){
	// Set the pin as output
	LED_DDR |= 1<<LED_PIN;
	
	// Set the pin HIGH
	LED_PORT |= 1<<LED_PIN;
	
	while(1){
		// Toggle the pin
		LED_PORT ^= 1 << LED_PIN;
		
		// Wait 500 milliseconds
		_delay_ms(500);
	}
}

To compile the code click Tools -> Make All. 

If the WinAVR wasn’t updated using the toolchain from Atmel then the following error message should appear:

‘fatal error: opening dependency file .dep/main.o.d: no such file or
directory’

To fix it visit this forum https://www.avrfreaks.net/forum/windows-81-compilation-error?page=all
and you can find a link to a .dll file. Copy this file in the WinAVR
installation folder -> utils -> bin and replace the existing file. Now
it should compile without errors.

To upload the code to the microcontroller click Tools ->
Program. But first lets see how to connect the microcontroller to the
programmer.

Connecting USBTinyISP to ATmega328P AVR

USBTinyISP header pinout

USBTinyISP has 2 headers and each one can be used but I prefer the small one.
In my case the pin headers are mirrored so you should check with a multimeter
first with the power of. 

The corresponding pins on the microcontroller can be found in the datasheet.

MOSI — master out, slave in

MISO — master in, slave out

SCK — system clock

RST — reset

This protocol of communication is called SPI (Serial Peripheral Interface)
.

A 10k resistor is needed from VCC to the reset pin of the microcontroller to
keep it high. If the reset pin is pulled to ground then the microcontroller
will be kept in reset  mode.

On the USBTinyISP there is a yellow jumper. If removed the programmer will not
provide 5V power to the microcontroller (MCU) and you need to provide power
from other source but be sure to have a common ground. This is useful when you
want to power the micro with 3.3V for example.

Installing drivers for USBTinyISP

The drivers for USBTinyISP can be found on Adafruit website here https://learn.adafruit.com/usbtinyisp/drivers. The install includes drivers for some other programmers. Check the box that has USBtinyISP at the end.

USBTinyISP driver instal

Now if everything is connected properly you should be able to program the
micro using Tools — > Program.

Having a LED blink using the delay function is useful for checking if the
F_CPU is set correctly. If not the LED will blink either to slow or too fast.
ATmega328 comes from the factory with their cpu clock  divided by 8. In
the datasheet you will see the term prescaler. The CPU clock can be divided
with a prescaler of 1 (no prescaler), divided by 8, 16… The micro has an
internal RC oscillator at 8MHz and has a fuse set to divide this by 8 so the
actual speed is 1MHz. You could either change the speed in the makefile to
1000000 or change the fuse and set the CPU divider to 1 and keep the 8MHz
specified in the makefile.

There is also the option of connecting a 16MHz crystal oscillator to the
microcontroller and get a more precise clock. For most applications the
internal RC oscillator is just fine but don’t build a clock with that.

AVR Fuses

There are 3 bytes stored in a special area of flash memory called fuse bits.
These are Low, High and Extended fuse bytes. Setting some of this bits wrong
can make the micro unusable and will be needed a special high voltage
programmer to make it work again. For this reason there are fuse calculators
and as long as you are careful what options you select it will be fine.

Here is a good online tool for fuse calculation
https://www.engbedded.com/fusecalc Be sure to select the exact part. Default fuse values for ATmega328P look like
this

ATmega328P default fuse values fuse calculator

Clock Selection

With the first selection menu the source and type for the CPU clock can be
selected. The Clock Startup can be either of the following: 14CK + 0 ms, 14CK
+ 4 ms, 14CK + 65 ms. 

The Startup Time is just how long it take for the clock source to stabilize
from when power is first applied. Always go with the longest setting 14CK +
65ms unless you know for a fact your clock source needs less time and 65ms is
too long to wait. 

Clock Output

Checking Clock output on PORTB0 will output a square wave with the clock
frequency at pin PB0 and is useful when you want to debug the clock rate or to
drive other chips. 

Clock Divide

This divides the clock by 8 and it’s the default factory value. You may want
to uncheck this to get the full speed. Although on battery powered devices
the slower the clock the less power is consumed. 

Reset Disable 

Warning. This fuse turns the reset pin into a normal pin and after doing
this the chip cannot be programmed anymore. 

Brown-out Detect (BOD)

When the voltage will drop beneath the specified BOD voltage the micro
will turn off until the voltage returns to normal. This must be tuned on
if the EEPROM memory is used to prevent write errors. The chip has a
lower voltage limit at which it can work reliably and beneath that
voltage the chip can behave erratically, erasing or overwriting the RAM
and EEPROM. 

Preserve EEPROM

If this is checked the EEPROM will not be erased during programming.
Here usually settings are kept so is a good idea to check this to
preserve the settings

To calculate the fuses click Apply feature settings. I don’t
recommend using the Manual fuse bits configuration unless you
know what you are doing. 

Burning the fuses 

To program the fuses open a command prompt window and paste

avrdude -c usbtiny -p atmega328p -U lfuse:w:<0xHH>:m
avrdude -c usbtiny -p atmega328p -U hfuse:w:<0xHH>:m
avrdude -c usbtiny -p atmega328p -U efuse:w:<0xHH>:m

Replace 0xHH with the values from the fuse calculator.

Further reading

  • Atmel AVR4027: Tips and Tricks to Optimize Your C Code for 8-bit AVR Microcontrollers

I pasted the entire error message in my original post

Here is the mk file

##
## Auto Generated makefile by CodeLite IDE
## any manual changes will be erased
##
## Debug
ProjectName :=test1
ConfigurationName :=Debug
WorkspacePath :=C:/Users/James/code/codelite_test1
ProjectPath :=C:/Users/James/code/codelite_test1/test1
IntermediateDirectory :=./Debug
OutDir := $(IntermediateDirectory)
CurrentFileName :=
CurrentFilePath :=
CurrentFileFullPath :=
User :=James
Date :=18/10/2017
CodeLitePath :=»C:/Program Files/CodeLite»
LinkerName :=C:/TDM-GCC-64/bin/g++.exe
SharedObjectLinkerName :=C:/TDM-GCC-64/bin/g++.exe -shared -fPIC
ObjectSuffix :=.o
DependSuffix :=.o.d
PreprocessSuffix :=.i
DebugSwitch :=-g
IncludeSwitch :=-I
LibrarySwitch :=-l
OutputSwitch :=-o
LibraryPathSwitch :=-L
PreprocessorSwitch :=-D
SourceSwitch :=-c
OutputFile :=$(IntermediateDirectory)/$(ProjectName)
Preprocessors :=
ObjectSwitch :=-o
ArchiveOutputSwitch :=
PreprocessOnlySwitch :=-E
ObjectsFileList :=»test1.txt»
PCHCompileFlags :=
MakeDirCommand :=makedir
RcCmpOptions :=
RcCompilerName :=C:/TDM-GCC-64/bin/windres.exe
LinkOptions :=
IncludePath := $(IncludeSwitch). $(IncludeSwitch).
IncludePCH :=
RcIncludePath :=
Libs :=
ArLibs :=
LibPath := $(LibraryPathSwitch).

##
## Common variables
## AR, CXX, CC, AS, CXXFLAGS and CFLAGS can be overriden using an environment variables
##
AR := C:/TDM-GCC-64/bin/ar.exe rcu
CXX := C:/TDM-GCC-64/bin/g++.exe
CC := C:/TDM-GCC-64/bin/gcc.exe
CXXFLAGS := -g -O0 -Wall $(Preprocessors)
CFLAGS := -g -O0 -Wall $(Preprocessors)
ASFLAGS :=
AS := C:/TDM-GCC-64/bin/as.exe

##
## User defined environment variables
##
CodeLiteDir:=C:Program FilesCodeLite
Objects0=$(IntermediateDirectory)/main.cpp$(ObjectSuffix)

Objects=$(Objects0)

##
## Main Build Targets
##
.PHONY: all clean PreBuild PrePreBuild PostBuild MakeIntermediateDirs
all: $(OutputFile)

$(OutputFile): $(IntermediateDirectory)/.d $(Objects)
@$(MakeDirCommand) $(@D)
@echo «» > $(IntermediateDirectory)/.d
@echo $(Objects0) > $(ObjectsFileList)
$(LinkerName) $(OutputSwitch)$(OutputFile) @$(ObjectsFileList) $(LibPath) $(Libs) $(LinkOptions)

MakeIntermediateDirs:
@$(MakeDirCommand) «./Debug»

$(IntermediateDirectory)/.d:
@$(MakeDirCommand) «./Debug»

PreBuild:

##
## Objects
##
$(IntermediateDirectory)/main.cpp$(ObjectSuffix): main.cpp $(IntermediateDirectory)/main.cpp$(DependSuffix)
$(CXX) $(IncludePCH) $(SourceSwitch) «C:/Users/James/code/codelite_test1/test1/main.cpp» $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/main.cpp$(ObjectSuffix) $(IncludePath)
$(IntermediateDirectory)/main.cpp$(DependSuffix): main.cpp
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/main.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/main.cpp$(DependSuffix) -MM main.cpp

$(IntermediateDirectory)/main.cpp$(PreprocessSuffix): main.cpp
$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/main.cpp$(PreprocessSuffix) main.cpp

-include $(IntermediateDirectory)/*$(DependSuffix)
##
## Clean
##
clean:
$(RM) -r ./Debug/

Понравилась статья? Поделить с друзьями:

Читайте также:

  • Fatal error onewire h no such file or directory
  • Fatal error one or more table pointers are invalid modification could be unsafe
  • Fatal error u1073
  • Fatal error on startup matlab
  • Fatal error on ssl transport asyncio

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии