View previous topic :: View next topic |
Author |
Message |
Eric_91
Joined: 13 May 2020 Posts: 8
|
CRC16 always 0000 |
Posted: Mon Jun 08, 2020 5:29 am |
|
|
Hello
I am trying to check the integrity of the flash memory of my DSPIC33FJ64GS608.
I use several compilation units.
So I put the directive "#ROM 0x0057FA = crc16 (0x000200, 0x0057F4)" in the header of "main.c."
When I load the code with ICD4: I look in the program memory at the address 0x0057F4 and I always see 0000.
What should I do to get the right CRC16?
Anyone have an idea of the problem ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Mon Jun 08, 2020 6:42 am |
|
|
You are probably looking in the wrong place.
The '0x57FA' Here is a _word_ address. So byte 0AFF4.
If the ICD gives the address in bytes you won't be looking at the right
location.
It's a 'classic' problem, that some things are in bytes, and some things
in words... |
|
|
Eric_91
Joined: 13 May 2020 Posts: 8
|
|
Posted: Mon Jun 08, 2020 7:32 am |
|
|
Thank you for your answer,
The syntax in the CCS manual is : #ROM address = crc16(start, end)
So when i put "#ROM 0x0057FA = crc16 (0x000200, 0x0057F4)", 0x0057FA is normally a address.
In the DSPIC33FJ64GS608 datasheet the user program flash memory is [0x000200-0x0057FE]
I don't think that i'm looking in a wrong address, because if i suppress this directive i can see FFFF instead 0000
I don't see where i make a error?
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Tue Jun 09, 2020 1:53 am |
|
|
I suspect your problem is the use of multiple compilation units.
Don't.....
The CCS compiler was fundamentally designed as a single pass compiler.
MCU's were added, but have never really worked well, and lose you
quite a lot. Much of the compiler optimisation does not work effectively
if these are used. You get larger code, and less optimal use of RAM.
Given how fast the compiler can actually build any project, it is really
much better to stick with the original CCS way of working and build
the project as a single entity.
I've just built a small test for your chip, with the checksum at your
location, and without MCU's, it merrily puts the checksum there.
You will find lots of problems posted here which turn out to be people
building using MCU's. Treat these as something to avoid if you can,
and you will find things are much more likely to work correctly.... |
|
|
Eric_91
Joined: 13 May 2020 Posts: 8
|
|
Posted: Tue Jun 09, 2020 2:26 am |
|
|
Hello Ttelmah,
Thanks a lot for your answer.
I also think the problem comes from MCUs.
In the CCS manual there is this mysterious sentence: "When linking multiple compilation units be aware this directive applies to the final object
file."
Unfortunately the manual does not explain how to do this.
My project is already very advanced and I do not wish to create a single unit because I find that it is a way of programming little Advanced.
In any case, thank you for your response. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Tue Jun 09, 2020 3:43 am |
|
|
The answer is to put it into your final 'build' file, not the source files.
If you look a the ex_mcu project, if you include this in any of the standard
.c or .h files, it does not give the checksum required. However if you take
the file that gives the final 'assembly' of the project 'project_mcu.c', and
add the #rom statement to this:
Code: |
#import(FILE=report_mcu.o)
#import(FILE=filter_mcu.o)
#import(FILE=main_mcu.o)
#ROM 0x0057FA = crc16 (0x000200, 0x0057F4)
|
The CRC is then correctly generated.
Makes total sense if you think about it. The actual 'project' as a whole
does not exist till it is all brought together at this point, so the ROM
statement has nothing to actually 'checksum'...
The checksum has to be added after the final 'putting together' of the
MCU components.
I looked at what you posted from the CCS reference, and thought "this
is what I'd mean by that". Rebuilt their demo project, to use your
processor, and done like this it merrily works. |
|
|
Eric_91
Joined: 13 May 2020 Posts: 8
|
|
Posted: Tue Jun 09, 2020 5:40 am |
|
|
I loaded the CCS_MCU project and read your message with great interest.
I changed the processor. Compilation and link editing are ok.
But I don't understand in which file I should include the directives:
Code: | #import (FILE = report_mcu.o)
#import (FILE = filter_mcu.o)
#import (FILE = main_mcu.o)
#ROM 0x0057FA = crc16 (0x000200, 0x0057F4) |
If you could enlighten me... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Tue Jun 09, 2020 5:56 am |
|
|
In the mcu example, project_mcu.c is the main .c file that includes
all the other files to build the project. It contains the first three lines of
what I post (loading the three .o files).
If you add the #ROM to this, it then merrily creates the checksum for the
resulting 'linked' file, which is where it has to be. |
|
|
Eric_91
Joined: 13 May 2020 Posts: 8
|
|
Posted: Tue Jun 09, 2020 6:37 am |
|
|
Hello Ttelmah
Thank you for your patience
I added the line
#ROM 0x0057FA = crc16 (0x000200, 0x0057F4)
in the file project_mcu.c and I loaded the code with ICD4.
It still doesn't work.
This seems normal to me because the main_mcu.c file is present in the folder but is absent from the project.
The main_mcu.c file includes the project_mcu.h file. but not the project_mcu.c file
I still don't understand how you do it |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Tue Jun 09, 2020 7:27 am |
|
|
Which file in your project, imports the other files?.
How is your project actually being built?.
The ROM statement has to come after the actual files are combined. |
|
|
Eric_91
Joined: 13 May 2020 Posts: 8
|
|
Posted: Tue Jun 09, 2020 7:40 am |
|
|
There is no file which imports the other files since in Multiple compilation Units (MCUs) the project includes a tree structure which integrates the source files. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Tue Jun 09, 2020 8:06 am |
|
|
Normally, if you are using the CCS IDE, this is created for you.
If your structure is a 'tree', what is at the top of the tree?. This is the location
where everything is finally built, and is where the ROM statement needs
to be.
If you haven't got a file doing this, make one.
Look at the example, and build a file like this and put the ROM statement into
it. The point is that the ROM statement needs to be added to the complete
project, not any single part of the MCU structure. |
|
|
Eric_91
Joined: 13 May 2020 Posts: 8
|
|
Posted: Tue Jun 09, 2020 8:41 am |
|
|
So sorry, I understand quickly but I have to explain myself for a long time.
Can you watch the project: http://dl.free.fr/mDJVITHNM
So, please tell me what to change to make it work like you do. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Wed Jun 10, 2020 1:36 am |
|
|
OK. Glaring thing. You have a .X file. Implies you are using MPLAB.
You need to find out from somebody who knows how to drive MPLAB
how to add an extra command to the link line generated by MPLAB.
If I open your project in the CCS IDE, and simply edit project_mcu.c
to have:
Code: |
#import(FILE=report_mcu.o)
#import(FILE=filter_mcu.o)
#import(FILE=main_mcu.o)
#ROM 0x0057FA = crc16 (0x000200, 0x0057F4)
|
and then build in the CCS IDE, it merrily adds the checksum. |
|
|
Eric_91
Joined: 13 May 2020 Posts: 8
|
|
Posted: Wed Jun 10, 2020 3:03 am |
|
|
Hello Ttelmah,
Indeed, I use the MPLAB X IDE.
I understand better now why we had trouble understanding each other.
I will try to obtain additional information on the MPLAB X linker.
In any case, a big thank you for being interested in my problem. |
|
|
|