Pre-Processor Problems Recompiling OptiBoot V62 [SOLVED]

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

Greetings -

 

I have a need to recompile optiboot because of the need to trigger the bootload entry with a switch closure on reset. I had some problems with my modified version (too big, among other things) so went back to the original (on GitHub) to see what happens with compiling the original. 

 

Early in the macro definitions, there is testing for valid baud rate. It looks like this:

/* set the UART baud rate defaults */
#ifndef BAUD_RATE
#if F_CPU >= 8000000L
#define BAUD_RATE   115200L // Highest rate Avrdude win32 will support
#elsif F_CPU >= 1000000L
#define BAUD_RATE   9600L   // 19200 also supported, but with significant error
#elsif F_CPU >= 128000L
#define BAUD_RATE   4800L   // Good for 128kHz internal RC
#else
#define BAUD_RATE 1200L     // Good even at 32768Hz
#endif
#endif

#ifndef UART
#define UART 0
#endif

#define BAUD_SETTING (( (F_CPU + BAUD_RATE * 4L) / ((BAUD_RATE * 8L))) - 1 )
#define BAUD_ACTUAL (F_CPU/(8 * ((BAUD_SETTING)+1)))
#define BAUD_ERROR (( 100*(BAUD_RATE - BAUD_ACTUAL) ) / BAUD_RATE)

#if BAUD_ERROR >= 5
#error BAUD_RATE error greater than 5%
#elif BAUD_ERROR <= -5
#error BAUD_RATE error greater than -5%
#elif BAUD_ERROR >= 2
#warning BAUD_RATE error greater than 2%
#elif BAUD_ERROR <= -2
#warning BAUD_RATE error greater than -2%
#endif

#if (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 > 250
#error Unachievable baud rate (too slow) BAUD_RATE 
#endif // baud rate slow check
#if (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 < 3
#if BAUD_ERROR != 0 // permit high bitrates (ie 1Mbps@16MHz) if error is zero
#error Unachievable baud rate (too fast) BAUD_RATE 
#endif
#endif // baud rate fastn check

 

With F_CPU defined as (up at the very top of the defines)

#define F_CPU 8000000L

I get constant warnings that "BAUD_RATE error greater than 5%" and "unachievable baud rate (too fast) BAUD_RATE".

 

I comment out all the baud rate setting stuff and replace with a simple 

 

#define BAUD_RATE 9600L

Same error persists. Then I try something that SEEMS like it ought to work.

 

int64_t MyBaud = BAUD_RATE;
int64_t MyFCPU = F_CPU;

Then I debug rather than just build and break down in the program. The watch window shows me

 

    MyBaud        86857072090846220

    MyFCPU        86857072090846220

 

Something really strange is going on here! Can anyone help with some insight?

 

Thanks

Jim

This topic has a solution.

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

Last Edited: Fri. Jul 24, 2015 - 07:04 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What are you using for your compile command?  (and which version of the compiler.)

The makefile usually provides the definitions for F_CPU and BAUD_RATE, so it's quite possible that the "!defined(...)" chains are (at best) poorly tested.

(in particular:  "#elsif" ??  Wow! (that's from before my time, but it's still pretty embarrassing not to have noticed!))

 

(Are you seeing an error about that earlier in the compiler output?  I can eventually get a "unachievable baud rate" message like this:

avr-gcc -g -Wall -Os -fno-split-wide-types -mrelax -mmcu=atmega328p -DF_CPU=16000000  -DLED_START_FLASHES=3   -c -o optiboot.o optiboot.c
optiboot.c:276:2: error: invalid preprocessing directive #elsif
 #elsif F_CPU >= 1000000L
  ^
optiboot.c:277:0: warning: "BAUD_RATE" redefined [enabled by default]
 #define BAUD_RATE   9600L   // 19200 also supported, but with significant error
 ^
optiboot.c:275:0: note: this is the location of the previous definition
 #define BAUD_RATE   115200L // Highest rate Avrdude win32 will support
 ^
optiboot.c:278:2: error: invalid preprocessing directive #elsif
 #elsif F_CPU >= 128000L
  ^
optiboot.c:279:0: warning: "BAUD_RATE" redefined [enabled by default]
 #define BAUD_RATE   4800L   // Good for 128kHz internal RC
 ^
optiboot.c:277:0: note: this is the location of the previous definition
 #define BAUD_RATE   9600L   // 19200 also supported, but with significant error
 ^
optiboot.c:304:2: error: #error Unachievable baud rate (too slow) BAUD_RATE
 #error Unachievable baud rate (too slow) BAUD_RATE 
  ^

 

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

Using the toolchain that is part of AS6.2 with the built-in makefile. The code is verbatim from the V6.2 GitHub repository. Only change was to add a definition for F_CPU (at first). Then, I commented out the chain of stuff setting baud rate and supplied a fixed definition for BAUD_RATE 9600L. Then I added those two diagnostic variables to try to see what BAUD_RATE and F_CPU were in the body of the program. Thats it. Nothing else changed.

 

I know that it won't have the correct starting addrress. I was more concerned about size at this point.

 

Many thanks

Jim

 

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

Jim,

 

That didn't really answer the question. Can you copy verbatim the "Build output" where it invokes avr-gcc to do the compilation? (to see what -D's might be passed).

Last Edited: Mon. Jul 20, 2015 - 10:55 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK, sorry for the delay. Had some minor surgery on Friday and still not up to the usual.

 

Here is the top part of the program, from the first #include through the baud rate tests:

 

#define F_CPU 8000000UL

#define OPTIBOOT_MAJVER 6
#define OPTIBOOT_MINVER 2

/*
 * OPTIBOOT_CUSTOMVER should be defined (by the makefile) for custom edits
 * of optiboot.  That way you don't wind up with very different code that
 * matches the version number of a "released" optiboot.
 */

#if !defined(OPTIBOOT_CUSTOMVER)
#define OPTIBOOT_CUSTOMVER 0
#endif

