Infineon / micropython

MicroPython - a lean and efficient Python implementation for microcontrollers and constrained systems
https://micropython.org
Other
3 stars 3 forks source link

After saving a file into PSoC6 board the application can not be stopped. #60

Closed Antonia-place closed 1 year ago

Antonia-place commented 1 year ago

Hi, I create a very simple program, to blink the onboard led from PSoC6 board for every 1 second; then I saved this file into PSoC (from Thonny), then I run the application. The application run ok, but now, I can not stopp the app in order to update and/or modify. I saved the file with this name: main.py, as for RPI Pico. This is the program that I saved:

from machine import Pin
import time
from utime import sleep

#p0 = Pin('P13_7', Pin.OUT, Pin.PULL_DOWN, value=Pin.STATE_LOW)

p0 = Pin('P13_7')                    # create pin object for pin P13_7.
p0.init(Pin.OUT) #, Pin.PULL_DOWN)      # set pin as output and enable pull-down resistor.
p0.low()                             # set value low.

while True:

#    p0.toggle()
    p0.low()
    print("test_1")
    sleep(1)      # sleep for 1 second

    p0.high()
    print("test_2")
    sleep(1)      # sleep for 1 second

I attached some video, tt see the actual issue.

Then, I tryed the following actions, in order to delete the saved file:

In this moment, I can not access MicroPython from Thonny or other serial tools and the saved app run and can not be stopped.

Do you have any solution for this situation? In this latest verssion, MicroPython V0.3.0, files with code can not be saved into PSoC6?

Moreover, before save the file into PSoC, when I write the above piece of code, the Stop button from Tonny also not stop the running program; the only way was to press on reset button on the board...

The video files:

https://github.com/Infineon/micropython/assets/10450789/7448ffa3-3bcd-44a9-8935-54b5ed1ccb88

https://github.com/Infineon/micropython/assets/10450789/4aeb0854-6695-4baf-aaa5-0dc2bd70a169

https://github.com/Infineon/micropython/assets/10450789/62be273d-8c76-490d-b96e-9ab587eaa152

Thank you, Mihai

Antonia-place commented 1 year ago

It is any posibility to stop the running script from PSoC6 in order to update it? STOP button from Thonny dosen't any efect... Do you know how to erase entire PSoC6 memory, in order to delete the script that run after PSoC6 board is powered up?

jaenrig-ifx commented 1 year ago

Hi @Antonia-place,

If you add a script as main.py to the device storage, this will be the program running every power on reset. Remove that script from the device storage. Usually in Thonny, you should in the section MicroPython devices, the files stored: image

Beside the IDEs, the tool mpremote allows you inspect the device storage file system, list the files, remove them, etc.

Flashing again the firmware wil not delete the flash device storage. And there should be no need to re-flash the firmware every time.

Also keep in mind the different operating modes: REPL terminal and stand-alone (when you save a main.py application in the device): https://ifx-micropython.readthedocs.io/en/latest/psoc6/mpy-usage.html

Regarding the run, stop buttons, keep in mind that such start, stop debugging mode is not (yet? or for MPY?) supported. We will check the IDE integration command buttons, and also compare it with other ports (rpi, esp32, etc.) in the future. But IDE integration is second prio, as currently our focus is on enabling core peripherals and functionalities (SPI, I2C, etc.), as we are working towards 1.0 version, with a proper features coverage for PSoC6.

I hope that helps. Thanks for helping us improve MPY 🛰️

Antonia-place commented 1 year ago

Hi, The board start to run the already saved, after power is applied and no file structure is present in Thonny, as you can see in the above picture; moreover, after board Hard reset, the console output in th the picture: Thonny console after Hard reset

Now, how can I use mpremote if REPL is not accessible from the board? Do you have an tutorial for this mpremote? I tryed from win cmd, I opened python from there and then I typed the following commands: pip install --user mpremote python import mpremote mpremote then? This is the win cmd output: win cmd output What should I do next?

PS: mpremote should work even repl is not responding (from Thonny, Arduino LAB or other serial console)? Could be this board bricked too and useless for microPython, as previus one?

Thank you, Mihai

jaenrig-ifx commented 1 year ago

I don´t think it is the board... You can see here the available command for mpremote: https://docs.micropython.org/en/latest/reference/mpremote.html

Antonia-place commented 1 year ago

Hello, I succedded to install and configure mpremote but nothing is changed. The application saved run after power is applied, no metter what, and I cannot comunicate with PSoC6 board from mpremote. Here is the console output and log: mpremote output mpremote console log.txt

