Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 07:49 19 May 2024 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 : MMBasic on the Raspberry Pi Pico - proposed functionality

     Page 3 of 6    
Author Message
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2294
Posted: 04:18pm 29 May 2021
Copy link to clipboard 
Print this post

  matherp said  
  Quote  after FLASH SAVE n resets the pico, the USB connection is dropped. this will drive people crazy!


And will always be thus, because the firmware runs from flash. In order to write to flash interrupts have to be disabled which, of course, kills the USB


after 3ms it kills the USB. if you get interrupts back up and running before then, the connection should remain alive.

what if you:
- disable interrupts,
- write a single 256 byte block of flash (or 2 blocks, or 3),
- re-enable interrupts,
- wait for a 1ms USB interrupt to happen and be handled,
- loop back to write the next block.

this may well be a tad slower than a single write, but then we're not doing this while running our basic program. there would be some tinkering required to find out the optimal number of blocks to write each time round, and the number may be dependant on the CPU clock speed.

i'm presuming this is what MicroPython does, as it looks like it is able to write to the flash without the USB connection being dropped continuously. i shall ask a question on the pico forums and see what people say.


cheers,
rob   :-)
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8605
Posted: 04:30pm 29 May 2021
Copy link to clipboard 
Print this post

  Quote  i shall ask a question on the pico forums and see what people say.


Good luck - I haven't had a useful answer on anything I've asked so far. Flash block size is 4K

UPDATE

Just checked the micropython code and they are just ignoring the requirement to disable interrupts when writing flash. I can do the same but it is contrary to the SDK

  Quote  4.1.8. hardware_flash
Low level flash programming and erase API.

Note these functions are unsafe if you have two cores concurrently executing from flash. In this case you must performv your own synchronisation to make sure no XIP accesses take place during flash programming.

Likewise  they  are  unsafe  if  you  have  interrupt  handlers  or  an  interrupt  vector  table  in  flash,  so  you  must  disable interrupts before calling in this case

Edited 2021-05-30 03:21 by matherp
 
hitsware2

Guru

Joined: 03/08/2019
Location: United States
Posts: 707
Posted: 06:05pm 29 May 2021
Copy link to clipboard 
Print this post

>> I'm presuming this is what MicroPython does,
>> as it looks like it is able to write to the
>> flash without the USB connection being dropped
>> continuously.

Based on the ability to write to REPL while running ?
my site
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5771
Posted: 06:27pm 29 May 2021
Copy link to clipboard 
Print this post

It's certainly not good practice to mess with an interrupt vector table without first disabling any interrupts that might use it. Anything could happen. :(
Mick

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

Guru

Joined: 03/08/2019
Location: United States
Posts: 707
Posted: 06:36pm 29 May 2021
Copy link to clipboard 
Print this post

I get the editor screen ,
but when I try to RUN ....

my site
 
Plasmamac

Guru

Joined: 31/01/2019
Location: Germany
Posts: 504
Posted: 07:06pm 29 May 2021
Copy link to clipboard 
Print this post

Works here
Plasma
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5771
Posted: 07:19pm 29 May 2021
Copy link to clipboard 
Print this post

I'm not getting that. Have you tried using Tera Term to see if you have the same problem?
Edited 2021-05-30 05:19 by Mixtel90
Mick

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

Joined: 05/03/2018
Location: Netherlands
Posts: 3589
Posted: 07:30pm 29 May 2021
Copy link to clipboard 
Print this post

Works here too. Using Putty with the same settings as used with the F4 an MX170.

Putting the firmware onto the pi pico is by far the simplest i have seen.
Gonna spend some more time on it later, happy now that it works.

Thanks Peter...

Oh, btw, can the usb issue simply be solved by copying the interrupt table and handlers in ram.?

.
Edited 2021-05-30 05:34 by Volhout
PicomiteVGA PETSCII ROBOTS
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2294
Posted: 07:43pm 29 May 2021
Copy link to clipboard 
Print this post

  hitsware2 said  I get the editor screen ,
but when I try to RUN ....
<IMAGE>


