Skip to main content
Visitor II
April 18, 2007
Question

Running User Program programmed at flash memory Bank 0 Sector 2

  • April 18, 2007
  • 6 replies
  • 986 views
Posted on April 18, 2007 at 02:34

Running User Program programmed at flash memory Bank 0 Sector 2

    This topic has been closed for replies.

    6 replies

    daryl2Author
    Visitor II
    April 13, 2007
    Posted on April 13, 2007 at 08:26

    Hi all,

    I am working on a project using a STR75x MCU. I currently have the In-Application Programming (IAP) program running at flash memory Bank 0 Sector 0 - Sector 1, as my IAP is > 8k. My user program is flashed at Bank 0 Sector 2 onwards. When I launch my user program, it got an exception when performing MRCC_DeInit(). I have set the ROMSTART=0x20004000. Is this workable and are there any steps I miss out?

    If I strink my IAP to less than 8K and my user program stored in Bank 0 Sector 1 instead, I am able to launch the user program successfully.

    Visitor II
    April 15, 2007
    Posted on April 15, 2007 at 15:52

    Hi Tiger4,

    Could you please give me more details on : ''When I launch my user program, it got an exception when performing MRCC_DeInit(). ''

    What is kind of xception, you get ? if possible to provide a screenshot

    this may be helpful to understand your case .

    Regards,

    Rave

    daryl2Author
    Visitor II
    April 15, 2007
    Posted on April 16, 2007 at 00:04

    Hi Rave,

    Attached is a screenshot of the exception on my IAR embedded workbench software. It says ''Baf JTAG communication: Write to IR: Expected 0x1, got 0x0 (TAP command: 15) @ Off 0x5. I am using the Micrium uC/OS II RTOS demo software v 2.84 as my user program.

    daryl2Author
    Visitor II
    April 16, 2007
    Posted on April 17, 2007 at 01:07

    Hi Zouh,

    Yes, my IAP is based on the one from ST. My changes resulted in the IAP size to be more than 8K (1 sector size).

    I can boot my IAP up but unable to load the user program I flash in at Bank 0 Sector 2 using IAR embedded workstation. The IAP also having some problem downloading files from UART to flash.

    Visitor II
    April 17, 2007
    Posted on April 17, 2007 at 06:40

    Hello tiger4,

    Just to add to what was said by Zouhair: Your IAP code is located in Sector0 and Sector1.

    In the IAP driver provided by ST, the user application will be loaded beginning from Bank0 sector1 base address. Before loading the application, a check of its size is done in the routine FLASH_SectorMask() in common.c source file (this routine is called in ymodem.c in Ymodem_Receive() routine):

    if user_application size < 8kbytes --> sector1 will be erased

    if user_application size < 16kbytes --> sectors 1 and 2 will be erased

    if user application size < 24kbytes --> sectors 1, 2 and 3 will be erased

    etc...

    In your case, the sector1 is dedicated to IAP so it shouldn't be erased.

    So, to solve your problems, the routine FLASH_SectorMask() in common.c source file should be updated as follow:

    u32 FLASH_SectorMask(vu32 Size)

    {

    if (Size <= 0x2000)

    return 0x4 // instead of return 0x2;

    if (Size <= 0x4000)

    return 0xC // instead of return 0x6;

    if (Size <= 0x6000)

    return 0x1C // instead of return 0xE;

    if (Size <= 0xE000)

    return 0x3C // instead of return 0x1E;

    if (Size <= 0x1E000)

    return 0x7C // instead of return 0x3E;

    if (Size <= 0x2E000)

    return 0xFC // instead return 0x7E;

    //if (Size <= 0x3E000) this case is no longer valid because the user application size shouldn't exceed 256 - 16kbytes = 240kbytes.

    //return 0xFE;

    return 0;

    }

    Best regards,

    Najoua.

    daryl2Author
    Visitor II
    April 18, 2007
    Posted on April 18, 2007 at 02:34

    Hi all,

    Thanks for the replies. I have spotted the problem in the Flash_SectorMask function and corrected it. However, I am still unable to launch my user program. I found out the cause is in my IAP 75x_init.s file. My IAP uses interrupts to handle UART and USB inputs for updating its user program. Hence I need to perform EIC init below, but if I do this, I will not be able to launch my user program. But once I remove EIC Init, my user progrm will launch correctly but my IAP interrupt will not be working now. What do I need to do to enable EIC init and at the same time able to launch user program. Thanks

    ;-----------

    ;Description : Initialize the EIC as following :

    ; - IRQ disabled

    ; - FIQ disabled

    ; - IVR contains the load PC opcode

    ; - All channels are disabled

    ; - All channels priority equal to 0

    ; - All SIR registers contains offset to the related IRQ table entry

    ;-----------

    #ifdef EIC_INIT

    LDR r3, =EIC_Base_addr

    LDR r4, =0x00000000

    STR r4, [r3, #ICR_off_addr] ; Disable FIQ and IRQ

    STR r4, [r3, #IER_off_addr] ; Disable all interrupts channels

    LDR r4, =0xFFFFFFFF

    STR r4, [r3, #IPR_off_addr] ; Clear all IRQ pending bits

    LDR r4, =0x18

    STR r4, [r3, #FIR_off_addr] ; Disable FIQ channels and clear FIQ pending bits

    LDR r4, =0x00000000

    STR r4, [r3, #CIPR_off_addr] ; Reset the current priority register

    LDR r4, =0xE59F0000 ; Write the LDR pc,pc,#offset..

    STR r4, [r3, #IVR_off_addr] ; ..instruction code in IVR[31:16]

    LDR r2,= 32 ; 32 Channel to initialize

    LDR r0, =WAKUP_Addr ; Read the address of the IRQs address table

    LDR r1, =0x00000FFF

    AND r0,r0,r1

    LDR r5,=SIR0_off_addr ; Read SIR0 address

    SUB r4,r0,#8 ; subtract 8 for prefetch

    LDR r1, =0xF7E8 ; add the offset to the 0x00 address..

    ; ..(IVR address + 7E8 = 0x00)

    ; 0xF7E8 used to complete the LDR pc,offset opcode

    ADD r1,r4,r1 ; compute the jump offset

    EIC_INI

    MOV r4, r1, LSL #16 ; Left shift the result

    STR r4, [r3, r5] ; Store the result in SIRx register

    ADD r1, r1, #4 ; Next IRQ address

    ADD r5, r5, #4 ; Next SIR

    SUBS r2, r2, #1 ; Decrement the number of SIR registers to initialize

    BNE EIC_INI ; If more then continue

    #endif

    [ This message was edited by: tiger4 on 18-04-2007 11:00 ]