Skip to main content
Visitor II
October 19, 2007
Question

Iflash write protection

  • October 19, 2007
  • 3 replies
  • 907 views
Posted on October 19, 2007 at 07:12

Iflash write protection

    This topic has been closed for replies.

    3 replies

    bob2Author
    Visitor II
    October 17, 2007
    Posted on October 17, 2007 at 12:04

    I am trying to apply write protection (not access) to the lowest two 8k blocks of Iflash. I dont seem to be able to make it work. There is an example of the code on page 41 of the 276 superset datasheet 'SET PROTECTION' example 1.

    a) Will this example work? i.e it does not show WPG being set although we are writing 32 bits of data, I have tried setting WPG but it still wont work.

    b) I assume you cannot apply write protection while the cpu is in 'boot mode' because it is running from the test flash. I have tried it and the cpu appears to crash.

    Can anyone offer any help/suggestions or general enlightenment

    Many thanks Bob

    Visitor II
    October 18, 2007
    Posted on October 18, 2007 at 13:13

    Hello bob2,

    Yes of course, the write protection example is working well.

    I don't undertsand your question about the WPG (Word Program) bit.

    To test if the write protection is set properly or no, you can just apply a write operation in the concerned sector, then read the WPF flag( Write protection flag) in FER register (Flash error register)::If write protection was performed successfully, this bit (WPF) will be automatically set.

    Regards,

    Najoua.

    bob2Author
    Visitor II
    October 19, 2007
    Posted on October 19, 2007 at 07:12

    Hi and thanks for your reply.

    WPF bit

    The datasheet states that the 'fuse bits' are in XFLASH so although we are not writing to actual XFLASH, I had just tried setting the WPF bit since we are writing 32 bits (are we not?) into the fuse bits somewhere in the XFLASH area. See Superset manual 5.5 and 5.5.1 page Ok I will use the example as written.

    --------------

    We have a lot of experience with the 167 range of processors

    This 276 application is fairly new but has been running for some time and we have several versions of code running. Now that we are about to enter production phase, I am attempting to write protect our boot block.

    Please read the following and I hope I have been clear. It is simple, so I must be doing something wrong!

    Many thanks for your time

    -----Test code method-----------------------

    My test code is being executed from my application in the Iflash running at 02'0000 and above, no XFLASH is being used.

    XPERCON is set to 0x0525 so XFLASH is enabled.

    XPEN bit is also set.

    I wanted to get the write protection to work from test code first because it is simpler and faster than continually re-booting and I can use commands to enable/disable write protection.

    After running this piece of code (approx = the data sheet example), I can still perform a complete re-boot of the CPU which includes a complete Iflash ERASE of all blocks and a re-load and write of a boot block. The datasheet states that any write protect bits will remain across a reset and I assume an ERASE does not change these bits? (see the description under WPF)

    Here is my test code commands to apply protection - this is running in block 02'xxxx. After this I can still re-boot and write (after first erasing -see production method below) into the B0F0 and B0F1 areas I attempted to protect.

    WRITE_PROTECT_ON:

    MOV R0, 0x0100 ; Set SPR in FCR0H (data)

    MOV R1, FCR0H ; Target address

    EXTS FLASH_CONTROL, 1 ; Sector address

    MOV [R1], R0 ; Target address <-data

    ; --- Address of write protection register to FLASH command address

    MOV R0, 0xDFB4 ; Load address of register FNVWPIRL in FARL (0E),[DFB4]

    MOV R1, FARL

    EXTS FLASH_CONTROL, 1

    MOV [R1], R0

    MOV R0, 0x000E ; Load address of register FNVWPIRL in FARH [0E],(DFB4)

    MOV R1, FARH

    EXTS FLASH_CONTROL, 1

    MOV [R1], R0

    ; --- Data (blocks to protect) to FLASH command data

    MOV R0, 0xFFFC ; Protect B0F0 and B0F1 in FDR0L

    MOV R1, FDR0L

    EXTS FLASH_CONTROL, 1

    MOV [R1], R0

    MOV R0, 0xFFFF ; Load Data in FDR0H

    MOV R1, FDR0H

    EXTS FLASH_CONTROL, 1

    MOV [R1], R0

    ; --- Start operation

    MOV R0, 0x8000 ; WMS - start set protection

    MOV R1, FCR0H

    EXTS FLASH_CONTROL, 1

    MOV [R1], R0

    JMP ExitTestRequest

    -----Boot method-----------------------

    I intended to apply the protection (to our boot block code) during the boot sequence - after the boot code has been downloaded and written. So the designed process is thus:

    Enter boot mode - SERIAL

    Our PC application downloads the 32byte loader - we call this the 6xx file

    This then receives our loader file which runs in iRAM - we call this our 7xx file

    The 7xx file (running in iRAM) firstly ERASES the entire Iflash and then receives the boot block and writes this to Iflash starting at 00'0000h and ocupies the lowest two 8k blocks B0F0 & B0F1. The 7xx file also has XFLASH enabled and XPEN set.

    After sucessfully writing the boot block write protection shall be appllied.

    I have written all the above and the application and everything works except I seem unable to set the write protection (in other words I try to set write protection but I am still able to overwrite the boot block).

    Many thanks, Bob