On 06.08.2011 0:39, Alex Stefan wrote:
> Does anybody have some example routines for reading/writing to high
> addresses in
> the flash?
Something like that:
typedef uint32_t address_t;
inline void flash::Init()
{
FCTL2 = FWKEY | FSSEL_SMCLK | (34 * FN0);
FCTL3 = FWKEY; // clear lock
}
inline void flash::Erase(address_t page)
{
asm volatile( "\r\n"
" push %B0 \r\n"
" push %A0 \r\n"
" popx.a %A0 \r\n"
" mov %3, %2 \r\n" // FCTL1 = FWKEY | ERASE;
" clrx 0(%A0) \r\n"
:"=r"(page)
:"0"(page), "m"(FCTL1), "i"((uint16_t)FWKEY | ERASE)
);
}
inline void flash::Write(address_t addr, uint8_t data)
{
asm volatile( "\r\n"
" push %B0 \r\n"
" push %A0 \r\n"
" popx.a %A0 \r\n"
" mov %4, %3 \r\n" // FCTL1 = FWKEY | WRT;
" movx.b %2, 0(%A0) \r\n"
:"=r"(addr)
:"0"(addr), "r"(data), "m"(FCTL1), "i"((uint16_t)FWKEY | WRT)
);
}
inline void flash::Write(address_t addr, uint16_t data)
{
asm volatile( "\r\n"
" push %B0 \r\n"
" push %A0 \r\n"
" popx.a %A0 \r\n"
" mov %4, %3 \r\n" // FCTL1 = FWKEY | WRT;
" movx.w %2, 0(%A0) \r\n"
:"=r"(addr)
:"0"(addr), "r"(data), "m"(FCTL1), "i"((uint16_t)FWKEY | WRT)
);
}
inline void flash::Write(address_t dst, uint8_t const * src, uint16_t size)
{
asm volatile( "\r\n"
" push %B0 \r\n"
" push %A0 \r\n"
" popx.a %A0 \r\n"
"1: \r\n"
" mov %7, %6 \r\n" // FCTL1 = FWKEY | WRT;
" movx.b @%1+, 0(%A0) \r\n"
" incx.a %A0 \r\n"
" dec %2 \r\n"
" jnz 1b \r\n"
:"=r"(dst), "=r"(src), "=r"(size)
:"0"(dst), "1"(src), "2"(size), "m"(FCTL1), "i"((uint16_t)FWKEY | WRT)
);
}
inline void flash::Read(uint8_t * dst, address_t src, uint16_t size)
{
asm volatile( "\r\n"
" push %B1 \r\n"
" push %A1 \r\n"
" popx.a %A1 \r\n"
"1: \r\n"
" movx.b @%1+, 0(%A0) \r\n"
" inc %A0 \r\n"
" dec %2 \r\n"
" jnz 1b \r\n"
:"=r"(dst), "=r"(src), "=r"(size)
:"0"(dst), "1"(src), "2"(size)
);
}
Please note, that you corrupted R15 in your routines and missed some FCTLx
registers magic to get data be actually written into flash.
>
> This is what I've written so far, but it's far from a working version:
>
> static inline __attribute__((always_inline)) void
> flash_write_byte(uint32_t addr, uint8_t val)
> {
>
> __asm__ __volatile__ (
> "dint \n"
> "nop \n"
> "mova %[addr], r15 \n"
> "movx %[val], @r15 \n"
> "eint \n"
> :
> :[addr] "r"(addr), [val] "m"(val)
> );
> }
> static inline __attribute__((always_inline)) uint8_t
> flash_read_byte(uint32_t addr)
> {
>
> uint8_t result;
> __asm__ __volatile__ (
> "dint \n"
> "nop \n"
> "mova %[addr], r15 \n"
> "movx @r15, %[result] \n"
> "eint \n"
> :[result] "=m"(result)
> :[addr] "r"(addr)
> );
> return result;
> }
>
> The problem, from what I could tell, comes from the inlining of the functions
> and the way the compiler generates their prologue. It would help me very
> much if
> I had fully working example to start from.
>
> Alex
>
>
> ------------------------------------------------------------------------------
> BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA
> The must-attend event for mobile developers. Connect with experts.
> Get tools for creating Super Apps. See the latest technologies.
> Sessions, hands-on labs, demos& much more. Register early& save!
> http://p.sf.net/sfu/rim-blackberry-1
> _______________________________________________
> Mspgcc-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/mspgcc-users
--
Regards,
Sergey A. Borshch mailto: [email protected]
SB ELDI ltd. Riga, Latvia
------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model
configuration take the hassle out of deploying and managing Subversion and
the tools developers use with it. Learn more about uberSVN and get a free
download at: http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
Mspgcc-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users