yep, i got that with minicom, but not with GFXterm64. looks like you may need to use the alternative control codes from the micromite manual, pg32:

f1:         ctrl-Q
f2:         ctrl-W
f3:         ctrl-R
f4:         ctrl-T
f5:         ctrl-Y
shift f3:   ctrl-G


it seems to be a shortfalling of minicom, and no doubt some other linux terminals.


cheers,
rob   :-)
 
Plasmamac

Guru

Joined: 31/01/2019
Location: Germany
Posts: 504
Posted: 07:48pm 29 May 2021
Copy link to clipboard 
Print this post

I wonder about the gpio . Maybe some new tricks because the pico gpio magic ?

Win10/Tera Term
Edited 2021-05-30 05:49 by Plasmamac
Plasma
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2294
Posted: 08:21pm 29 May 2021
Copy link to clipboard 
Print this post

  matherp said  
  Quote  i shall ask a question on the pico forums and see what people say.


Good luck - I haven't had a useful answer on anything I've asked so far. Flash block size is 4K


replies here:
https://www.raspberrypi.org/forums/viewtopic.php?f=145&t=312883

suggestion seems to be simply do one block (4k) at a time, with each call to erase and write bracketed with interrupt_disable and interrupt_enable, and a few NOPs sprinkled in between to ensure any pending interrupt is handled:

for i=1 to n
  disable_ints
  erase_block
  enable_ints
  nop
  disable_ints
  write_block
  enable_ints
next i


even if it took 2ms to erase or write a 4k block, 100k could be handled in 100ms or so, which seems perfectly acceptable. i did read somewhere that one should avoid writing to the (USB) console while doing this, so make sure the console is flushed before starting.


cheers,
rob   :-)
Edited 2021-05-30 06:21 by robert.rozee
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3027
Posted: 08:43pm 29 May 2021
Copy link to clipboard 
Print this post

These commands are listed twice by LIST COMMANDS:
Else If        Else If
End If         End If
Exit Do        Exit Do
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3589
Posted: 08:52pm 29 May 2021
Copy link to clipboard 
Print this post

Tried to enter a program with autosave. Not succesfull.
Use Putty (an Putty cannot generate an EOL delay, so it works imaginary 38400 baud speed).

