• AVR Freaks

Hot!Soft swap instruction "bootswp"

Author
Sanguin
New Member
  • Total Posts : 1
  • Reward points : 0
  • Joined: 2016/02/22 02:17:49
  • Location: 0
  • Status: offline
2016/02/23 00:50:30 (permalink)
5 (1)

Soft swap instruction "bootswp"

Hello,
 
I'm trying to use the "bootswp" instruction to soft swap from the active to the inactive partition on a dsPIC33EP64GS504 in dual partition mode. The application in my inactive partiton should be fine, because it is working after I change FBTSEQ and force a restart. The processor is always restarting after it runs the following instructions:
 
asm("disi #0x3FFF"); //disable interrupts
asm("mov #0x55, W0"); //unlocking sequence
asm("mov W0, NVMKEY");
asm("mov #0xAA, W0");
asm("mov W0, NVMKEY");
asm("bootswp"); //soft swap
asm("goto 0x00"); //goto start of now active partition two

 
(Bootswp instruction is enabled in configuration bits for both partitions)
 
I think going to address 0x00 is correct, because I assume after the soft swap the "then active" partition uses the addresses starting from 0x00 and not the addresses starting from 0x400000 any more.
 
Does anybody have some experience with this and can help me to get this code work?
 
Regards,
Sanguin
#1

