User avatar
garygid
Gold Member
Posts: 12469
Joined: Wed Apr 21, 2010 8:10 am
Delivery Date: 29 Mar 2011
Leaf Number: 000855
Location: Laguna Hills, Orange Co, CA

Compiling Source Code for AVR-CAN

Wed Jul 20, 2011 10:40 pm

I am working with the free WinAVR software, currently the "Portable" version (no install needed). It is all just unzipped (or copied) to the ROOT of some drive, hard or flash.

I have mine on a USB Flash Drive, and have been using it on a Windows 32-bit Vista system.

The code is ".c", and I edit with their "Programmers Notepad". Then, using a properly-prepared "Makefile" file, it compiles, assembles, and links to make a ".hex" file, all with just one menu click.

Then, I use their AVRdude program (via a ".bat" file modified for the specific programmer I decide to use) to flash the AVR-CAN board.

I have been told that I can post the source folder, with all of its many supporting programs. I will try to remove some of the unused programs to an "Unused" sub-folder, for clarity. Then, I will zip the folder (containing SOC Meter version F1.07) and post the zip file.

NOTE: This SAME firmware is used to send CAN messages (binary, not ASCII) to the PC for viewing and logging using CAN-Do.
Last edited by garygid on Sun Jul 24, 2011 8:03 am, edited 2 times in total.
See SOC/GID-Meter and CAN-Do Info
2010 Prius
2011 LEAF, 2014 Tesla S85
2018 & 2019 Tesla Model 3
PU: SDG&E
Solar PV: 33 x 225W -> 7 kW max AC
Craigslist: Xm5000Li Electric Motorcycle

User avatar
garygid
Gold Member
Posts: 12469
Joined: Wed Apr 21, 2010 8:10 am
Delivery Date: 29 Mar 2011
Leaf Number: 000855
Location: Laguna Hills, Orange Co, CA

Re: Compiling Source Code for AVR-CAN

Sat Jul 23, 2011 9:00 am

Getting WinAVR:
see
http://www.webring.org/l/rd?ring=avr;id ... e%2Enet%2F" onclick="window.open(this.href);return false;

Prepare to use:
Last edited by garygid on Thu May 02, 2013 3:12 pm, edited 1 time in total.
See SOC/GID-Meter and CAN-Do Info
2010 Prius
2011 LEAF, 2014 Tesla S85
2018 & 2019 Tesla Model 3
PU: SDG&E
Solar PV: 33 x 225W -> 7 kW max AC
Craigslist: Xm5000Li Electric Motorcycle

User avatar
garygid
Gold Member
Posts: 12469
Joined: Wed Apr 21, 2010 8:10 am
Delivery Date: 29 Mar 2011
Leaf Number: 000855
Location: Laguna Hills, Orange Co, CA

Re: Compiling Source Code for AVR-CAN

Sat Jul 23, 2011 9:04 am

Source Code:

1. SOC Main Program and Subroutines:

2. Makefile:

3. Folder of Support Routines (some unused):

4. The WinAVE Libraries:
See SOC/GID-Meter and CAN-Do Info
2010 Prius
2011 LEAF, 2014 Tesla S85
2018 & 2019 Tesla Model 3
PU: SDG&E
Solar PV: 33 x 225W -> 7 kW max AC
Craigslist: Xm5000Li Electric Motorcycle

User avatar
garygid
Gold Member
Posts: 12469
Joined: Wed Apr 21, 2010 8:10 am
Delivery Date: 29 Mar 2011
Leaf Number: 000855
Location: Laguna Hills, Orange Co, CA

Re: Compiling Source Code for AVR-CAN

Sat Jul 23, 2011 9:36 am

Compile ... and make Hex file:

1. Open the WinAVR "Programmers Notepad":

2. Edit: Not Yet! Get the standard SOC-Meter release version F1.07 (or later) working FIRST.

3. Make Clean: This function (on the Tool menu) erases old files that were produced by previous Compile-Link attempts. Try it to see that it works, it takes only a couple of seconds. Note the "results" down below the Edit Panel.

4. Make All: This powerful function (also on the Tool menu) also gets its instructions from the "Makefile" file (no file extension). Basically it starts with your source code (spy.c and spy.h), adds other programs and libraries, compiles, assembles, and links everything, and finally produces a "spy.hex" file that you can use to flash the AVR-CAN board. If this step completes without error, you can move on to the "flashing" step, otherwise you edit (or whatever is needed) to correct the "errors".
Last edited by garygid on Sun Jul 24, 2011 8:04 am, edited 1 time in total.
See SOC/GID-Meter and CAN-Do Info
2010 Prius
2011 LEAF, 2014 Tesla S85
2018 & 2019 Tesla Model 3
PU: SDG&E
Solar PV: 33 x 225W -> 7 kW max AC
Craigslist: Xm5000Li Electric Motorcycle

User avatar
garygid
Gold Member
Posts: 12469
Joined: Wed Apr 21, 2010 8:10 am
Delivery Date: 29 Mar 2011
Leaf Number: 000855
Location: Laguna Hills, Orange Co, CA

Re: Compiling Source Code for AVR-CAN

Sat Jul 23, 2011 9:52 am

Flashing AVR-CAN with Spy.hex

1. Using "mini USB AVR JTAG" from Ebay:

2. Using AVR-Dragon:

3. Using RS232 AVR-JTAG-ICE from Ebay:
The problem here, is a "sufficiently good" RS232 port is needed. MANY of the inexpensive, easy-to-find USB-to-RS232 adapters are NOT "good enough". I have two "brands" (long ago, forgotten sources) that work 100%. However, I have purchased and tried two other sources, and one works 2% of the time, the other works 50% to 80% ... neither is recommended.
See SOC/GID-Meter and CAN-Do Info
2010 Prius
2011 LEAF, 2014 Tesla S85
2018 & 2019 Tesla Model 3
PU: SDG&E
Solar PV: 33 x 225W -> 7 kW max AC
Craigslist: Xm5000Li Electric Motorcycle