Example:
' A pay thy, Ci0sss
r a rt X
I)y Ns223,3 (Ftit(1w(wo =r cv( g
r=1n )nsad
Local integer i,j

xstart = 50
Print gfx$ "C" 0,0,sw,sh
Print gfx$ "I" 0,0,255,4
For i = 1 To 40
  For j = 1 To 40
    If w(i,j) And 1 Then
      Print gfx$ "A" xs+10*i,ys+10*j,xs+6+10*i,ys+6+10*j,0,0
    EndIf
  Next j
Next i

End Sub

End


The last 16 lines or so are exact duplicate, but the beginning of the program is corrupted. Maybe something to do with buffer size.

This is original program:

' A short test program to play the Game of Life, invented
' by John Conway. Unfortunately, Covid19 took John's life
' on April 11, 2020. His legacy lives on in the coutless
' people inspired by his invention of the cellular automaton
' called the Game of Life and his other works.
'
' Written by vegipete, April 22, 2020 for use with GFXTerm.

Option DEFAULT INTEGER
Dim INTEGER i,j,count
Dim INTEGER xs,ys
Dim INTEGER sw,sh

Dim string GFX$
Dim float w(41,41)

GFX$ = Chr$(16)

Print GFX$ "?"  ' request size of GFXTerm Window
Input sw,sh ' grab dimensions - width and height

Print Chr$(27)+"[2J";   ' esc sequence to erase the text screen
Print "Thank you John Conway. Rest in Peace."

xs = 100: ys = 20

' clear the world to start
For i = 0 To 41
For j = 0 To 41
  w(i,j) = 0
Next j
Next i

' seed the world
w(19,31) = 3 : w(20,31) = 3 : w(21,31) = 3
w(19,32) = 3 : w(21,32) = 3
w(19,33) = 3 : w(21,33) = 3
w(20,34) = 3
w(17,35) = 3 : w(19,35) = 3 : w(20,35) = 3: w(21,35) = 3
w(18,36) = 3 : w(20,36) = 3 : w(22,36) = 3
w(20,37) = 3 : w(23,37) = 3
w(19,38) = 3 : w(21,38) = 3
w(19,39) = 3 : w(21,39) = 3

showWorld
Pause 2000

For i = 0 To 1000
ConwayLife
showWorld
Next i

End

' Calculate a new generation of life, using the classic rules
Sub ConwayLife
Local integer i,j,count

' wrap the corners
w(0,0) = w(40,40) : w(41,41) = w(1,1)
w(0,41) = w(40,1) : w(41,0) = w(1,40)

' wrap the edges
For i = 1 To 40
  w(0,i) = w(40,i) ' left
  w(41,i) = w(1,i) ' right
  w(i,0) = w(i,40) ' top
  w(i,41) = w(i,1) ' bottom
Next i

' move most recent generation to previous and clear new geneartion
For i = 1 To 40
  For j = 1 To 40
    w(i,j) = w(i,j) << 1
  Next j
Next i

' calculate new generation
For i = 1 To 40
  For j = 1 To 40
    count = Neighbours(i,j)

    If (w(i,j) And 2) Then  ' was cell alive last generation?
      ' yes so test if it stays alive
      If (count = 2) Or (count = 3) Then
        w(i,j) = w(i,j) + 1 ' cell remains alive for new generation
      EndIf
    Else
      ' no so test if it gets born
      If count = 3 Then
        w(i,j) = w(i,j) + 1 ' cell becomes alive for new generation
      EndIf
    EndIf

  Next j
Next i


End Sub

' return number of neighbours around given point
Function Neighbours(x,y)
Local count

count = 0

If (w(x-1,y-1) And 2) Then count = count + 1
If (w(x+0,y-1) And 2) Then count = count + 1
If (w(x+1,y-1) And 2) Then count = count + 1
If (w(x-1,y+0) And 2) Then count = count + 1
If (w(x+1,y+0) And 2) Then count = count + 1
If (w(x-1,y+1) And 2) Then count = count + 1
If (w(x+0,y+1) And 2) Then count = count + 1
If (w(x+1,y+1) And 2) Then count = count + 1

Neighbours = count

End Function

' display the current world
Sub showWorld
Local integer i,j

xstart = 50
Print gfx$ "C" 0,0,sw,sh
Print gfx$ "I" 0,0,255,4
For i = 1 To 40
  For j = 1 To 40
    If w(i,j) And 1 Then
      Print gfx$ "A" xs+10*i,ys+10*j,xs+6+10*i,ys+6+10*j,0,0
    EndIf
  Next j
Next i

End Sub

End

PicomiteVGA PETSCII ROBOTS
 
Plasmamac

Guru

Joined: 31/01/2019
Location: Germany
Posts: 504
Posted: 08:53pm 29 May 2021
Copy link to clipboard 
Print this post

just curiousity :




multicore_hang.zip

rpi forum
Plasma
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8605
Posted: 10:29pm 29 May 2021
Copy link to clipboard 
Print this post

  Quote  Use Putty (an Putty cannot generate an EOL delay, so it works imaginary 38400 baud speed).


How about don't use putty - use teraterm

  Quote  replies here:
https://www.raspberrypi.org/forums/viewtopic.php?f=145&t=312883

"
Doesn't work - tried it already "Good luck - I haven't had a useful answer on anything I've asked so far."
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3027
Posted: 10:35pm 29 May 2021
Copy link to clipboard 
Print this post

  Volhout said  Tried to enter a program with autosave. Not succesfull.


Your program works for me with AUTOSAVE. Termination is CMM2-style with CTRL-C instead of CTRL-Z (and you're not told that anything is saved). F4 put me in the editor with your Game Of Life program, and F2 ran it (though I didn't know what input it should have had). I got a bunch of numbers output.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
hitsware2

Guru

Joined: 03/08/2019
Location: United States
Posts: 707
Posted: 11:33pm 29 May 2021
Copy link to clipboard 
Print this post


  robert.rozee said  
yep, i got that with minicom, but not with GFXterm64. looks like you may need to use the alternative control codes from the micromite manual, pg32:

f1:         ctrl-Q
f2:         ctrl-W
f3:         ctrl-R
f4:         ctrl-T
f5:         ctrl-Y
shift f3:   ctrl-G

it seems to be a shortfalling of minicom, and no doubt some other linux terminals.
rob   :-)

Thank You   .... ctrl-W runs it ....
Strange ( to me ) that You would blame Linux terminals , rather than the code ?
Edited 2021-05-30 09:34 by hitsware2
my site
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5923
Posted: 03:29am 30 May 2021
Copy link to clipboard 
Print this post

I seem to have a problem communicating using MMEdit.
TeraTerm works OK but with MMEdit, the data gets sent but no sign of any return data until I disconnect and reconnect. Then the data flows in response to the earlier commands. This confirms that the commands are getting from MMEdit to the pico.
Any new commands and it is back to no data.

eg:
Open up a Chat window
Enter "List commands" - no response.
Close the chat window and wait for the connection to clear.
Open the chat window again and you get the list of commands.
After that - no response...

I am trolling through some Wireshark captures trying to see what is different between MMEdit and TeraTerm.

Nothing obvious yet.

It is as if there is flow control at play.


Jim
VK7JH
MMedit   MMBasic Help
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2294
Posted: 05:02am 30 May 2021
Copy link to clipboard 
Print this post

  hitsware2 said  
  robert.rozee said  yep, i got that with minicom, but not with GFXterm64. looks like you may need to use the alternative control codes from the micromite manual, pg32:

f1:         ctrl-Q
f2:         ctrl-W
f3:         ctrl-R
f4:         ctrl-T
f5:         ctrl-Y
shift f3:   ctrl-G

it seems to be a shortfalling of minicom, and no doubt some other linux terminals.
rob   :-)

Thank You   .... ctrl-W runs it ....
Strange ( to me ) that You would blame Linux terminals , rather than the code ?



it is just that minicom is strictly emulating a VT102 terminal, and as such does not have function keys that the mmbasic editor fully understands. you'll also find that while <pg up> and <pg down> keys work correctly with the mmbasic editor, <home> and <end> do not.

colour and function keys are - out of necessity - a bit of a mish-mash. to get a full set of function keys we need to use VT200 key mapping, while colour requites VT300 escape sequences. most terminal emulators recognize a portion of VT100 sequences (not all), along with a few VT102 specific sequences that are particularly useful.

most folks just lump the above together under 'VT100 emulation', which kind of makes sense since there are probably only a handful of real/physical VT1xx series terminals still in existence.

unfortunately, programs like minicom have a long history running back decades; as such, no one has put much effort into adding the necessary extensions. TeraTerm (windows only) emulates an enormous set of different terminals, all at the same time. GFXterm (win32, linux 32 and 64, RPi) takes a different approach, only emulating only those sequences that the micromites make use of (plus one or two others!).


cheers,
rob   :-)
Edited 2021-05-30 15:03 by robert.rozee
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3589
Posted: 05:33am 30 May 2021
Copy link to clipboard 
Print this post

@matherp:

I am not sure Teraterm is running in linux (under Wine maybe ?). I will look at alternatives. I think the strength of Putty is that it can live "besides" other connections to the same port.

i.e. you can make a profile for a micromite connected to /dev/ttyACM0, including logging, in putty. Run putty with that profile. And then you can have a second application sending data to /dev/ttyACM0. The second application will not find the port blocked, but can simply use it. Meanwhile Putty handles all the hardware handshaking, buffering, logging.

I use it a daily. But for the pi-pico-mite I can look for different. Was planning to try GFXterm anyway (hence the game-of-life application).

Volhout

P.S. there are some nice PIO sequencer examples, like the neopixel support...


edit: GFXterm64 works fine with autosave, sending is quite a bit slower than (not working) Putty..which was instantly.
Edited 2021-05-30 15:55 by Volhout
PicomiteVGA PETSCII ROBOTS
 
     Page 3 of 6    
Print this page
© JAQ Software 2024