Shop OBEX P1 Docs P2 Docs Learn Events
Python P2 Loader - Page 2 — Parallax Forums

Python P2 Loader

2

Comments

  • ozpropdev wrote: »
    David Betz wrote: »
    ozpropdev wrote: »
    Try this one.
    This version loads the P2 eval board Ok.
    Thanks for the simple example of loading a file. Isn't there an ACK sent after the load completes though? How do I know it worked other than observing the program's behavior?

    In my own P2 code I send my own "ACK" back to my loader to prove load success.
    So the ROM loader itself doesn't send any sort of ACK? Should that be changed in the next version of the chip? It seems like the loaded program shouldn't have to complete the handshake.

  • RaymanRayman Posts: 14,646
    Seems like the ROM could do this...
  • RaymanRayman Posts: 14,646
    edited 2018-12-24 15:13
    I wonder if this loading scheme is really the best...
    Seems like you should tell the P2 how many bytes are coming at least... And then a checksum at the end would be the usual way, right?

    I don't really understand the base64 encode either... Doesn't seem to add any value to me... Ok, well I see that it can be used to detect bad data. Looks like the upper 2 bits of each byte have to be zero to be valid.

    But, seems this ship has sailed. I guess one could always add their own error checking to their code... On the other hand, errors using FTDI chip (with it's own error detection) are probably very remote...
  • David Betz wrote: »
    ozpropdev wrote: »
    David Betz wrote: »
    ozpropdev wrote: »
    Try this one.
    This version loads the P2 eval board Ok.
    Thanks for the simple example of loading a file. Isn't there an ACK sent after the load completes though? How do I know it worked other than observing the program's behavior?

    In my own P2 code I send my own "ACK" back to my loader to prove load success.
    So the ROM loader itself doesn't send any sort of ACK? Should that be changed in the next version of the chip? It seems like the loaded program shouldn't have to complete the handshake.
    I just read the documentation and the "~" character that the Python loader uses to end the program loading command bypasses checksum validation. You can also end the command with "?" which will result in a "." response if the load was success and the program started and "T" if the checksum failed. So it seems you can get a positive ACK. I withdraw my comment.
  • RaymanRayman Posts: 14,646
    edited 2018-12-24 18:07
    I'm glad to hear that other stuff is in there already!

    I forgot the boot process was described in the Google Docs file now...
  • jmgjmg Posts: 15,173
    ozpropdev wrote: »
    Try this one.
    This version loads the P2 eval board Ok.

    To augment this Python loader, here is minimal code to scan/list available COM ports on a PC
    # Minimal Python code to scan all Serial ports, and report Port info
    import serial.tools.list_ports
    
    portlist = serial.tools.list_ports.comports()  # List All ports can be useful to avoid conflicts
    for sp in portlist:
      if (sp.vid is not None) and (sp.pid is not None): 
         print(sp.device, sp.description, sp.manufacturer, sp.serial_number, hex(sp.vid), hex(sp.pid)) # Usually USB
      else:
         print (sp.device, sp.description, sp.manufacturer )  # Shorter list for motherboard ports.
        
    # Results on PC with one USB COM port connected :
    # COM1 Communications Port (COM1) (Standard port types)
    # COM3 Intel(R) Active Management Technology - SOL (COM3) Intel
    # COM19 USB Serial Port (COM19) FTDI P2EEI94A 0x403 0x6015
    # 
    
  • jmgjmg Posts: 15,173
    Given the higher current needs of P2, I was also looking around for a means to report the USB settings like
    # CONFIGURATION 1: 500 mA ==================================
    #  bMaxPower            :   0xfa (500 mA)   << 7 lines later
    

    but that is proving more elusive.
    I was hoping something in the COM port infos, could easily expand into the USB bMaxPower setting ?
  • Cluso99Cluso99 Posts: 18,069
    500mA is max for USB2.0
  • RaymanRayman Posts: 14,646
    edited 2018-12-25 11:26
    The new FTDI chips can detect when connected to a USB-IF charger device and can then draw 1.0 Amps...
  • Suggest using optparse for specifying the serial port and filename(s), rather than hardcoding.

    Is this Python2 or Python3?
  • RaymanRayman Posts: 14,646
    edited 2019-01-12 21:16
    I just tried on a Mac and got this error below... I thought python would be perfectly cross platform...
    Exit status: $? && exit 1
      File "py_p2loader.py", line 117
        print("Loading.......",end="")
                                  ^
    SyntaxError: invalid syntax
    
  • jmgjmg Posts: 15,173
    Rayman wrote: »
    I just tried on a Mac and got this error below... I thought python would be perfectly cross platform...


    Did you use Python 3.x ?

  • Rayman, you need Python 3
  • RaymanRayman Posts: 14,646
    ok, thanks! I'll try that.
  • RaymanRayman Posts: 14,646
    edited 2019-01-12 22:02
    Actually, it claims to be 3.7.2:
    This package will install Python 3.7.2 for macOS 10.9 or later for the following architecture(s): x86_64.
    
  • Just updated to Python 3.7.2 here on PC.

    File loaded was Invaders, works Ok.
    Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 22:20:52) [MSC v.1916 32 bit (Intel)] on win32
    Type "help", "copyright", "credits" or "license()" for more information.
    >>> 
     RESTART: C:\py_p2_loader\P2Eval_loader_1.1.py 
    HUBSET #1 Ok
    HUBSET #2 Ok
    Loading TXT ....complete
    >>> 
    
  • @Rayman ,
    Have you tried the latest version of the loader in this thread? From your filename and text output above, it looks like it could be the original version...wouldn't expect that aspect to matter, but worth a try...

    Cheers
  • RaymanRayman Posts: 14,646
    Ok maybe I was doing it wrong
    Wasn’t in interactive mode
  • Works for me in both interactive mode (using IDLE 3.7) and command line mode.
    Rayman wrote: »
    I just tried on a Mac and got this error below... I thought python would be perfectly cross platform...
    Exit status: $? && exit 1
      File "py_p2loader.py", line 117
        print("Loading.......",end="")
                                  ^
    SyntaxError: invalid syntax
    

    Maybe try end = "" with spaes?
  • jmgjmg Posts: 15,173
    ozpropdev wrote: »
    Works for me in both interactive mode (using IDLE 3.7) and command line mode.

    Maybe Rayman's case is finding an older Python in command line, but works fine from loaded 3.7.2 ?
    Perhaps Python loader should check/report the Python version it finds ?

  • Mark_TMark_T Posts: 1,981
    edited 2019-01-13 01:45
    Did you use python3 cmd, not python, you might have both python 2 and 3 installed?

    (Its easy to tell if you are in python3, because print requires parentheses in python 3
  • RaymanRayman Posts: 14,646
    edited 2019-01-13 01:46
    Does python 2 come installed on Mac ?
    I only installed one
  • Prob not, I have both and mainly use Python3, but occasionally I type "python" without thinking...
  • dgatelydgately Posts: 1,630
    edited 2019-01-13 04:58
    Rayman wrote: »
    Does python 2 come installed on Mac ?
    I only installed one
    A Python 2 version is installed, initially on macOS (Python 2.7.10 on macOS Mojave - 10.14.2).
    An install of Python 3 can coexist with Python 2. Python as a command will exec Python 2... Python3 as a command launches Python 3. This link may help:

    https://legacy.python.org/getit/mac/

    I was able to use the loader (P2Eval_loader_1.1.py) from avsa242's link in a post above. My Python3 is version: 3.6.5. In P2Eval_loader_1.1.py, I had to change 2 references to 'com5' to '/dev/cu.usbserial-P2EEI8V', which is what macOS names my P2 board (your's may differ).

    Python 2 gives the following error:
    File "P2Eval_loader_1.1.py", line 70
        print("Loading TXT ....",end="")
                                    ^
    SyntaxError: invalid syntax
    
  • RaymanRayman Posts: 14,646
    I think I am somehow invoking python 2.7 even though using python launcher...
    If I try running python3 from command line I get an error saying "No module named 'serial' ".
    Think I need to fix the path somehow...
  • RaymanRayman Posts: 14,646
    edited 2019-01-13 17:37
    Ok, I finally got it :). Thanks avsa242 for showing me the right file.

    Had to do "python3 -m pip install pyserial" to get serial module installed.
    Now, I can run from command line with "python3 P2Eval_loader_1.1.py"

    I really wish python2 wasn't on my system or that python3 would overwrite python2...
    But, I just have to remember to type "python3".

    Can finally load up the VGA example with a Mac.
  • RaymanRayman Posts: 14,646
    Note that changing the "port = 'com5'" at the top of the file has no effect.
    You have to go to the bottom and change sp.port. Mine is like this:
    sp.port = "/dev/tty.usbserial-P2EEJWO"
    
  • @ozpropdev could you upload your code to github so we can make pull request and improve it?
  • Rayman wrote: »
    I really wish python2 wasn't on my system or that python3 would overwrite python2...
    But, I just have to remember to type "python3".

    I've begrudgingly become a Python user. My life was worse before I discovered "virtualenv" to manage the different versions of Python (I have to use three versions to get my day work done) as well as the plethora of differing library needs.

    Although I'm primarily on either Linux or macOS, this tool apparently supports Windows, as shown here:

    http://timmyreilly.azurewebsites.net/python-pip-virtualenv-installation-on-windows/

    Good luck!
  • jmgjmg Posts: 15,173
    Google finds this
    https://stackoverflow.com/questions/9079036/how-do-i-detect-the-python-version-at-runtime
    Which has various version tests.
    I suspect the serial module will be Python version specific, making a universal version impractical ?
    However, should be easy to add a version test, of one of the many forms...

    The hex form allows finer version testing, in one line, if early 3.x are found to have issues.
    import sys
    print('Python hexversion %s is in use.' % hex(sys.hexversion))
    if sys.hexversion < 0x3000000:
        print('Python Version 3.x required for py_p2loader')
    
Sign In or Register to comment.