News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Work around for flash memory over 64 on 18F57Q43 needed

Started by TimB, Jul 15, 2022, 09:52 AM

Previous topic - Next topic

TimB


Hi All

I'm working with Gabi on a project that uses the 18F57Q43. I'm using it as it has a lot of flash ram and I want to use some of the space for a splash screen on a TFT device. Its being saved as Flash16 data or Cdata etc

The issue is that as soon as the memory used goes over 64k it causes issues eg it crashes

Tried forcing the Flash above the 64 limit to it does not span it but still the same

Thanks In advance

Tim

top204

Declare Access_Upper_64K = True

The above declare will trigger the compiler to also manipulate the TBLPTRU SFR, and so give access to flash memory data over the 64K boundary. I thought I had added the above declare to the manual, but it appears not to be in the latest version.

The compiler used to automatically set the, above 64K, flag when devices that contained more than 64K were compiled for, but people complained that the code usage was larger on these devices than it was on 64K and less devices, even though they were not going up to 64K in code, so I made it an option. Sometimes you cannot win. :-)

Because the compiler has to manipulate the TBLPTRU SFR everytime it access' flash memory, as a 24-bit value (TBLPTRL\H\U), the code usage will increase, but there is nothing that can be done to eliminate its requirement. However, as normal, the compiler does its best to make it as small as possible.

With 18F devices, mnemonics do not care where they are in flash, however, reading and writing flash memory needs the TBLPTRL, TBLPTRH and TBLPTRU SFRs manipulated with a 24-bit value, and the TBLPTRU SFR cleared after it has been manipulated etc...

If using Dim As FlashX directives, the data will be automatically stored in lower flash memory. For very large flash memory storage, use the Cdata directives. A couple of years ago, I created a PIC18F26K40 bootloader in a single PIC device that stored the 64K flash and EEPROM data to transfer to the device in upper 64K flash memory of a PIC18F27K40, using Cdata tables, and the bootloading and GUI code lower down in flash.

By the way Tim.... Love the beard. :-)


top204

I've just remembered. I have recently placed a new declare to make the Dim As FlashX directives automatically place their flash memory data in high memory instead of low memory with 18F devices:

For example:

    Declare Flash_Tables_At_End = True        ' Place Dim As FlashX tables in high flash memory
'
' Create an 8-bit flash memory data table
'   
    Dim MyFlash As Flash8 = 1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9

The above will produce the assembler code:

F1_EOF equ $ ; TEST_18F25K20.BAS
;---------------------------------------------
; USER. FLASH MEMORY TABLE DATA
MyFlash
    db 1,2,3,4
    db 5,6,7,8
    db 9,1,2,3
    db 4,5,6,7
    db 8,9,1,2
    db 3,4,5,6
    db 7,8,9
__eof

Notice that the flash memory data is placed after the program's mnemonics, instead of before them. "F1_EOF" means the end of the main program's mnemonics. This allows Dim As Flash to have very large data items in them as well, but the "Declare Access_Upper_64K = True" will still need to be issued for devices that contain more than 64K of flash memory.

I added the above declare a few months ago for a program I was writing that had loads of flash memory data, but I did not want to use CData, because I find Dim As FlashX much easier to use, because it can be placed anywhere in the program's listing, and not get placed in the assembler listing at the same location, as Cdata tables do, and can block code if not placed correctly in the program. I will be adding it to the manual as soon as I have tested it thoroughly enough with all commands that automatically use flash memory reading. Version 4.0.1.9 onwards of the Positron8 compiler has the new declare.

TimB


Many thanks Les

I can confirm both changes to Gabi's code are working great.

Really appreciate the work on the compiler

Tim