unsigned const int __attribute__((section(".version"))) 
optiboot_version = 256*(OPTIBOOT_MAJVER + OPTIBOOT_CUSTOMVER) + OPTIBOOT_MINVER;


#include <inttypes.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/eeprom.h>

/*
 * Note that we use our own version of "boot.h"
 * <avr/boot.h> uses sts instructions, but this version uses out instructions
 * This saves cycles and program memory.  Sorry for the name overlap.
 */
#include "boot.h"


// We don't use <avr/wdt.h> as those routines have interrupt overhead we don't need.

/*
 * pin_defs.h
 * This contains most of the rather ugly defines that implement our
 * ability to use UART=n and LED=D3, and some avr family bit name differences.
 */
#include "pin_defs.h"

/*
 * stk500.h contains the constant definitions for the stk500v1 comm protocol
 */
#include "stk500.h"

#ifndef LED_START_FLASHES
#define LED_START_FLASHES 0
#endif

/* set the UART baud rate defaults */

#ifndef BAUD_RATE
#if F_CPU >= 8000000L
#define BAUD_RATE   115200L // Highest rate Avrdude win32 will support
#elif F_CPU >= 1000000L
#define BAUD_RATE   9600L   // 19200 also supported, but with significant error
#elif F_CPU >= 128000L
#define BAUD_RATE   4800L   // Good for 128kHz internal RC
#else
#define BAUD_RATE 1200L     // Good even at 32768Hz
#endif
#endif


#ifndef UART
#define UART 0
#endif

#define BAUD_SETTING (( (F_CPU + BAUD_RATE * 4L) / ((BAUD_RATE * 8L))) - 1 )
#define BAUD_ACTUAL (F_CPU/(8 * ((BAUD_SETTING)+1)))
#define BAUD_ERROR (( 100*(BAUD_RATE - BAUD_ACTUAL) ) / BAUD_RATE)

#if BAUD_ERROR >= 5
#error BAUD_RATE error greater than 5%
#elif (BAUD_ERROR + 5) <= 0
#error BAUD_RATE error greater than -5%
#elif BAUD_ERROR >= 2
#warning BAUD_RATE error greater than 2%
#elif (BAUD_ERROR + 2) <= 0
#warning BAUD_RATE error greater than -2%
#endif

#if (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 > 250
#error Unachievable baud rate (too slow) BAUD_RATE 
#endif // baud rate slow check
#if (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 < 3
#if BAUD_ERROR != 0 // permit high bitrates (ie 1Mbps@16MHz) if error is zero
#error Unachievable baud rate (too fast) BAUD_RATE 
#endif
#endif // baud rate fastn check

 

And, here is the build output:


------ Build started: Project: optiboot, Configuration: Debug AVR ------
Build started.
Project "optiboot.cproj" (default targets):
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreBuild" in file "C:\Program Files (x86)\Atmel\Atmel Studio 6.2\Vs\Compiler.targets" from project "C:\Users\Jim\Dropbox\Accelerometer Docs\Code\optiboot\optiboot\optiboot\optiboot.cproj" (target "Build" depends on it):
	Using "RunCompilerTask" task from assembly "C:\Program Files (x86)\Atmel\Atmel Studio 6.2\Extensions\Application\AvrGCC.dll".
	Task "RunCompilerTask"
		Shell Utils Path C:\Program Files (x86)\Atmel\Atmel Studio 6.2\shellUtils
		C:\Program Files (x86)\Atmel\Atmel Studio 6.2\shellUtils\make.exe all 
		Building file: .././optiboot.c
		Invoking: AVR/GNU C Compiler : 4.8.1
		"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1056\avr8-gnu-toolchain\bin\avr-gcc.exe"  -x c -funsigned-char -funsigned-bitfields -DDEBUG  -O1 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=atmega328p -c -std=gnu99 -MD -MP -MF "optiboot.d" -MT"optiboot.d" -MT"optiboot.o"   -o "optiboot.o" ".././optiboot.c" 
C:\Users\Jim\Dropbox\Accelerometer Docs\Code\optiboot\optiboot\optiboot\optiboot.c(280,2): error: invalid preprocessing directive #elsif
		 #elsif F_CPU >= 1000000L
		  ^
C:\Users\Jim\Dropbox\Accelerometer Docs\Code\optiboot\optiboot\optiboot\optiboot.c(281,0): warning: "BAUD_RATE" redefined [enabled by default]
		 #define BAUD_RATE   9600L   // 19200 also supported, but with significant error
		 ^
C:\Users\Jim\Dropbox\Accelerometer Docs\Code\optiboot\optiboot\optiboot\optiboot.c(279,0): info: this is the location of the previous definition
		 #define BAUD_RATE   115200L // Highest rate Avrdude win32 will support
		 ^
C:\Users\Jim\Dropbox\Accelerometer Docs\Code\optiboot\optiboot\optiboot\optiboot.c(282,2): error: invalid preprocessing directive #elsif
		 #elsif F_CPU >= 128000L
		  ^
C:\Users\Jim\Dropbox\Accelerometer Docs\Code\optiboot\optiboot\optiboot\optiboot.c(283,0): warning: "BAUD_RATE" redefined [enabled by default]
		 #define BAUD_RATE   4800L   // Good for 128kHz internal RC
		 ^
C:\Users\Jim\Dropbox\Accelerometer Docs\Code\optiboot\optiboot\optiboot\optiboot.c(281,0): info: this is the location of the previous definition
		 #define BAUD_RATE   9600L   // 19200 also supported, but with significant error
		 ^
C:\Users\Jim\Dropbox\Accelerometer Docs\Code\optiboot\optiboot\optiboot\optiboot.c(299,2): error: #error BAUD_RATE error greater than 5%
		 #error BAUD_RATE error greater than 5%
		  ^
C:\Users\Jim\Dropbox\Accelerometer Docs\Code\optiboot\optiboot\optiboot\optiboot.c(361,20): warning: 'flash_led' declared 'static' but never defined [-Wunused-function]
		 static inline void flash_led(uint8_t);
		                    ^
		make: *** [optiboot.o] Error 1
	Done executing task "RunCompilerTask" -- FAILED.
