Mantis Bug Tracker

View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0000005FirmwareFlash Burningpublic2008-10-29 11:192008-11-26 22:48
ReporterFred 
Assigned Tosean94z 
PriorityhighSeverityminorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version0.0.16-FlashGordon 
Target Version0.0.18-JackTheRipperFixed in Version0.0.18-JackTheRipper 
Summary0000005: Function writeAlignedBlock does not write the data
DescriptionI just attempted to burn a block of code to another block of flash using the new two way serial comms and found it did not work.

The dumps from before and after show that the first page of visible flash at 0x4000 is erased (rather than the page at 0x8000 as instructed).

I had a quick look at the source and the first thing that stands out is that the pointer is an unsigned short* type and you are incrementing it by 2 each time. I believe that when you increment a pointer it increments in chunks of the size it is, so ++ or += 1 mean 2 in the case of a short. I could be wrong though, but it would pay to check that.
TagsNo tags attached.
FirmwareVersion
Issue TypeBug
Risk of Breakage
Attached Filespng file icon 0x4000.erased.not.written.not.0x8000.as.instructed.png [^] (64,612 bytes) 2008-10-29 11:27


jpg file icon working.jpg [^] (347,562 bytes) 2008-11-11 19:01
c file icon flashWrite.c [^] (6,972 bytes) 2008-11-19 18:06

- Relationships

-  Notes
User avatar (0000002)
Fred (administrator)
2008-10-29 11:20
edited on: 2008-10-29 17:04

Date: 2008-10-27 15:29
Sender: sean94z

"I'll put some code together today and test it on the hardware when I get home and post my findings/patch."

User avatar (0000003)
Fred (administrator)
2008-10-29 11:21
edited on: 2008-10-29 17:04

Date: 2008-10-27 19:21
Sender: fredcooke

"Awesome, note that this is the highest priority bug logged yet (yeah right) ;-)"

User avatar (0000004)
Fred (administrator)
2008-10-29 11:21

Date: 2008-10-29 03:34
Sender: sean94z

"Good eye mate.

send( "Echo Pointer Test ");
pointer = 0x4000; //16384
sendUS(pointer);
send(" ");
pointer++;
sendUS(pointer);
send( " ");
telnet -----> Echo Pointer Test 16384 16385

send( "Echo Pointer Test ");
*pointer = 0x4000; //16384
sendUS(*pointer);
send(" ");
pointer++;
sendUS(*pointer);
send( " ");

telnet ------ Echo Pointer Test 16384 65535

Now to patch the code."
User avatar (0000005)
Fred (administrator)
2008-10-29 11:22
edited on: 2008-10-29 17:04

Date: 2008-10-29 05:52
Sender: fredcooke

"One of those blocks you are setting and getting the address of the pointer, the other the value AT the address, but I'm sure you know that now :-)"

User avatar (0000011)
Fred (administrator)
2008-10-30 00:46

I just ran it again with the new C file and there is absolutely no change in behaviour. I did notice something new though which you can see in the attachment pic that I posted earlier. The first word of the erased byte IS written. However the erased block is still the wrong one, and the data is still not written. The first word that IS written 0xCF3F is NOT the first word of the source block. I don't know where it came from, but this is worth investigating too.

Fred.
User avatar (0000012)
Fred (administrator)
2008-10-30 06:16

I just had a look and the issue is within the assembly as called by line 79 :

StackBurner(flash_address);
User avatar (0000013)
sean94z (reporter)
2008-10-30 15:37

I'll take a look at the flashBurn.s file and see what I find. Thanks!
User avatar (0000023)
Fred (administrator)
2008-11-01 15:33

OK, missed these comments till now. The last comment post dates the attachments though, so I assume they aren't up to date. I'll wait till you give me the go ahead and post new files before I merge them in.

Fred.
User avatar (0000036)
sean94z (reporter)
2008-11-03 17:44

I didn't get much down over the weekend but I thought I would post this.


if (Counters.logsSentCounter == 3)
    {
        send("-----------------Printing Flash Gordon Test------------------------ ");
        writeAlignedBlock((unsigned short*)0x8000, (unsigned short*)0x4000);
    }

Results in 0x8000 being erased, still need to verify that it is writing data.
User avatar (0000037)
sean94z (reporter)
2008-11-03 21:20

I have been playing with the eraseSector function and discovered that it only will erase starting at $8000 no matter what address I pass into it.
User avatar (0000040)
sean94z (reporter)
2008-11-04 18:16

Strange observation

eraseSector((unsigned short*) 0x8c00);
    }
will erase 4c00 when I look at freeems.full.dump.48k.s19

eraseSector((unsigned short*) 0x8000);

will erase 0x4000 and so on............................
User avatar (0000041)
Fred (administrator)
2008-11-04 20:05

Getting closer :-)
User avatar (0000052)
sean94z (reporter)
2008-11-06 16:20

Offset implemented in eraseFunction, it now behaves as ordered. Should have write block ready to go very soon.
User avatar (0000053)
sean94z (reporter)
2008-11-06 17:16

