Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 16:37 21 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Playing catchup on the PicoMite.

Author Message
Bowden_P
Senior Member

Joined: 20/03/2019
Location: United Kingdom
Posts: 162
Posted: 11:12pm 14 Oct 2022
Copy link to clipboard 
Print this post

Hi everyone,
I'm playing catchup on the PicoMite, so rea23's topic on "Flash Memory on Pi Pico" is particularly interesting w.r.t program space for oversize programs, i.e code >124KB.
( http://www.thebackshed.com/forum/ViewTopic.php?FID=16&TID=15240 )

Please could you clarify for me :-

1. Does a "FLASH n" slot capacity also match the base program capacity of 124KB ?

2. If you switch to another section of an oversize program using the "FLASH CHAIN n" command, how do you return to your base program code, and where would that return be exactly ?

3. Can you load the base program and some "FLASH n" code sections in one go, or does the load have to be done separately for each section?

With thanks, Paul.
Nothing so constant as change.
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3481
Posted: 12:39am 15 Oct 2022
Copy link to clipboard 
Print this post

You load each flash N separately.

Variables are preserved between FLASH RUN instances, so one program which is going to run another can set a variable and the other program must at its beginning start executing the code section indicated by the variable.

Don't know about your memory question.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4147
Posted: 07:22am 15 Oct 2022
Copy link to clipboard 
Print this post

FLASH ...

with RUN - clears variables

with CHAIN - keeps them

I don't think they match in the way you asked but does that matter? (I suspect not.)

CHAIN doesn't return, it's a bit like a jump.  If you want, you could sort of synthesise a return by using CHAIN to the original code (but it would be a jump, really, not a return).

John
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 8304
Posted: 08:22am 15 Oct 2022
Copy link to clipboard 
Print this post

CHAIN isn't a return. It's a jump but retains the variables as already described. When you CHAIN into a program it runs from the first line, no matter where the CHAIN command was that called it.

e.g. program A runs and at line 20 it has a CHAIN command to run program B. Program B then runs from line 1. At line 15 it has a CHAIN command to run program A, whith then runs from line 1.

The trick is to use a variable to tell the CHAINed program where to run from and test that variable at the start. So, in the above example, if program A begins with something like
IF N=1 THEN
do this
ELSE IF N=2
do this
END IF
then you can chain the program using
N=2
FLASH CHAIN 2
and on return control will be passed to something other than N=0, which would be the default for a first run. You can also CHAIN a different program using
N=1
FLASH CHAIN 3
for example.

Each flash slot can hold a full user program. It can do this because it is stored in tokenized form, not ASCII code, so is appreciably smaller in memory usage. Because the programs are already tokenized (which is done by the editor) you can flip between them pretty quickly!

No doubt someone will correct me on the following if I'm wrong:
I think a FLASH CHAINed program is actually run from flash memory and doesn't overwrite RAM memory or the variables area (as the variables area isn't stored in flash anyway). So it's not like the old paging systems, it's a case of changing control to the new program and back again.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 10:25am 15 Oct 2022
Copy link to clipboard 
Print this post

Great info, many thanks. Read about it but never tested it and of course this thread appears at a time when I don't have a PM with me, so:

Can you give an idea of just how quickly a CHAIN happens? Like, is there a perceptible delay?

Thanks again  


Craig
 
Bowden_P
Senior Member

Joined: 20/03/2019
Location: United Kingdom
Posts: 162
Posted: 12:00pm 15 Oct 2022
Copy link to clipboard 
Print this post

Many thanks Gurus,
Is it correct to assume that the FLASH 1 slot is defaulted to the base program section of the flash memory ? ( I'm guessing it is.)
This gives 7 x 124KB of program space = 868KB !


So a "FLASH CHAIN 1" while running the base program would effectively restart the code from line 1, without clearing variables ?

Tinine's question on timing is also interesting to me.

With best regards, Paul.
Nothing so constant as change.
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4147
Posted: 12:02pm 15 Oct 2022
Copy link to clipboard 
Print this post

The "base program"? May well be what's in flash slot 1...

As to how long... time it or read the code?

John
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10628
Posted: 12:31pm 15 Oct 2022
Copy link to clipboard 
Print this post

  Quote  Is it correct to assume that the FLASH 1 slot is defaulted to the base program section of the flash memory ?

No: the "base" program is in an additional hidden slot. To do as suggested above you ignore the "base" program. Use FLASH RUN n to start the main program and then you can chain to and from it.
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 8304
Posted: 01:13pm 15 Oct 2022
Copy link to clipboard 
Print this post

CHAINing is very fast. You are just transferring control from the current program to the CHAINed one. This only affects the program space as no variables are moved/copied.

The flash slots are just slots - there is nothing special about any of them.

The only problem with flash slots is that, because they only store the tokenized program space, they can't be used to store data files. If you want to do that you need a SD card.

When matherp had just implemented CHAIN I wrote some little programs that just ran through the flash slots, each chaining to the next one in the loop. I've not run it for a while. It might be faster now. :)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Bowden_P
Senior Member

Joined: 20/03/2019
Location: United Kingdom
Posts: 162
Posted: 01:37pm 15 Oct 2022
Copy link to clipboard 
Print this post

Thanks again Gurus,
So, how do you return to the "hidden" base program after a hop to a CHAIN'ed slot ? ( Or is that not possible ?)

With best regards, Paul.
Nothing so constant as change.
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4147
Posted: 02:43pm 15 Oct 2022
Copy link to clipboard 
Print this post

It's well hidden - I can't even find the phrase "base program" in the manual!

John
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 8304
Posted: 03:06pm 15 Oct 2022
Copy link to clipboard 
Print this post

I think I explained how to get back...  :)
You use FLASH CHAIN n again - think of FLASH CHAIN as a jump instruction, not a call or gosub. There is no mechanism built in to give you a return point like you would have with gosub or sub though, so you have to create one if you need it.