Done building target "CoreBuild" in project "optiboot.cproj" -- FAILED.
Done building project "optiboot.cproj" -- FAILED.

Build FAILED.
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========
Thanks for taking a look...

Different set of errors than last time. I see some #elsif in there, which I did not place there! I will try fixing those, but they are in the GitHub source code!

 

Thanks for taking a look...

 

Jim

 

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

Last Edited: Mon. Jul 20, 2015 - 09:14 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am confused. Those #elsif statements are NOT in the code above. When I went back to the other machine where I was compiling, there were none there, either. I built again, and here is the second output

 

------ Build started: Project: optiboot, Configuration: Debug AVR ------
Build started.
Project "optiboot.cproj" (default targets):
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreBuild" in file "C:\Program Files (x86)\Atmel\Atmel Studio 6.2\Vs\Compiler.targets" from project "C:\Users\Jim\Dropbox\Accelerometer Docs\Code\optiboot\optiboot\optiboot\optiboot.cproj" (target "Build" depends on it):
	Using "RunCompilerTask" task from assembly "C:\Program Files (x86)\Atmel\Atmel Studio 6.2\Extensions\Application\AvrGCC.dll".
	Task "RunCompilerTask"
		Shell Utils Path C:\Program Files (x86)\Atmel\Atmel Studio 6.2\shellUtils
		C:\Program Files (x86)\Atmel\Atmel Studio 6.2\shellUtils\make.exe all 
		Building file: .././optiboot.c
		Invoking: AVR/GNU C Compiler : 4.8.1
		"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1056\avr8-gnu-toolchain\bin\avr-gcc.exe"  -x c -funsigned-char -funsigned-bitfields -DDEBUG  -O1 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=atmega328p -c -std=gnu99 -MD -MP -MF "optiboot.d" -MT"optiboot.d" -MT"optiboot.o"   -o "optiboot.o" ".././optiboot.c" 
C:\Users\Jim\Dropbox\Accelerometer Docs\Code\optiboot\optiboot\optiboot\optiboot.c(303,2): warning: #warning BAUD_RATE error greater than 2% [-Wcpp]
		 #warning BAUD_RATE error greater than 2%
		  ^
C:\Users\Jim\Dropbox\Accelerometer Docs\Code\optiboot\optiboot\optiboot\optiboot.c(361,20): warning: 'flash_led' declared 'static' but never defined [-Wunused-function]
		 static inline void flash_led(uint8_t);
		                    ^
		Finished building: .././optiboot.c
		Building target: optiboot.elf
		Invoking: AVR/GNU Linker : 4.8.1
		"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1056\avr8-gnu-toolchain\bin\avr-gcc.exe" -o optiboot.elf  optiboot.o   -Wl,-Map="optiboot.map" -Wl,--start-group -Wl,-lm  -Wl,--end-group -Wl,--gc-sections -mmcu=atmega328p  
		Finished building target: optiboot.elf
		"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1056\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O ihex -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures  "optiboot.elf" "optiboot.hex"
		"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1056\avr8-gnu-toolchain\bin\avr-objcopy.exe" -j .eeprom  --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0  --no-change-warnings -O ihex "optiboot.elf" "optiboot.eep" || exit 0
		"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1056\avr8-gnu-toolchain\bin\avr-objdump.exe" -h -S "optiboot.elf" > "optiboot.lss"
		"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1056\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O srec -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures "optiboot.elf" "optiboot.srec"
		"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1056\avr8-gnu-toolchain\bin\avr-size.exe" "optiboot.elf"
		   text	   data	    bss	    dec	    hex	filename
		    694	      0	      0	    694	    2b6	optiboot.elf
	Done executing task "RunCompilerTask".
	Using "RunOutputFileVerifyTask" task from assembly "C:\Program Files (x86)\Atmel\Atmel Studio 6.2\Extensions\Application\AvrGCC.dll".
	Task "RunOutputFileVerifyTask"
				Program Memory Usage 	:	694 bytes   2.1 % Full
				Data Memory Usage 		:	0 bytes   0.0 % Full
	Done executing task "RunOutputFileVerifyTask".
Done building target "CoreBuild" in project "optiboot.cproj".
Target "PostBuildEvent" skipped, due to false condition; ('$(PostBuildEvent)' != '') was evaluated as ('' != '').
Target "Build" in file "C:\Program Files (x86)\Atmel\Atmel Studio 6.2\Vs\Avr.common.targets" from project "C:\Users\Jim\Dropbox\Accelerometer Docs\Code\optiboot\optiboot\optiboot\optiboot.cproj" (entry point):
Done building target "Build" in project "optiboot.cproj".
Done building project "optiboot.cproj".

Build succeeded.
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========

This does NOT square with last night. If I hard-code BAUD_RATE, (right below F_CPU)  it changes to:

 

------ Build started: Project: optiboot, Configuration: Debug AVR ------
Build started.
Project "optiboot.cproj" (default targets):
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreBuild" in file "C:\Program Files (x86)\Atmel\Atmel Studio 6.2\Vs\Compiler.targets" from project "C:\Users\Jim\Dropbox\Accelerometer Docs\Code\optiboot\optiboot\optiboot\optiboot.cproj" (target "Build" depends on it):
	Task "RunCompilerTask"
		Shell Utils Path C:\Program Files (x86)\Atmel\Atmel Studio 6.2\shellUtils
		C:\Program Files (x86)\Atmel\Atmel Studio 6.2\shellUtils\make.exe all 
		Building file: .././optiboot.c
		Invoking: AVR/GNU C Compiler : 4.8.1
		"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1056\avr8-gnu-toolchain\bin\avr-gcc.exe"  -x c -funsigned-char -funsigned-bitfields -DDEBUG  -O1 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=atmega328p -c -std=gnu99 -MD -MP -MF "optiboot.d" -MT"optiboot.d" -MT"optiboot.o"   -o "optiboot.o" ".././optiboot.c" 