It is any solution to recover this board? Because i don't want to purchase boards everytime when I save a program into PSoC6 memory!!! It is any chanse to save my board? Where is located this file? How can I erase the entire MCU memory (something like "format")? Saving the program into PSoC6 flash is not yet working properly?

jaenrig-ifx commented 1 year ago

Hi @Antonia-place,

I can reproduce now the issue, and we are working on the solution. Thanks for you patience 🕐 and checking out these first beta versions. It is of real help 👍
This seems to be also present in some other ports (esp32).

Point one, let us find out how to complete erase the device memory. And secondly, we will work on enabling the interrupt mechanism to break the while True in a 'main.py'.

I come to you asap. Don´t worry about your board, it is not damaged :) You can still flash any other application (with ModusToolbox).

Regards, Juan

Antonia-place commented 1 year ago

Hi,

It is super that you reprodused this issue!!!! I am waiting for the new release, in order to use MicroPython on PSoC6 board. I wish you good luck to find a solution for this.

Thank you for support, Mihai

jaenrig-ifx commented 1 year ago

Hi @Antonia-place,

We are adding another function to the mpy-psoc6 script to erase the device memory.

You can download the work latest version (for windows):

curl.exe -s -L https://raw.githubusercontent.com/infineon/micropython/ext-flash-erase/tools/psoc6/mpy-psoc6.cmd > mpy-psoc6.cmd

It will be merged soon into the main branch of the project when further validated by some colleagues. But since you are already waiting for a while, you can maybe give it try. It works on my end.

The new command is:

mpy-psoc6.cmd device-erase

If you have a serial terminal open (i.e. Thonny) you should see a program erasing the memory (based on the QSPI_XIP ModusToolbox example):

*************** PSoC 6 MCU: External Flash Access in XIP Mode ***************

1. Total Flash Size: 67108864 bytes.

1. Erasing 262144 bytes of memory.

2. Reading after Erase. Ensure that the data read is 0xFF for each byte.

Received Data (64 bytes):
-------------------------
0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 
0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 
0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 
0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 

================================================================================

SUCCESS: Data successfully accessed in XIP mode!

================================================================================

This only recover the device memory, but using a blocking loop in the main.py will get again to a non-accessible device. This will be fixed in the near future.

Meanwhile, my recommendation is that you store any application in the device memory with another name other than main.py, for example my_app.py. And then, from the terminal, you can run it with

>>> import builtins
>>> builtins.execfile("/my_app.py")
test_1
test_2

test_1
test_2
test_1
test_2

Now the device will still be inaccessible from the terminal, but if you hard reset it with the reset button, you will recover your device. Then, only if you want to permanently deploy the application in the device, and no further develop, debug, etc. You can name it main.py and leave the device running the application forever.

Thanks for your patience! Regards, Juan A

Antonia-place commented 1 year ago

The erase command is wrong: should be: mpy-psoc6.cmd device-erase I add here the the log from console and Thonny output: Output OK from Thonny for erase-device Log from erase-device.txt

Then I flashed again the MicroPython and this is the output: Thonny, after erase the device memory and flash again microPython

Then, I saved a sample code into the PSoC6 device memory, and after board hard reset, I can access thye saved file for modifying:

Thonny after saving a cod into PSoC6

PS: I see that the name of device (PSoC6) in Thonny is the same with RPI Pico...

It is working for the moment.

Thank you for support!

jaenrig-ifx commented 1 year ago

Yes, there was a typo. But glad that it works :)

In Thonny use the device generic. We haven´t yet worked out the integration with the IDEs. Right now, I am not sure how the type/vendor of the device in Thonny is resolved.

jaenrig-ifx commented 1 year ago

Hi @Antonia-place,

The memory erase recovery is now included in the new release v0.4.0 with some other features and fixes.

We will address the issue with the device inaccessibility when adding main.py blocking loops in future releases. For now I close this topic.

Antonia-place commented 1 year ago

Hello @jaenrig-ifx , I want to know that with this hex device-erase_CY8CPROTO-062-4343W.hex I succedded to recover the first PSoC6 board (after I erased the flash memory), with which I opened the ticket https://github.com/Infineon/micropython/issues/55 Now, I have two boards working with MicroPython v0.4.0. and I am very happy!

Thank you for support, Mihai

jaenrig-ifx commented 1 year ago

Hi @Antonia-place,

Glad to hear 😃 As we proceed, we will unfold more of the features of the PSoC6 in/and MicroPython, and refine certain undesired behaviors. Thanks for contributing to the task 👍