Dual-boot

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
jjw
Posts: 78
Joined: Sat Aug 25, 2012 5:35 am
Has thanked: 71 times
Been thanked: 9 times

Dual-boot

Post by jjw »

I didn’t find any info how to make dual-boot for Pic mcu in Forum so I made this tryout the best knowledge I had. This is working quite well in my hardware now but not knowing is there a better way to do it and is there in a code some mistakes. So is there anybody in a Forum who can review my Flowchart. In a near future I will make a triple-boot which necessary for my purpose and it would be nice to get comments of my dual-booting version before making the triple-boot Flowchart. I do have lot of space in pic18f252 so that’s not a problem.
Thanks in advanced for your help :D .

jjw
Attachments
Dual_boot30082013_test.fcf
(126.49 KiB) Downloaded 338 times

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times

Re: Dual-boot

Post by kersing »

First, there is no real issue with the solution as implemented (I've only checked the outline of your Main macro, not the contents of the large blocks of code). Just picking nits as you are asking for feedback:

This implementation is not really a dual boot implementation as most people would interpret dual boot. Depending on the state of B7 and A4 none (B7 and A4 are zero) or one (B7 or A4 is one or both are one) of the large code blocks will be executed. In a 'dual boot' scenario you would reboot the controller and exactly one of the large blocks would be executed.

Possible improvements:
  • - Move the large code blocks to two separate macros, one for each function, to reduce the size of the main macro.
    - For dual boot only one switch is required. If B7 is zero go to one block, if not the other block. (The 'Yes' and 'No' branches of the same decision block)
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times

Re: Dual-boot

Post by Spanish_dude »

You have a lot of stuff connected to your PIC !

I just checked the code real quickly and I have something to propose.
Like kersing said, dual-boot implies you "reboot" the controller. From there you have two options IMO:
1) Have a variable in the EEPROM with which you can start one of the three programs.
2) Have a sort of a bootloader to chose one of the three programs.

The first one, I don't know how you would change the value in eeprom.
But the second one could be interesting.

You could have your microcontroller use your PC monitor to display which program you want to boot.
Have your microcontroller connect to your PC with USART or USB Serial (if it has it) and use a program like Hyperterminal or PuTTy to connect to the microcontrollers COM port and display text sent from your microcontroller.

Your PC could then display a message like :
PIC 18F252 Bootloader v0.0:
(Press corresponding number to boot a program)
1) Program 1
2) Program 2
3) Program 3
... Waiting user input ...
Once the user has chosen which program to boot, you can re-initialize the microcontroller by resetting the I/O pins to whatever it is you want (as long as it doesn't conflict with the USART/USB hardware).

Your bootloader is nothing more than a simple state machine, check the pseudo code:

Code: Select all

// main

IO_Init(); // initialise IO for USB
USBSerial_Init(); // initialise USB Serial
USBSerial_SendString("PIC 18F252 Bootloader v0.0:\n(Press corresponding number to boot a program)\n ...etc"); // send string throug USB Serial

// main loop
while (1)
{
    user_response = USB_waitForUserInput(); // loop in function while no char received

    switch(user_response)
    {
        case '1': // if user pressed 1
            bootProgram1(); // call program 1
            break;
        case '2': // if user pressed 2
            bootProgram2(); // call program 2
            break;
        case '3': // if user pressed 3
            bootProgram3(); // call program 3
            break;
        default: // if user sent anything else than 1, 2 or 3
            // error, received char not recognized
    }
}
The only way to choose a new boot is to reboot the microcontroller so the user can choose what program to run.
I think that's close enough to what a PC does :P.

jjw
Posts: 78
Joined: Sat Aug 25, 2012 5:35 am
Has thanked: 71 times
Been thanked: 9 times

Re: Dual-boot

Post by jjw »

Thanks for the help Kersin and Spanish_dude . Lot to think about for the next step.

Wbr,
jjw

jjw
Posts: 78
Joined: Sat Aug 25, 2012 5:35 am
Has thanked: 71 times
Been thanked: 9 times

Re: Dual-boot

Post by jjw »

Huge thanks to Martin who changed the flowchart more efficient and also more easily to modify! I have been testing it with my hardware and it worked very well. Still lot to test and do but approaching every day a bit….

jjw
Attachments
Dual_boot25082013_v2.fcf
(45.06 KiB) Downloaded 340 times

Post Reply