C:\Users\Jim\Dropbox\Accelerometer Docs\Code\optiboot\optiboot\optiboot\optiboot.c(300,2): error: #error BAUD_RATE error greater than 5%
		 #error BAUD_RATE error greater than 5%
		  ^
C:\Users\Jim\Dropbox\Accelerometer Docs\Code\optiboot\optiboot\optiboot\optiboot.c(362,20): warning: 'flash_led' declared 'static' but never defined [-Wunused-function]
		 static inline void flash_led(uint8_t);
		                    ^
		make: *** [optiboot.o] Error 1
	Done executing task "RunCompilerTask" -- FAILED.
Done building target "CoreBuild" in project "optiboot.cproj" -- FAILED.
Done building project "optiboot.cproj" -- FAILED.

Build FAILED.
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========

Jim

 

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

Add this:

int32_t f_cpu_        = F_CPU;
int32_t baud_rate_    = BAUD_RATE;
int32_t baud_setting_ = BAUD_SETTING;
int32_t baud_actual_  = BAUD_ACTUAL;
int32_t baud_error_   = BAUD_ERROR;

... immediately after:

endif // baud rate fastn check

... and rebuild with -save-temps.  Examine the .i file generated.  For example, I see something like this:

int32_t f_cpu_ = 8000000UL;
int32_t baud_rate_ = 115200L;
int32_t baud_setting_ = (( (8000000UL + 115200L * 4L) / ((115200L * 8L))) - 1 );
int32_t baud_actual_ = (8000000UL/(8 * (((( (8000000UL + 115200L * 4L) / ((115200L * 8L))) - 1 ))+1)));
int32_t baud_error = (( 100*(115200L - (8000000UL/(8 * (((( (8000000UL + 115200L * 4L) / ((115200L * 8L))) - 1 ))+1)))) ) / 115200L);

What do you see?

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Mon. Jul 20, 2015 - 10:39 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#define F_CPU 8000000UL

Lose the "U"...   While I haven't looked closely enough to figure out exactly where things go wrong, the calculations that figure out the baud rate error are necessarily signed since the error can be either positive or negative...

 

"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1056\avr8-gnu-toolchain\bin\avr-gcc.exe"  -x c -funsigned-char -funsigned-bitfields -DDEBUG  -O1 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=atmega328p -c -std=gnu99 -MD -MP -MF "optiboot.d" -MT"optiboot.d" -MT"optiboot.o"   -o "optiboot.o" ".././optiboot.c" 

Sigh.  That is SO not the same as the compile line generated by the official makefile:

avr-gcc -g -Wall -Os -fno-split-wide-types -mrelax -mmcu=atmega328p -DF_CPU=16000000L -DBAUD_RATE=115200 -DLED_START_FLASHES=3 -c -o optiboot.o optiboot.c

Is there established technique for generating a Atmel Studio project that can use the same makefile as a command-line build?  While it's not really something I planned to spend time on, it would be nice if Studio users weren't quite so neglected.  (or will it require a whole added directory structure as well?)

 

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

Jim: are you using int64_t in your prog? We only need an int32_t for the baud calcs I think....

 

Imagecraft compiler user

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

westfw wrote:
Sigh.  That is SO not the same as the compile line generated by the official makefile:
That shouldn't make the difference.

 

I compiled the code fragment from Jim's post using his posted command line.  I received a warning that the baud rate was more than 2% off.  Examining the .i file revealed that the calculated error was 3%, which is correct for 115200 baud @ 8 MHz.

 

Why he is getting the other errors he has seen is still a concern.  Hopefully an examination of his .i file will be revealing.

 

EDIT:  whoops, fixed a 'should' that was meant to be a 'shouldn't'!

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Tue. Jul 21, 2015 - 04:49 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

>> That is SO not the same as the compile line generated by the official makefile

That shouldn't make the difference.

 No.   But (for example) the original makefile would have printed something like:

BAUD RATE CHECK: Desired: 115200, Real: 111111, UBRRL = 8, Error=3.5%

 

If F_CPU is defined as an unsigned number (8000000UL), it apparently forces the expressions that evaluate the baud rate error to be unsigned, and ANY negative error will be interpreted as a very large positive error.  I'm not sure how to fix that; the compiler doesn't seem to like casts in expressions that are evaluated by the preprocessor...

 

https://github.com/Optiboot/opti...

https://github.com/Optiboot/opti...

 

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

Quote:
the compiler doesn't seem to like casts in expressions that are evaluated by the preprocessor...
The preprocessor is purely a text substitution system.  It only performs integer arithmetic when evaluating expressions within an #if or and #elif statement:

 

https://gcc.gnu.org/onlinedocs/gcc-3.0.2/cpp_4.html

The preprocessor does not know anything about types in the language. Therefore, sizeof operators are not recognized in `#if', and neither are enum constants. They will be taken as identifiers which are not macros, and replaced by zero. In the case of sizeof, this is likely to cause the expression to be invalid.

 

The preprocessor calculates the value of expression. It carries out all calculations in the widest integer type known to the compiler; on most machines supported by GCC this is 64 bits. This is not the same rule as the compiler uses to calculate the value of a constant expression, and may give different results in some cases. If the value comes out to be nonzero, the `#if' succeeds and the controlled text is included; otherwise it is skipped.

 

If expression is not correctly formed, GCC issues an error and treats the conditional as having failed.

 

However, a bit of testing has left me curious.

#if -5 < 0
#warning Good, -5 is less than 0.
#else
#error APOCALYPSE!
#endif

#if -5 < 0u
#warning Good. -5 is less than 0u.
#else
#error APOCALYPSE!
#endif
$ gcc -c -g -save-temps -W -Wall -o pp_test.elf pp_test.c
pp_test.c:2:2: warning: #warning Good, -5 is less than 0.
pp_test.c:7:5: warning: the left operand of "<" changes sign when promoted
pp_test.c:10:2: error: #error APOCALYPSE!