Offset implement in writeWord, it now behaves as ordered. Now on to testing/fixing writeAlignedBlock.
User avatar (0000054)
sean94z (reporter)
2008-11-06 19:52

Almost working, writeAligned seems to only write the first word it reads, possible syntax error. But at least its wrights an entire 1k block. Maybe I cant go flash to flash........

writeAlignedBlock((unsigned short*)0x7c00, (unsigned short*)0x2000);
User avatar (0000055)
sean94z (reporter)
2008-11-06 20:43

I have refactored the code and moved the offSet addition to the writeAligned function. This should lower CPU overhead, however eraseSector and writeWord will write to the wrong address if called outside of writeAligned, unless the offSet is added before passing the parameters.
User avatar (0000056)
sean94z (reporter)
2008-11-07 19:26

Added extra delay in StackBurner.s. No matter what I do I cannot write to 0x8000. I passed 0x7c00 and 0x1024 and the results look promising.
User avatar (0000057)
sean94z (reporter)
2008-11-07 21:26

RAMAddr offset is NOT needed, I was mistaken.
User avatar (0000058)
sean94z (reporter)
2008-11-07 21:31

7c00/c000 WORKS!!!!!!!!!!!! But here is the kicker if I comment out line
sendUS((unsigned short)RAMAddr. The cpu will hang and I never get my DONE message.



send("-----------------Printing Flash Gordon Test------------------------ ");
        writeAlignedBlock((unsigned short*)0x7c00, (unsigned short*)0xc000);
        send(" DONE ");






    while (wordCount > 0)
    {
        unsigned short sourceData = *RAMAddr; /*Convert the RAMAddr to data(dereference) */
    // sourceData += sourceData;
        writeWord(flashAddr, sourceData);
        RAMAddr = RAMAddr + 1; /* increment RAM source up by one word */
        flashAddr = flashAddr + 1; /* increment flash destination up by one word */
        sendUS((unsigned short)RAMAddr);
        wordCount--; /* Decrement our word counter */
    }
User avatar (0000059)
Fred (administrator)
2008-11-07 21:45

This isn't the best style IMO :

RAMAddr = RAMAddr + 1; /* increment RAM source up by one word */
flashAddr = flashAddr + 1; /* increment flash destination up by one word */

I would like to see this instead :

RAMAddr++; /* increment RAM source up by one word */
flashAddr++; /* increment flash destination up by one word */

They should behave identically. You can check the generated ASM between compiles to confirm that it is OK :-)
User avatar (0000060)
sean94z (reporter)
2008-11-07 21:55

Changed! Tests fine, as long as I don't comment out the sendUS((unsigned short)RAMAddr);
User avatar (0000061)
Fred (administrator)
2008-11-08 11:26

Try putting in a call to adjust ADCs instead and see if its the function call making it OK. If it's in ASM, perhaps you aren't handling the stack pointer or return of data to regs on and off the stack effectively?
User avatar (0000065)
sean94z (reporter)
2008-11-10 20:17
edited on: 2008-11-10 20:18

replacing sendUS with send(" FUQ "); causes it to write a block of CF3Fs

Tried replacing the While with a For loop, had no effect.

User avatar (0000066)
sean94z (reporter)
2008-11-10 22:34

Now works without making any external calls. There is a 'junk' function in flashWrite.c to get it working for the time being.
User avatar (0000067)
Fred (administrator)
2008-11-10 23:13

Works perfectly (congratulations) :

writeAlignedBlock((unsigned short*)0x7c00, (unsigned short*)0xc000);

Erases 0xC000 and writes nothing :

writeAlignedBlock((unsigned short*)&VETableMainFlash, (unsigned short*)0xC000);

Thanks for that, it's an improvement over the last release which is good :-)

Wrapping it in ppage swapping did not help :

unsigned char old = PPAGE;
PPAGE = BIGTABLES_PPAGE;
writeAlignedBlock((unsigned short*)&VETableMainFlash, (unsigned short*)0xC000);
PPAGE = old;

same exact result as without.
User avatar (0000070)
sean94z (reporter)
2008-11-11 20:57

I'm now working with .17 code, let me see if I can find the WTF.
User avatar (0000071)
sean94z (reporter)
2008-11-12 22:52
edited on: 2008-11-12 23:00

eraseSector( (unsigned short*)&VETableMainFlash );
writeWord((unsigned short*)&VETableMainFlash, (unsigned short)0x0000);


will erase and write 0000 to the first word in block 0x4000

The problem is in the loop unless 0x4000 is the wrong address

Also calling
eraseSector( (unsigned short*)&VETableMainFlash );
with eraseSector commented out of writeAlignedBlock.
writeAlignedBlock((unsigned short*)&VETableMainFlash, (unsigned short*)0xC000);

Will Erase 0x4000 and write nothing to it.

User avatar (0000087)
sean94z (reporter)
2008-11-19 18:08

Seems to work now, I should be able to add ppage to the header.

 StackBurner(0x3E); //PPAGE loaded into Register B, PPAGE is set with Reg B in StackBurn asm file 0x3E is a test value
User avatar (0000099)
Fred (administrator)
2008-11-26 22:48

Tested successfully this evening, closing.


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker