Hi, I faced next issue that I've been studying for several hours and have no idea why flash reads end up with incorrect value:
The function reading the data from flash is: (gdb) list FlashReadByte 7 #include "uart.h" 8 9 uint16_t seg_cnt; 10 11 static inline uint8_t FlashReadByte(uint32_t address) 12 { 13 volatile uint8_t result; 14 volatile uint16_t sr, flash; 15 16 __asm__ __volatile__ ("mov r2,%0":"=r"(sr):); // save SR before disabling IRQ 17 __dint(); 18 __asm__ __volatile__ ("movx.a %1,%0":"=r"(flash):"m"(address)); 19 __asm__ __volatile__ ("movx.b @%1, %0":"=r"(result):"r"(flash)); 20 __asm__ __volatile__ ("mov %0,r2"::"r"(sr)); // restore previous SR and IRQ state 21 __eint(); 22 return result; // aligned address -> low-byte contains result 23 } Now, I am accessing flash at 0x14400 (82944d), this is the gdb session dump: Breakpoint 24 at 0x45e0: file ../bootloader.c, line 22. (gdb) monitor dis 0x14400 10 __ivtbl_64+0x4480: 14400: ff ff ff ff AND.B @R15+, 0xffff(R15) 14404: ff ff ff ff AND.B @R15+, 0xffff(R15) 14408: ff ff (gdb) monitor dis 82944 10 __ivtbl_64+0x4480: 14400: ff ff ff ff AND.B @R15+, 0xffff(R15) 14404: ff ff ff ff AND.B @R15+, 0xffff(R15) 14408: ff ff (gdb) continue Continuing. Breakpoint 24, FlashReadByte (address=82944) at ../bootloader.c:22 22 return result; // aligned address -> low-byte contains result (gdb) print result $62 = 85 'U' As you can see the flash content at 0x14400 read by mspdebug is ff ff ..... while the 'result' variable says it's 85. Well, it's not :-) Before, I was doing flash erases in the program, but suspected that there might have been some flash access niuances, so now flash read is the only operation that I do. What am I missing here? Best Regards, Tomek 2014-05-05 9:34 GMT+02:00 Tomek Lorek <tlo...@gmail.com>: > 2014-05-04 22:14 GMT+02:00 Tomek Lorek <tlo...@gmail.com>: >> Just checked the flashdump diff right before and after executing the >> program - "movx #0, @%0"::"r"(flash))" variant messed up the flash >> bank A from where I was running the code and it erased 0xc400 instead >> of 0x1c400. >> Do you have any idea why? > > Ok, got it! I have misplaced the input and output operands: > Correct: __asm__ __volatile__ ("movx.b #0, @%0":"=r"(flash):); > Incorrect: __asm__ __volatile__ ("movx.b #0, @%0"::"=r"(flash)); ------------------------------------------------------------------------------ Is your legacy SCM system holding you back? Join Perforce May 7 to find out: • 3 signs your SCM is hindering your productivity • Requirements for releasing software faster • Expert tips and advice for migrating your SCM now http://p.sf.net/sfu/perforce _______________________________________________ Mspgcc-users mailing list Mspgcc-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mspgcc-users