This suggests to me that the type promotion rules for the preprocessor (when evaluating expressions in #if and #elif directives) are opposite that of C, at least w.r.t. the signedness of the operands.  A brief search hasn't found any text or document to support this notion.

 

n1256 has this to say:

Prior to evaluation, macro invocations in the list of preprocessing tokens that will become the controlling constant expression are replaced (except for those macro names modified by the defined unary operator), just as in normal text. If the token defined is generated as a result of this replacement process or use of the defined unary operator does not match one of the two specified forms prior to macro replacement, the behavior is undefined. After all replacements due to macro expansion and the defined unary operator have been performed, all remaining identifiers (including those lexically identical to keywords) are replaced with the pp-number 0, and then each preprocessing token is converted into a token. The resulting tokens compose the controlling constant expression which is evaluated according to the rules of 6.6. For the purposes of this token conversion and evaluation, all signed integer types and all unsigned integer types act as if they have the same representation as, respectively, the types intmax_t and uintmax_t defined in the header <stdint.h>.145) This includes interpreting character constants, which may involve converting escape sequences into execution character set members. Whether the numeric value for these character constants matches the value obtained when an identical character constant occurs in an expression (other than within a #if or #elif directive) is implementation-defined.146) Also, whether a single-character character constant may have a negative value is implementation-defined.

 

145) Thus, on an implementation where INT_MAX is 0x7FFF and UINT_MAX is 0xFFFF, the constant 0x8000 is signed and positive within a #if expression even though it would be unsigned in translation phase 7.

... but this doesn't speak to type promotion in the preprocessor.  This is either a 'feature' documented somewhere, or a bona fide bug.  I hesitate to suggest the latter.  EDIT: I was right to hesitate.  See post #14.

 

In any case, you can adjust your code to handle this:

#define BAUD_SETTING (( (F_CPU + BAUD_RATE * 4L) / ((BAUD_RATE * 8L))) - 1 )
#define BAUD_ACTUAL (F_CPU/(8 * ((BAUD_SETTING)+1)))
#define BAUD_ERROR (( 100*(BAUD_RATE - BAUD_ACTUAL) ) / BAUD_RATE)

#if BAUD_ACTUAL < BAUD_RATE
#define BAUD_ERROR_MAGNITUDE (( 100L*(BAUD_RATE - BAUD_ACTUAL) ) / BAUD_RATE)
#define BAUD_ERROR_SIGN -1
#else
#define BAUD_ERROR_MAGNITUDE (( 100L*(BAUD_ACTUAL - BAUD_RATE) ) / BAUD_RATE)
#define BAUD_ERROR_SIGN 1
#endif

#if (BAUD_ERROR_MAGNITUDE >= 5) && (BAUD_ERROR_SIGN > 0)
#error BAUD_RATE error greater than 5%
#elif (BAUD_ERROR_MAGNITUDE >= 5) && (BAUD_ERROR_SIGN < 0)
#error BAUD_RATE error greater than -5%
#elif (BAUD_ERROR_MAGNITUDE >= 2) && (BAUD_ERROR_SIGN > 0)
#warning BAUD_RATE error greater than 2%
#elif (BAUD_ERROR_MAGNITUDE >= 2) && (BAUD_ERROR_SIGN < 0)
#warning BAUD_RATE error greater than -2%
#endif

#if (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 > 250
#error Unachievable baud rate (too slow) BAUD_RATE
#endif // baud rate slow check
#if (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 < 3
#if BAUD_ERROR_MAGNITUDE != 0 // permit high bitrates (ie 1Mbps@16MHz) if error is zero
#error Unachievable baud rate (too fast) BAUD_RATE
#endif
#endif // baud rate fastn check

The added or changed code is in boldface.

 

This should work without modification to your makefile.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Tue. Jul 21, 2015 - 06:36 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have never used make from a command line and have not a clue how to do it. I know that there is an "official make" but have no idea what I need to do to adapt it for my board (M328P, some pin changes, baud rate not Arduino standard, and a few things like that). I've searched on the forum for a tutorial on using Make but the universal response seems to have been "don't bother, use AS6.2 the way 'God' intended". But I am totally lost about even setting the starting address.

 

I would really appreciate some help, here.

 

Thanks

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

Jim, see the changes I propose above in post #12.

 

Bill,

 

joeymorin wrote:
This suggests to me that the type promotion rules for the preprocessor (when evaluating expressions in #if and #elif directives) are opposite that of C, at least w.r.t. the signedness of the operands.
Well, that was wrong :(

 

This is actually exactly how the compiler handles mixed-sign operands:

 

Otherwise, if the operand that has unsigned integer type has rank greater or equal to the rank of the type of the other operand, then the operand with signed integer type is converted to the type of the operand with unsigned integer type.

When fiddling with the test code I posted above, I played with adding L and LL to the various constants, with no effect.  As mentioned, the preprocessor evaluates all constant integer expressions using the widest type available to the implementation, i.e. 64-bit.  What is implicit in that fact is that the operands themselves are always treated as though they are of that same type.  The consequence is that they are all of the same rank, regardless of suffixes like L or LL, so the above quoted clause from 6.3.1.8 always applies to mixed-sign operations.

 

I posed this question on StackOverflow, and was promptly educated:

https://stackoverflow.com/questions/31544991/promotion-when-evaluating-constant-integer-expressions-in-preprocessor-directive

 

I've shown you one way to deal with this in post #12 above.  For another way, have a look at <util/setbaud.h>.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Tue. Jul 21, 2015 - 06:34 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Fine, I'll change the numeric evaluation statements.

 

However, I think that I need to compile the way that westfw does because I am getting 620 bytes (with Os) out of something that SHOULD fit in 512. As I stated above, I have NO idea how to deal with "non-native" make files and such. Is it sufficient to specify the make file in the IDE or do you need to do it all by  command line? There are so many questions!

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

Last Edited: Tue. Jul 21, 2015 - 08:16 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Joey: thanks for the patch suggestion.  That looks quite reasonable.

 

Jim: Are you somewhat comfortable with the windows "command line"?  Using make from the CLI is pretty easy, but you'll need to have the various atmel tools in your PATH and such.  It was set up to be REALLY easy for users of a somewhat obsolete version of the Arduino environment (back when that used to include a full copy of WINAVR)  You'd just connect to the directory with the source in it, and type a make command like:

make atmega328 BAUD_RATE=14400 AVR_FREQ=8000000 LED=B2

And you'd get a .hex file.  Unfortunately, I'm your opposite - I have very little experience with AS.  It'll take me a couple hours to set up a "virgin" AS6.2 VM to see how it sets things up, and the easiest way to compile optiboot in that situation.

 

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

Ive used Mac (Darwin) command line and Win very very little. PATH is one of the things that is a complete mystery to me. Do you have to do it for each tool used? Not really sure what you mean by "connect to the directory..." - do you mean to change directories until you are in the directory containing the source?

 

If I want an entirely different flash mechanism ( they are back/back R/G LEDs that take several pins to control.l So, My plan is to have a fixed flash mechanism inside. So, do I just leave the LED bit off?

 

Thanks for the input. 

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

Another look shows that your original formula for calculating the error was incorrect, even when all operands were signed:

#define BAUD_ERROR (( 100*(BAUD_RATE - BAUD_ACTUAL) ) / BAUD_RATE)

This should have been:

#define BAUD_ERROR (( 100*(BAUD_ACTUAL - BAUD_RATE) ) / BAUD_RATE)

As it was, it would report negative error when the real baud rate was higher than that which was requested, instead of when it was lower.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Tue. Jul 21, 2015 - 10:31 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

BTW, I also tracked down the passage in the standard responsible for the 'pre-promotion' (my term) of all integer constant to 'the widest integer type available to the compiler'.  This 'pre-promotion' takes place prior to the application of the type conversion and integer promotions rules in 6.3.1.8.

 

The relevant text is in 6.10.1 item 4:

For the purposes of this token conversion and evaluation, all signed integer types and all unsigned integer types act as if they have the same representation as, respectively, the types intmax_t and uintmax_t defined in the header <stdint.h>.

All of this will make me quite cautious in the future when using preprocessor directives to evaluate conditional expressions containing integer constants. surprise

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

Hmm.  Copy the makefile from the optiboot repository into the source directory.

In AS, select the "Project/Project Properties" panels, and go to the "build" pane.

Click "use external makefile", point the "makefile name" at the copied makefile, and set the "Build commandline" to "atmega328 AVR_FREQ=8000000 BAUD_RATE=19200 LED_START_FLASHES=0" (or whatever) and the "clean commandline" to "clean"

 

Then you should be able to do a "build"...

 

If I want an entirely different flash mechanism ( they are back/back R/G LEDs that take several pins to control.l So, My plan is to have a fixed flash mechanism inside. So, do I just leave the LED bit off?

 Setting LED_START_FLASHES=0 will turn off the current flash mechanism, which simply toggles some io port bit.  You can add your own code to do something else.

 

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

Thanks for the details.

 

Will try it right away.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

What do I do about PATH?

 

Do I need a separate PATH entry for each tool? If so, which tools?

 

Or, just the path to some enclosing directory? Again, which?

 

And,. finally, should this work with the current avr-gcc distribution or do I need to go back to WinAVR?

 

Thanks

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

You shouldn't need to do anything special with paths; the thought that you might would have applied to running from a "command prompt", but it seems to be easy enough to set up from inside AS.

 

Here's exactly what I did:

 

Start with virgin WXP.

Install latest AS6.2.

Download optiboot .zip from github.

Start AS, create "New Project", "GCC C Executable project", with name "optitest" (default directory, and Solution Name defaults to optitest as well.)  Select the atmega328p chip (although, I don't think this will matter.)

This creates a directory structure and a bunch of files, under "My Documents\Atmel Studio\optitest", including a source directory "My Documents\Atmel Studio\optitest\optitest" (whcih will have an optitest.c scaffold file.

Copy all the files from the optiboot source directory (Downloads\optiboot-master.zip\optiboot-master\optiboot\bootloaders\optiboot\ or something like that; somewhat confused by windows automatically navigating through the zip file.)  I just drilled down with Explorer, used ctrl-A to select everythibg, ctrl-C to copy, and ctrl-V to past in the optitest directory.)

Modify the project properties as described in the previous message.

Click "build."   There will be some errors/warnings that can be ignored (the AS install doesn't include the "bash" shell, which the makefile uses for the pre-compile vebose baud-rate check, for example.)  And the .elf file is not saved, and the .hex file might not be in the right place for programming or simulating, but...

 

------ Build started: Project: optitest, Configuration: Debug AVR ------
Build started.
Project "optitest.cproj" (default targets):
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreBuild" in file "C:\Program Files\Atmel\Atmel Studio 6.2\Vs\Compiler.targets" from project "C:\Documents and Settings\Bill\My Documents\Atmel Studio\optitest\optitest\optitest.cproj" (target "Build" depends on it):
	Using "RunCompilerTask" task from assembly "C:\Program Files\Atmel\Atmel Studio 6.2\Extensions\Application\AvrGCC.dll".
	Task "RunCompilerTask"
		Shell Utils Path C:\Program Files\Atmel\Atmel Studio 6.2\shellUtils
		C:\Program Files\Atmel\Atmel Studio 6.2\shellUtils\make.exe -C "C:\Documents and Settings\Bill\My Documents\Atmel Studio\optitest\optitest" -f "makefile" atmega328 AVR_FREQ=8000000 BAUD_RATE=19200 LED_START_FLASHES=0 
		process_begin: CreateProcess(NULL, bash baudcheck.tmp.sh, ...) failed.
		make (e=2): The system cannot find the file specified.
		make: [baudcheck] Error 2 (ignored)
		make: Entering directory `C:/Documents and Settings/Bill/My Documents/Atmel Studio/optitest/optitest'
		avr-gcc (AVR_8_bit_GNU_Toolchain_3.4.5_1522) 4.8.1
		Copyright (C) 2013 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.
C:\Documents and Settings\Bill\My Documents\Atmel Studio\optitest\optitest\optiboot.c(358,20): warning: 'flash_led' declared 'static' but never defined [-Wunused-function]
		 static inline void flash_led(uint8_t);
		                    ^
		avr-gcc -g -Wall -Os -fno-split-wide-types -mrelax -mmcu=atmega328p -DF_CPU=8000000  -DBAUD_RATE=19200 -DLED_START_FLASHES=0        -c -o optiboot.o optiboot.c
		avr-gcc -g -Wall -Os -fno-split-wide-types -mrelax -mmcu=atmega328p -DF_CPU=8000000  -DBAUD_RATE=19200 -DLED_START_FLASHES=0      -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe -Wl,--relax -nostartfiles -nostdlib -o optiboot_atmega328.elf optiboot.o -lc
		avr-size optiboot_atmega328.elf
		   text	   data	    bss	    dec	    hex	filename
		    426	      0	      0	    426	    1aa	optiboot_atmega328.elf
		avr-objcopy -j .text -j .data -j .version --set-section-flags .version=alloc,load -O ihex optiboot_atmega328.elf optiboot_atmega328.hex
		avr-objdump -h -S optiboot_atmega328.elf > optiboot_atmega328.lst
		rm optiboot.o optiboot_atmega328.elf
		make: Leaving directory `C:/Documents and Settings/Bill/My Documents/Atmel Studio/optitest/optitest'
	Done executing task "RunCompilerTask".
	Using "RunOutputFileVerifyTask" task from assembly "C:\Program Files\Atmel\Atmel Studio 6.2\Extensions\Application\AvrGCC.dll".
	Task "RunOutputFileVerifyTask"
		
		Display Output File Size Skipped due to : Output File not found
	Done executing task "RunOutputFileVerifyTask".
Done building target "CoreBuild" in project "optitest.cproj".
Target "PostBuildEvent" skipped, due to false condition; ('$(PostBuildEvent)' != '') was evaluated as ('' != '').
Target "Build" in file "C:\Program Files\Atmel\Atmel Studio 6.2\Vs\Avr.common.targets" from project "C:\Documents and Settings\Bill\My Documents\Atmel Studio\optitest\optitest\optitest.cproj" (entry point):
Done building target "Build" in project "optitest.cproj".
Done building project "optitest.cproj".

Build succeeded.
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========

 

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

What a treasure trove.

 

Thanks for the hard work you have put in on this. I have little doubt that it will help others.

 

With appreciation!

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

Do you have to tell AS6 to use the special Make file or did you use the auto-generated Make?

 

Thanks

Jim

 

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

(See message #20...)

 

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

What do I do about PATH?

 

Do I need a separate PATH entry for each tool? If so, which tools?

While you have the better solution already I will just point out the following for future info. In AS6 the Tools menu has an option that says "Command Prompt". This starts a Command Prompt just like using the icon from the Start Menu except that in this particular one Atmel will have amended PATH so it includes paths to the toolchains .exe's in Studio's toolchains. So if you start such a prompt and type "avr-gcc -v" you should find it runs the one that is also used in AS6.

 

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

Sorry for the question about makefile. I was focussing on msg 23 and missed that.

 

And, thanks, cliff, for the information bit about PATH.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

For the newbie and/or terminally dumb among us (including yours truly), ...

 

There is no optiboot.zip on the root GitHub Optiboot page.

 

You get it by clicking the "download ZIP" button over on the right panel of the GitHub page. You get "optiboot-master.zip", which is an an zip archive containing all of the files (in the same hierarchy) on that GitHub page.

 

Jim

 

 

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, a modicum of success. There are, I think, maybe a few minor ooopsies in Bill's blow-by-blow description, above. So, I will try to reconstruct it, hoping to help others who might follow. Here goes:

 

1. Started with a plain and well-used AtmelStudio 6.2.

2. Select "New Project" from the initial Window.

3. Name the project "optiboot". This is important. He named "optitest" The build was looking for optitest (later in the process) but what was there to be compiled was optibot. NB - this may not be totally correct as it is driven by the imported makefile, not the IDE. I was, however, more confident with using "optiboot" rather than "optitest". Calling it "optitest" certainly remove confusion about what the code editor is supposed to show.

4. Choose a project location of your preference.

5. Choose ATmega328P. This will NOT be important as it is also driven by the imported makefile and the build commandline.

6. Create the prroject, then close AtmelStudio (it will recognize newly added files when it re-opens)

7. After downloading Optiboot-Master.zip, unzip it and navigate to optiboot-master\optiboot\bootloaders\optiboot\  Your mileage may vary according to how you unzipped it.Inside the last (optiboot) directory should be many files, starting with baudcheck.c Select all with control-A OR select the first file, scroll to the last, press the shift key and select the last. First, last, and all between should be highlighted. Then control-C to copy.

8. Navigate to the new optiboot project. Find optiboot.c several directories down.

9. In the directory containing optiboot.c, do control-V (or right-click and choose paste). You will be asked about a duplicate optiboot.c file; select "Replace". All of the files from optiboot-master should now be present.

10. For clarity on the new output files, you MAY wish to delete all of the .hex and .lst files  before proceeding.

11. Run AtmelStudio again

12. Choose the optiboot project. Note that the code editor should open with the imported optiboot.c. 

13. Go to Project Menu and choose "optiboot properties" at the bottom of the menu.

14. Select "build". It is in the left-most pane, at the very top.

15. Check the "Use external makefile" checkbox

16. A box for the path to the makefile should become visible. There is a navigate button at the right. Use that and select "makefile". It should be in the default directory where the file navigator opens.

17. In the text box for "Build commandline" , type in "atmega328 AVR_FREQ=8000000 BAUD_RATE=19200 LED_START_FLASHES=0" (without the quotes). Not that you MUST enter atmega328 even if you have Mega328( because it will fail with "No rule for atmega328p"

18. In the text box for "Clean commandline", it should show default "clean". If not, type in "clean"

19. Close the Properties pane

20. Choose "Build". It should do so, successfully.

 

The output window showed the following for me:

 

------ Build started: Project: optiboot, Configuration: Debug AVR ------
Build started.
Project "optiboot.cproj" (default targets):
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreBuild" in file "C:\Program Files (x86)\Atmel\Atmel Studio 6.2\Vs\Compiler.targets" from project "C:\Users\Jim\Documents\Atmel Studio\optiboot\optiboot\optiboot.cproj" (target "Build" depends on it):
	Task "RunCompilerTask"
		Shell Utils Path C:\Program Files (x86)\Atmel\Atmel Studio 6.2\shellUtils
		C:\Program Files (x86)\Atmel\Atmel Studio 6.2\shellUtils\make.exe -C "C:\Users\Jim\Documents\Atmel Studio\optiboot\optiboot" -f "Makefile" atmega328 AVR_FREQ=8000000 
		make: Entering directory `C:/Users/Jim/Documents/Atmel Studio/optiboot/optiboot'
		avr-gcc (AVR_8_bit_GNU_Toolchain_3.4.4_1229) 4.8.1
		Copyright (C) 2013 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.
		process_begin: CreateProcess(NULL, bash baudcheck.tmp.sh, ...) failed.
		make (e=2): The system cannot find the file specified.
		make: [baudcheck] Error 2 (ignored)
		avr-gcc -g -Wall -Os -fno-split-wide-types -mrelax -mmcu=atmega328p -DF_CPU=8000000  -DBAUD_RATE=115200 -DLED_START_FLASHES=3        -c -o optiboot.o optiboot.c
C:\Users\Jim\Documents\Atmel Studio\optiboot\optiboot\optiboot.c(300,2): warning: #warning BAUD_RATE error greater than 2% [-Wcpp]
		 #warning BAUD_RATE error greater than 2%
		  ^
		avr-gcc -g -Wall -Os -fno-split-wide-types -mrelax -mmcu=atmega328p -DF_CPU=8000000  -DBAUD_RATE=115200 -DLED_START_FLASHES=3      -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe -Wl,--relax -nostartfiles -nostdlib -o optiboot_atmega328.elf optiboot.o -lc
		avr-size optiboot_atmega328.elf
		   text	   data	    bss	    dec	    hex	filename
		    464	      0	      0	    464	    1d0	optiboot_atmega328.elf
		avr-objcopy -j .text -j .data -j .version --set-section-flags .version=alloc,load -O ihex optiboot_atmega328.elf optiboot_atmega328.hex
		avr-objdump -h -S optiboot_atmega328.elf > optiboot_atmega328.lst
		rm optiboot.o optiboot_atmega328.elf
		make: Leaving directory `C:/Users/Jim/Documents/Atmel Studio/optiboot/optiboot'
	Done executing task "RunCompilerTask".
	Using "RunOutputFileVerifyTask" task from assembly "C:\Program Files (x86)\Atmel\Atmel Studio 6.2\Extensions\Application\AvrGCC.dll".
	Task "RunOutputFileVerifyTask"
		
		Display Output File Size Skipped due to : Output File not found
	Done executing task "RunOutputFileVerifyTask".
Done building target "CoreBuild" in project "optiboot.cproj".
Target "PostBuildEvent" skipped, due to false condition; ('$(PostBuildEvent)' != '') was evaluated as ('' != '').
Target "Build" in file "C:\Program Files (x86)\Atmel\Atmel Studio 6.2\Vs\Avr.common.targets" from project "C:\Users\Jim\Documents\Atmel Studio\optiboot\optiboot\optiboot.cproj" (entry point):
Done building target "Build" in project "optiboot.cproj".
Done building project "optiboot.cproj".

Build succeeded.
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========

I read that as occupying 464 bytes, or is it words? There were two output files, optiboot_atmega328.hex and optiboot_atmega328.lst buried among the imported files and replacing two files of the same names that were already there (unless you deleted all those files in step 10). The .lst file show it starting at 0x7e00 and ending at 0x7fcc. Very NICE! 461 bytes!

 

So, thank you, sincerely, Bill! Now, I can proceed with my very minor modifications. And I will watch the file size very carefully as I go.

 

Best wishes and thanks

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

Last Edited: Fri. Jul 24, 2015 - 06:13 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I read that as occupying 464 bytes, or is it words?

Bytes not words - everything in the GNU/GCC world is done in bytes (the lowest common denominator across all architectures that GCC supports).

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

Finally figured that out after looking at the .lst file.

 

Extra Credit Question: How do I tell it to generate an .elf file for debugging?

 

Thanks

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

Uncomment the line in the makefile:

#.PRECIOUS: %.elf

should become

.PRECIOUS: %.elf

 

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

Thanks for that detail!

 

Just found a little hitch. I named project optiboot. IDE, for debug, expects optiboot.elf. What is generated by make using the imported makefile is optiboot_atmega328.elf

 

Somehow, need to get the IDE and the makefile on the same page. I guess one could do this:

 

1. Name the project optiboot_atmega328

2. Add the file optiboot.c as a project file so it can be edited 

3. There will also be an optiboot_atmega328.c as a dummy starter file which will be ignored by the imported makefile.

4. The resulting optiboot_atmega328.elf should then be recognized as a valid project elf file and it should be possible to debug.

 

Does this sound reasonable? (It DOES appear to work) Alternatives?

 

Thanks

Jim

 

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

Last Edited: Sat. Jul 25, 2015 - 04:53 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Bonus Question #2 (And Quadruple Brownie Points):

 

How does one get a .map file generated from the optiboot compile with the imported makefile? 

 

Again, Many Thanks

Jim

 

 

Until Black Lives Matter, we do not have "All Lives Matter"!