Hello,
For anyone intending to use Ake's code for devices other that the GB/GT, the resources required by the
code should be considered. The method places the RAM based function within a fixed block of RAM,
and this block remains dedicated to the erase/programming process.
A block size of 128 bytes has been allowed within the code, and the actual code size generated for the
function seems to be 101 bytes. This does not include any RAM as a buffer for the data to be written, in
the case of burst programming.
This amount of RAM is likely to be very significant for a device with less than 1K of RAM, for example
QG8 or QG4, and potentially makes the code unworkable for such devices. For the low end
MCUs, alternative methods will likely be necessary.
The other alternative would be to use the stack, rather than a dedicated block, for the RAM based
function(s). Some versions that use this method (identified by the DoOnStack label), seem to need
about 70-80 bytes of RAM, but this is probably due to the RAM based routines being written in assembler,
rather than C.
Obviously, the stack size will need to be sufficiently large, but the memory does become available again,
once the function is completed. Since interrupts need to be disabled during execution of the function, the
stack size requirement, beyond the function size, should be minimal provided the erase or programming
function calls are not too deeply nested.
Ake, there were a couple of issues associated with your code -
1) The linking initially failed because the reset vector was defined in two places (with the use of
MCUInit() function).
2) I received a C1805 warning at the line -
dstPtr = (char *)&Flash_Cmd;
However, the pointer value was actually correct (0x0100). The warning is "Non standard conversion
used".
3) The following description seems a little confusing to me -
/*
Start_Copy_In_RAM refers to the begining of the segment ToCopyToRAM.
This segment contains the functions after they have been copied to RAM.
*/
#define Start_Copy_In_RAM __SEG_START_FLASH_ROUTINES
#define Size_Copy_In_RAM __SEG_SIZE_FLASH_ROUTINES
The macro actually refers to the source address of the code block. The segment contains the functions
as they exist in flash.
4) Finally, the following macro doesn't seem to make sense.
#define Flash_Erase(Address) \
Flash_Cmd((unsigned int)Address, (unsigned int)1, (unsigned char*) &FlashBuffer[0], FLASH_ERASE_CMD)
FlashBuffer seems to be defined as a global RAM buffer for the source data during burst programming.
Its reference would seem unnecessary for the Flash_Erase.
Regards,
Mac
Message Edited by bigmac on
2008-02-25 04:23 AM