mako777 / RenaultAffa2

Program do obsługi wyświetlacza AFFA2++ w samochodach Renault
11 stars 1 forks source link

What compiler did you use ? #3

Open Marcos2BR opened 9 months ago

Marcos2BR commented 9 months ago

Hello mako777, What compiler did you use? To compile, do I need to add just avr-libc ?

PS: I want to translate the main.cpp strings into Portuguese ...

Thank you for your work , have a good 2024

mako777 commented 9 months ago

Hello, It is "avr-g++", it's part of AVR Toolchain, you can use it standalone in command line or install some IDE, like Atmel Studio (now called Microchip Studio), or VSCode or Eclipse. And import entire project in there.

Marcos2BR commented 9 months ago

Sorry, I couldn't compile it. I tested VSCODE and WINAVR. I'm not a programming expert, I only know how to do simple things (3D marlin, and simple binaries). I managed to compile "sagem_affa2" from raszit, BUT the "RenaultAffa2" does not. I tried several ways, pasting the INCLUDE libraries manually, etc., but I was unsuccessful.

ps: I set up the circuit with your HEX on the Arduino nano and tested it on my Renault Scenic 1 phase 2 (2005), and it worked well. I wanted to compile the main.cpp that I'm translating into Portuguese... Can you give me a tip on how to fix this? Thank you for your attention.

vscode error.txt vscode

mako777 commented 9 months ago

Hmmm, I think you messed up files structure, try to move everything from "include" folder to "src" folder and try again.

Marcos2BR commented 9 months ago

Sorry for the delay, I can't compile,

I tested without libraries, with updated libraries, different directories etc etc... I'm asking for help here (Brazilian forums), but if you can help me organize the directory/library, this is the current mirror of my VS CODE https://github.com/Marcos2BR/Renault-Affa2-COPY-

photo of my compilation error image

mako777 commented 8 months ago

I have it setup in Eclipse and it's working fine ... anyway I've tried to make this in VSCode/PlatformIO and I've got same linker error. I think it has something to do with file paths and locations, PlatformIO is apparently very picky about files structure. According to readme file it should look something like this: obraz but still errors ... Linker command line from eclipse is like this: avr-g++ -Wl,-Map,RenaultAffa2.map,--cref -mrelax -Wl,--gc-sections -Wl,-u,vfprintf -mmcu=atmega328p -o "RenaultAffa2.elf" ./AVRTools/Analog2Digital.o ./I2CBase.o ./main.o ./sagem_affa2.o ./timer.o ./usart.o -lprintf_flt -lm and from VSCode I've got this: avr-g++ -o .pio\build\ATmega328P\firmware.elf -mmcu=atmega328p -Os -Wl,--gc-sections -flto -fuse-linker-plugin .pio\build\ATmega328P\src\main.o -L.pio\build\ATmega328P -Wl,--start-group .pio\build\ATmega328P\lib3f4\libAVRTools.a .pio\build\ATmega328P\lib513\libI2cbase.a .pio\build\ATmega328P\lib7a9\libusart.a .pio\build\ATmega328P\libb36\libsagem_affa2.a .pio\build\ATmega328P\lib23e\libtimer.a -lm -Wl,--end-group Maybe this has something wrong in it ... unfortunately I have no more time right now to look into this, you can try to work this out. And possibly if you want, you can drop me translated files and I will compile it.

isidrocg commented 5 months ago

Hi! First of all, thank you very much @mako777 for such an amazing and complete work. I started looking for a solution some weeks ago to use the steering wheel controls of my Renault 2001 Clio 2. After 13 years driving it, I realized how many things this car offered with the original radio, and I wanted to use them with the Pioneer radio that I equipped it with (the previous owner removed the original one and put something with a CD player, that I changed for this one with MP3 support many years ago :smiley:).

My C/C++ programming skills are not so developed, so this code was like a breath of fresh air to me. The downside, though, is that I was facing the same compilation troubles with VSCode/PlatformIO as @Marcos2BR. I tried other IDEs as Eclipse and Microchip Studio but the effort to configure them was huge, so I compiled from the command line, using for that purpose AVR-GCC 13.2.0 for Windows (you can download the ones I used from here: https://blog.zakkemble.net/avr-gcc-builds/, there is also a Linux version). The process that is working for me: after downloading and decompressing it, enter the tool's bin folder from the command line. For example, if the tools are located onC:\avr-gcc-13.2.0-x64-windows\, and your code (with the folder structure specified by @Mako777) is located on C:\PlatformIO\RenaultAffa2\src, then the process is as follows:

  1. Run the C compiler for the files timer.c and usart.c (only needed the first time, any updates to main.cpp can go to step 2):

avr-gcc -Wl,-Map,C:\PlatformIO\RenaultAffa2\src\RenaultAffa2.map,--cref -mrelax -Wl,--gc-sections -Wl,-u,vfprintf -mmcu=atmega328p C:\PlatformIO\RenaultAffa2\src\timer.c C:\PlatformIO\RenaultAffa2\src\usart.c -lprintf_flt -lm -DF_CPU=16000000 -c

  1. Then, run the compiler for the C++ code, including here the already compiled C files:

avr-g++ -Wl,-Map,C:\PlatformIO\RenaultAffa2\src\RenaultAffa2.map,--cref -mrelax -Wl,--gc-sections -Wl,-u,vfprintf -mmcu=atmega328p -o "C:\PlatformIO\RenaultAffa2\src\RenaultAffa2.elf" C:\PlatformIO\RenaultAffa2\src\AVRTools\Analog2Digital.cpp C:\PlatformIO\RenaultAffa2\src\I2CBase.cpp C:\PlatformIO\RenaultAffa2\src\main.cpp C:\PlatformIO\RenaultAffa2\src\sagem_affa2.cpp C:\PlatformIO\RenaultAffa2\src\timer.o C:\PlatformIO\RenaultAffa2\src\usart.o -lprintf_flt -lm -DF_CPU=16000000

  1. After that, you only need to convert the ELF to HEX and upload to the Arduino:

avr-objcopy -j .text -j .data -O ihex C:\PlatformIO\RenaultAffa2\src\RenaultAffa2.elf C:\PlatformIO\RenaultAffa2\src\RenaultAffa2.hex

avrdude -p m328p -c arduino -P COM5 -b 115200 -D -U flash:w:C:\PlatformIO\RenaultAffa2\src\RenaultAffa2.hex

You can check if it compiled and uploaded correctly checking the Serial Port of the Arduino, it is configured at 115200 baud. You should see something like Serial start at speed: 115200 kbps

Some errors you may experience are related with the type of chip your board actually has, that you can configure with the argument -mmcu=atmega328p and the CPU speed, that you should check in your board and configure with the argument -DF_CPU=16000000. To determine the port to which your Arduino is connected, the easiest way is checking the Arduino IDE, it will show on the list of available boards, and you can configure in avrdude with the argument -P COM5.

This has been a long comment, but I would like to end discussing the source of the problem, as it took me quite a long time to find some kind of explanation... I believe the undefined references to tx0_buffer and rx0_buffer come from a problem during compilation with Platformio using avr-g++ to compile C files. C files should be compiled with avr-gcc. The tx0_buffer and rx0_buffer variables are created on usart.c, but if you open it with VSCode, you will see there are "errors", as the__flash keyword is not recognized. This keyword is specific of C, so everything after that is giving errors and it results on a compiler error. I wonder if we can provide VSCode with the *.o files of usart and timer and just compile the changes made on main.cpp, but I have no time to check it now.

For the future, I am working on a Speed Dependent Volume Control, as it seems that the original Clio Radio had it (Pin 1 on the Radio power connector). I found the cable and I only need to check the voltage values, but it is not safe to do that while driving :confounded:, so I will need someone registering them for me while I drive. I will come back when I succeed.

Good luck with the Portuguese translation!

mako777 commented 5 months ago

Heheh, I didn't had much time then and a little forgot about this :), but now I have time and looked into this and you are right. It is an issue with mixed C/C++ code and apparently Eclipse didn't care about this (or somehow managed this under the hood). And of course PlatformIO must have the correct files structure. So I've made necessary corrections and posted this in new branch here. It should work fine now.

Marcos2BR commented 5 months ago

Heheh, eu não tive muito tempo então e um pouco esqueci sobre isso :), mas agora eu tenho tempo e olhei para isso e você está certo. É um problema com o código misto C/C++ e, aparentemente, o Eclipse não se importava com isso (ou de alguma forma conseguiu isso sob o capô). E, claro, o PlatformIO deve ter a estrutura de arquivos correta. Então eu fiz as correções necessárias e postei isso em nova filial aqui. Deve funcionar bem agora.

compilation [SUCCESS] Tomorrow I'll upload it to the Arduino and test it on the car (Renault Scénic 1 Phase 2) Captura de tela 2024-05-04 204810