"Base program" is a sort of unofficial name, I think. :) It's the program that will open in the editor if you press F4. It's in a "hidden" flash slot and, during editing, in RAM. The hidden flash slot is updated whenever you press F1 to save or F2 to run the program. It is also copied into RAM automatically for editing when you power up (the Pico doesn't have battery-backed RAM). (I think I've got all this right... :) ).
Edited 2022-10-16 01:07 by Mixtel90
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Bowden_P
Senior Member

Joined: 20/03/2019
Location: United Kingdom
Posts: 162
Posted: 03:35pm 15 Oct 2022
Copy link to clipboard 
Print this post

Hi JohnS, Mixtel90
I'm sorry to have introduced the phrase "base program" - indeed not in the PicoMite manual. I am using it to describe where program code is stored if there were no CHAIN instruction. You have it Mixtel90 - the program area that will open in the editor if you press F4.

It appears that if this area is CHAIN'ed out of  - you can't get back, unless you can use "FLASH CHAIN 0", but that isn't in the manual either !

Seems you can either opt for using a "CHAIN" structured program only, or just this "base program" area of flash, but not both - is that correct ?

I guess you could put your variable declarations and setup code etc. in the F4 editable area, then hop into the CHAIN areas, but then never return afterwards.

With best regards, Paul.
Nothing so constant as change.
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4147
Posted: 03:42pm 15 Oct 2022
Copy link to clipboard 
Print this post

Borrowing the terminology, I think the current running program is in effect the base program, so if you CHAIN the new one becomes the base program.

You can only go back by another CHAIN - a rather limited meaning of "back".

However, variables keep their values so you can influence what each CHAINed chunk of code does.

John
Edited 2022-10-16 01:43 by JohnS
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3481
Posted: 04:31pm 15 Oct 2022
Copy link to clipboard 
Print this post

Sorry to have suggested "FLASH RUN" rather than "FLASH CHAIN".

Here's a simple example:

PicoMite MMBasic Version 5.07.05RC1
Copyright 2011-2022 Geoff Graham
Copyright 2016-2022 Peter Mather

> flash list
Slot 1 in use: "' flash slot 1"
Slot 2 in use: "' flash slot 2"
Slot 3 available
Slot 4 available
Slot 5 available
Slot 6 available
Slot 7 available
> flash list 1
' flash slot 1
Option default integer
Print "Pass=";pass
If pass>1 Then End
Flash chain 2
> flash list 2
' flash slot 2
Inc pass
Print "In flash slot 2, Pass=";pass
Flash chain 1
> flash run 1
Pass= 0
In flash slot 2, Pass= 1
Pass= 1
In flash slot 2, Pass= 2
Pass= 2
>

PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 8304
Posted: 06:49pm 15 Oct 2022
Copy link to clipboard 
Print this post

There isn't really a "base program" as such, it's just the current one. That's why it isn't in the manual. There's no need to think about a "chain" or "base" mode because they are one and the same. If you don't use FLASH CHAIN n then it won't happen. :)

When you FLASH CHAIN n control of the current program is released and transferred to the program in flash slot n, that's all. Now you are in a situation where the current program is a copy of the one in flash slot n.

Normally you would run with one main program that handles the other parts by CHAINing them. You would save this main program to one of the flash slots as that way another program could find it's way back - you'd probably also save all the flash slots containing the parts of your program to SD card for security. :)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Bowden_P
Senior Member

Joined: 20/03/2019
Location: United Kingdom
Posts: 162
Posted: 03:36pm 16 Oct 2022
Copy link to clipboard 
Print this post

Hi Gurus,
Thanks Lizby for your demo code - makes things clear in my mind.

Mixtel90 also confirms my assumptions earlier :-

  Quote  Seems you can either opt for using a "CHAIN" structured program only, or just this "base program" area of flash, but not both - is that correct ?

I guess you could put your variable declarations and setup code etc. in the F4 editable area, then hop into the CHAIN areas, but then never return afterwards.


If your application was partitionable into discrete functions - as perhaps having a top menu leading to several sub-menu areas - using a CHAIN structure could be a good idea.

With thanks, Paul.
Nothing so constant as change.
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025