User avatar
garygid
Gold Member
Posts: 12469
Joined: Wed Apr 21, 2010 8:10 am
Delivery Date: 29 Mar 2011
Leaf Number: 000855
Location: Laguna Hills, Orange Co, CA

Re: Compiling Source Code for AVR-CAN

Sun Jul 24, 2011 8:01 am

I have just been told that I can post our source-code folder, with
the needed supporting programs that are not in the library.

I will try to move some of the unused programs to an "Unused" sub-folder, for clarity.
Then, I will zip the folder (containing SOC Meter version F1.07) and post the zip file.

NOTE: This SAME firmware is used to send CAN messages (binary, not ASCII)
to the PC for viewing and logging using CAN-Do.

IMPORTANT:
If you change the program for your own uses, PLEASE DISPLAY a different
version number
when the program starts. I am using the F1.xx series.
For Home-Made versions, I suggest the "H" series, something like "H0.01".

If you do NOT do this, and there are several/many different "F1.07" (etc.)
versions floating around, it will be IMPOSSIBLE to help people with problems.
See SOC/GID-Meter and CAN-Do Info
2010 Prius
2011 LEAF, 2014 Tesla S85
2018 & 2019 Tesla Model 3
PU: SDG&E
Solar PV: 33 x 225W -> 7 kW max AC
Craigslist: Xm5000Li Electric Motorcycle

User avatar
evnow
Moderator
Posts: 11480
Joined: Thu Apr 22, 2010 11:41 am
Delivery Date: 25 Feb 2011
Leaf Number: 303
Location: Seattle, WA

Re: Compiling Source Code for AVR-CAN

Sun Jul 24, 2011 9:20 am

I was always getting an error in AVR Studio 4 (which uses WinAVR) when compiling. A bit of searching led me to this important piece of information.

The error I got on Win 7 64 bit was this.
make: Interrupt/Exception caught (code = 0xc00000fd, addr = 0x4217b3


In a 64 bit OS, 23 bit software should be installed under "Program Files (x86)" directory. Turns out, WinAVR doesn't like brackets and other stuff in the directory path. Here is the solution that worked. Now I can build, deploy & debug using AVR Studio 4.

http://www.avrfreaks.net/index.php?name ... ic&t=64657
CMD with "Run As Administrator"
cd C:\Program Files
mklink /D WinAVR "..\Program Files (x86)\WinAVR"

Change the reg key @
"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\WinAVR" to the new reference.

UninstallString = c:\Program Files\WinAVR\WinAVR-20090313-uninstall.exe

After that... I can build WinAvr GCC from AVRStudio on x64 Windows 7.
Alternatively, you could install WinAVR under the suggested c:\winavr directly. But that idea doesn't agree with me - aesthetically. I like to keep my directory structures clean :lol:

ps : Moving my post to keep Gary's posts in the beginning.
1st Leaf : 2/28/2011 to 5/6/2013
2nd Leaf : 5/4/2013 to 3/21/2017
Volt : 3/25/2017 to 5/25/2018
Model 3 : 5/10/2018 to ?

User avatar
garygid
Gold Member
Posts: 12469
Joined: Wed Apr 21, 2010 8:10 am
Delivery Date: 29 Mar 2011
Leaf Number: 000855
Location: Laguna Hills, Orange Co, CA

Re: Compiling Source Code for AVR-CAN

Sun Jul 24, 2011 3:27 pm

evnow,
Thanks for moving the post.

I used "WinAVR Portable" which needs NO install at all.

One just unzips "Portable" to the root of some drive,
and I used a USB flash drive.
See SOC/GID-Meter and CAN-Do Info
2010 Prius
2011 LEAF, 2014 Tesla S85
2018 & 2019 Tesla Model 3
PU: SDG&E
Solar PV: 33 x 225W -> 7 kW max AC
Craigslist: Xm5000Li Electric Motorcycle

jwatte
Posts: 132
Joined: Wed May 25, 2011 5:44 pm
Delivery Date: 14 Jul 2011

Re: Compiling Source Code for AVR-CAN

Sun Jul 24, 2011 4:41 pm

evnow wrote:Turns out, WinAVR doesn't like brackets and other stuff in the directory path.
Wow! What a POS. Nobody updated it even for Windows XP? Is it a ported Win16 program, using short names? Or is it just not using a Windows Installer compatible installer?

One thing you can do with programs like this (and programs that want to run "at the root" rather than just figuring out where they run using GetModuleInformation()) is to use the DOS "Subst" command.

Open a Command Prompt window (perhaps in administrative mode) and give the command:

SUBST Q: "C:\Program Files (x86)\YourProgram"

Now, the "drive" Q: shows up, and contains anything in YourProgram. Hopefully, it should be able to deal with that...

User avatar
evnow
Moderator
Posts: 11480
Joined: Thu Apr 22, 2010 11:41 am
Delivery Date: 25 Feb 2011
Leaf Number: 303
Location: Seattle, WA

Re: Compiling Source Code for AVR-CAN

Sun Jul 24, 2011 5:51 pm

jwatte wrote:Now, the "drive" Q: shows up, and contains anything in YourProgram. Hopefully, it should be able to deal with that...
The problem is the directory name "(86)" than being in the route. Anyway, it is an open source pgm ... I guess nobody wants to clean it up.
1st Leaf : 2/28/2011 to 5/6/2013
2nd Leaf : 5/4/2013 to 3/21/2017
Volt : 3/25/2017 to 5/25/2018
Model 3 : 5/10/2018 to ?

Return to “LEAF CANBus”