19 Replies Related Threads

    D Pickle
    Starting Member
    • Total Posts : 31
    • Reward points : 0
    • Joined: 2016/02/15 07:51:59
    • Location: 0
    • Status: offline
    Re: Soft swap instruction "bootswp" 2016/02/25 01:47:19 (permalink)
    +1 (1)
    I have the same problem with a PIC24FJ256GB406. Using MPLABX 3.10, XC16 1.25, ICD3.
     
    By default THIS pic does not have an alternative interrupt vector table and there are no "AltInterrupt" style alternate interrupt names to keep the compiler happy.
    Two basic options for a bootloader on this pic are either enable a boot segment or use dual partitions. Other imaginative options are available.
     
    From document 70005156b.pdf section 3.2.4.2 (Dual Partition Flash Program Memory) 
    ...Note:
    If the BOOTSWP instruction is executed from within a function that has created a new stack frame using the LNK instruction, a CALL must be used following BOOTSWP rather than a GOTO; otherwise, the device will generate a stack error trap...
     
    Inspecting the disassembly listing shows a lnk instruction in main(), so, presumably one requires
    asm("call 0x00"); //goto start of now active partition two
     
    I haven't got this to work yet. And, the code would have to allow for an updated compiler that now doesn't use a lnk command.
     
    It is somewhat frustrating that, unless you compile, the Configuration Bits window in MPLABX IDE does not reflect the dual partition state of the code, even though the code has #pragma config BTMODE = DUAL.
    MPLABX IDE 3.25 Configuration Bits window is no better, producing a "#pragma config DSSWEN = ON" which fails to compile.
     
    If you solve your problem, please write the solution here. Hopefully it will point me in the right direction.
     
     
    Cheers
    Dave.
    post edited by D Pickle - 2016/02/25 01:49:09
    #2
    pchidley
    Super Member
    • Total Posts : 117
    • Reward points : 0
    • Joined: 2009/11/24 13:23:55
    • Location: Calgary, Alberta, Canada
    • Status: offline
    Re: Soft swap instruction "bootswp" 2016/05/18 08:46:25 (permalink)
    0
    Any progress?  Looking for info on how to do this before I even start.
     
    #3
    lyersin
    Starting Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2012/02/21 06:20:51
    • Location: 0
    • Status: offline
    Re: Soft swap instruction "bootswp" 2016/05/25 00:34:28 (permalink)
    +2 (2)
    Hi,
     
    I have the same issue with bootswp instruction on a PIC24FJ1024GB610.
    I am trying both with goto and call instructions, the device resets but the partition has not been swapped.
     
    Have you set the config word #pragma config BTSWP = ON for enabling the BOOTSWP instruction?
     
    By the way, how are you changin the FBTSEQ ? Using TBLWRT ?
     
    Cheers,
     
    Lionel.
    #4
    pchidley
    Super Member
    • Total Posts : 117
    • Reward points : 0
    • Joined: 2009/11/24 13:23:55
    • Location: Calgary, Alberta, Canada
    • Status: offline
    Re: Soft swap instruction "bootswp" 2016/05/31 13:57:08 (permalink)
    0
    Having the same problem with the bootswp instruction on a PIC24FJ1024GB610.
     
    Hello MCHP, anyone home?
     
     
    #5
    NorthGuy
    Super Member
    • Total Posts : 5544
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: online
    Re: Soft swap instruction "bootswp" 2016/05/31 14:06:29 (permalink)
    +1 (1)
    I'm not sure the "goto" instruction at address 0x00 can be executed in a regular fashion. Have you tried jumping to other addresses?
    #6
    Aussie Susan
    Super Member
    • Total Posts : 3608
    • Reward points : 0
    • Joined: 2008/08/18 22:20:40
    • Location: Melbourne, Australia
    • Status: offline
    Re: Soft swap instruction "bootswp" 2016/05/31 19:46:13 (permalink)
    +1 (1)
    @pchidley - this is a user forum and Microchip people do not regularly take part (although there are a couple that do). If you want an official Microchip response then you will need to raise a support ticket.
    @NorthGuy - while this particular device might differ, normally the instruction at 0x00 is just a regular instruction as the PC is set to 0 at POR and doing an (assembler) 'goto 0' has long been the "accepted" way to effect a reset/restart. Are you saying that this chip might be different due to the dual partition flash memory organisation?
    Looking at the data sheet (and that is the extent of my knowledge of this chip) it says (Figure 4-4) that the 'active' partition is always *mapped* with a "GOTO" at position 0x00 and the inactive partition is *mapped* to 0x400000 ad there is a "GOTO" there (but I would guess the destination would assume a 0x00 base mapping address as it would only be executed when that partition was 'active').
    Susan
    #7
    NorthGuy
    Super Member
    • Total Posts : 5544
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: online
    Re: Soft swap instruction "bootswp" 2016/05/31 20:23:04 (permalink)
    0
    Aussie Susan
    @NorthGuy - while this particular device might differ, normally the instruction at 0x00 is just a regular instruction as the PC is set to 0 at POR and doing an (assembler) 'goto 0' has long been the "accepted" way to effect a reset/restart. Are you saying that this chip might be different due to the dual partition flash memory organisation?



    I'm not 100% sure, but I recall I couldn't put anything at 0x00 except "goto", e.g. "bra" wouldn't work. So doing "goto 0x0" might cause a reset instead of literally executing instruction located at 0x0. It may not be a big difference for a regular device, but for dual boot chip the reset will swap the partitions back. I didn't test this. Just suggesting a probable cause.
    #8
    Lazzarini
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2016/05/19 00:53:44
    • Location: 0
    • Status: offline
    Re: Soft swap instruction "bootswp" 2016/06/03 05:39:07 (permalink)
    +1 (1)
    Hi,
     
    I have the same issue with a PIC24FJ256GB410.
    I used the code from Sanguin, but when I use goto, call or bra instructions to address 0x00, the device resets and continues on the same partition.
    Someone has any progress?
     
    Thanks,
    Lazzarini
    #9
    NorthGuy
    Super Member
    • Total Posts : 5544
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: online
    Re: Soft swap instruction "bootswp" 2016/06/03 06:29:30 (permalink)
    +1 (1)
    Lazzarini
    Someone has any progress?



    Have you tried jumping to other addresses, not 0x0?
    #10
    Lazzarini
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2016/05/19 00:53:44
    • Location: 0
    • Status: offline
    Re: Soft swap instruction "bootswp" 2016/06/03 06:34:50 (permalink)
    0
    I've tried different addresses as the beginning of the code 0x400, or the other partition 0x400000. But it always resets the PIC and continues on the same partition.
    #11
    pchidley
    Super Member
    • Total Posts : 117
    • Reward points : 0
    • Joined: 2009/11/24 13:23:55
    • Location: Calgary, Alberta, Canada
    • Status: offline
    Re: Soft swap instruction "bootswp" 2016/06/03 13:14:12 (permalink)
    +2 (2)
    @Aussie Susan - You are right that MCHP staff are seldom seen on the forums.  However this is not a 'user' forum.  MCHP staff are paid to monitor it and it is their job to monitor it.  Not to mention it would be foolish for the company not to know what is going on here.  I had to write to Steve S himself once when the PIC32 forum was being ignored.  Turns out the guy in charge of supporting the forum had left and they forgot to replace him or reassign the task.
     
    As for a support ticket.  Did that the day I saw that no one here on the forum had it working either.
    Their response so far has been "that part is new" and "that part is in XC16 beta only".  BOTH totally lame excuses since the part I'm using with dual flash partition has been "active" and available retail for over six months.  Which means MCHP probably knew about dual partition parts a year or two ago in the planning stages.  And they still don't have a working code example.
     
    I'm working with tech support and an FAE to figure it out.  I'll probably figure it out first but I would be thrilled if MCHP did first.  (like six months ago)
     
    P.S.  Watch out if anyone is using MPLAB X v3.26, it has a serious debug error where the edit screen would show the wrong line and file when stopped by a break point or manually.  Program view was correct but the editor and there for debug was useless.  Fixed in v3.30
    2. MCC had a bug where assigning an output such as RTCC would result in all your user assigned pin names being reset to the default.  Not fun on a 100 pin part.  Seems to be fixed in v3.15.0
    3. And not to be left out, the XC16 group also screwed up recently.  Many of the .inc or .h files have multiple errors in them.  For example I'm using p24FJ1024GM610.h and many of the defines used for the configuration bits have changed.  Such as BSS_OFF and GSS_OFF are now just OFF.   Just to make sure that older projects like EZBL don't work on v1.26 without edits.  I would upload a screen cap to show you, but wait, that doesn't work either on the new forum software.
     
    And if you try to get a hold of anyone at MCHP they are probably in meetings about the Atmel acquisition.  Wouldn't it be nice if they supported the parts they have instead of looking for more parts to add.  Wait till the Atmel users get a taste of MCHP support.
     
    grin: grin  Can't upload a code segment or image but at least we have smileys.  (holding up sarcasm sign)
    #12
    pchidley
    Super Member
    • Total Posts : 117
    • Reward points : 0
    • Joined: 2009/11/24 13:23:55
    • Location: Calgary, Alberta, Canada
    • Status: offline
    Re: Soft swap instruction "bootswp" 2016/06/03 13:27:59 (permalink)
    +1 (1)
    For those of you asking the less than shiny questions please read;
     
    http://ww1.microchip.com/downloads/en/DeviceDoc/70005156b.pdf
     
    Especially page 11 where it tells you exactly WHAT to do.  However it doesn't tell you HOW to do it.
     
    MPLAB X has limited support for dual partitions, see project properties > xc16 (Global Options) > Partition
     
    Also MCC has limited support for dual partitions in particular the register settings in System Module > Registers
     
    Now if only we had the book "Dual Partition Flash Memory USB Boot Loader for Dummies"
     
    IF (when) I figure it out I will post the answer here, please do the same if you get it working.
    #13
    NorthGuy
    Super Member
    • Total Posts : 5544
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: online
    Re: Soft swap instruction "bootswp" 2016/06/03 14:27:47 (permalink)
    0
    LazzariniI've tried different addresses as the beginning of the code 0x400, or the other partition 0x400000. But it always resets the PIC and continues on the same partition.

     
    That's strange. If bootswp didn't work at all, the jump to 0x400 within the current partition wouldn't reset the PIC. May be they got the op-code for bootswp wrong? What does it show in the disassembly?
     
    [edit] I've got 0xfe2000 for BOOTSWP (see this thread - http://www.microchip.com/forums/m879813.aspx )  but this came from MPLAB. RESET is 0xfe0000 - pretty close. Perhaps, it is 0xfe1000 or 0xfe3000 or anything else nearby - there's no docs for this.
     
    [edit]I can't remember if I made it working or not.
     
    post edited by NorthGuy - 2016/06/03 14:42:00
    #14
    pchidley
    Super Member
    • Total Posts : 117
    • Reward points : 0
    • Joined: 2009/11/24 13:23:55
    • Location: Calgary, Alberta, Canada
    • Status: offline
    Re: Soft swap instruction "bootswp" 2016/06/09 09:48:35 (permalink)
    0
    Anyone got this working yet?  The datasheet lists it as a feature, so it must be true.  I mean work.
    #15
    Lazzarini
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2016/05/19 00:53:44
    • Location: 0
    • Status: offline
    Re: Soft swap instruction "bootswp" 2016/07/18 02:58:45 (permalink)
    +1 (1)
    Hi!
     
    After a lot of research and some help of microchip, I found the solution of my problem.
    First of all, I was using an old version of MPLAB X (v3.15), which the IDE GUI interface was developed for Dual Partition, but the PicKit 3 hardware not. So I thought that I was programming the PIC for Dual Partition, but I wasn't. I needed to update my MPLAB X for version 3.30 and it works correctly.
    For the bootswp I created a new function using Sanguin code with some modifications:
     
    static void inline __attribute__((always_inline, noreturn)) Swap(void)
    {
    __asm__ volatile("\n disi #0x3FFF"
    "\n mov #0x0055, w0"
    "\n mov w0, NVMKEY"
    "\n mov #0x00AA, w0"
    "\n mov w0, NVMKEY"
    "\n bootswp ; Swap partitions"
    "\n retfie ; Set PC = 0x000000, clear CORCON<IPL3>, and clear SR<7:0> atomically from the stack"
    : : : "memory"); 

    __builtin_unreachable();
     
    }

     
    My problem now is how to change the FBTSEQ?
     
    Thanks!
    Lazzarini 
    #16
    Stampede
    Super Member
    • Total Posts : 400
    • Reward points : 0
    • Joined: 2006/10/04 05:59:28
    • Location: Germany
    • Status: offline
    Re: Soft swap instruction "bootswp" 2016/07/22 05:57:49 (permalink)
    0
    Hi,
     
    Datasheet:
     

    The 12-bit Boot Sequence Number is stored in the FBTSEQ Flash Configuration Word, which is
    always located at the last location of user program memory, above the other Flash Configuration
    Words (see Figure 3-2). Unlike other Configuration registers, which only use the lower 16 bits of
    the program memory word, FBTSEQ is a full 24 bits wide. Each partition should, under normal
    operating conditions, have a different value for FBTSEQ. When Dual Partition modes are not
    used, the value of FBTSEQ is ignored.
    The Boot Sequence Number is stored in two parts: the actual value in the bit field, BSEQx
    (FBTSEQ<11:0>), and the one’s complement of the value in the IBSEQx bits field
    (FBTSEQ<23:12>). When the Boot Sequence Number is read upon a device Reset, the values
    of BSEQx and IBSEQx are automatically compared. If these two values are not mutual
    complements, the Boot Sequence Number is considered invalid. The complement value is not
    automatically created by hardware, nor is it verified by hardware upon programming. The
    application must calculate and program the appropriate value.

     
    So FBTSEQ needs to be set in your configuration first, then you need to reprogramm it using your flash writing routines.
    #17
    AMIT_GOHEL
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2013/04/04 03:03:38
    • Location: 0
    • Status: offline
    Re: Soft swap instruction "bootswp" 2017/06/30 00:23:39 (permalink)
    0
    Struggling with the similar issue since last 2-3 days.
    Able to download the entire Hex file to second partition(Inactive one),After Changing FBOOTSEQ number as per the document it still run the same partition code.
    I am not using Bootswap,my project needs permanent swapping.
     
    I think mircochip should provide some solid code example for this,otherwise there is no use of this wonderful technology if developer can not use it.
     
    If anyone got it working or can suggest anything would be great help.
    If I got solution I will post here ,Might save someone's time.
     
     
    #18
    Rob McKenna
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Status: offline
    Re: Soft swap instruction "bootswp" 2019/05/22 08:50:14 (permalink)
    0
    And they did provide some code. And this code actually makes it happen, you can either switch partition with Bootswap or overwrite the FBTSEQ number. It is hidden in their ezbl library.
     
    So, either integrate the library into your project, or copy the relevant functions from the library.
     
    ..oh, and there is cleary something missing in the documentation, microchip should add a few lines so everyone is clear about what they want to tell you. Something like this:
    https://www.youtube.com/watch?v=0a-yHJ8O_io
     
    #19
    Rob McKenna
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Status: offline
    Re: Soft swap instruction "bootswp" 2019/05/22 11:28:29 (permalink)
    0
    Sorry for double post, seems i can't edit my last one...
     
    These are the names of the functions, and where their implementation is to find:
    EZBL_WriteFBTSEQ (int target, int absoluteSEQ, int relativeSEQ)
    EZBL_PartitionSwap (void)
    (..ezbl-v2.11\ezbl_lib\sectioned_functions)
    #20
    Jump to:
    © 2019 APG vNext Commercial Version 4.5