Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ext flash erase #61

Merged
merged 6 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ports_psoc6.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
run: |
cd tools/psoc6
cp ../../mpy-psoc6_${{ matrix.board }}_${{ needs.server-build.outputs.commit_sha }}/firmware.hex .
source mpy-psoc6.sh && openocd_download_install && mpy_firmware_deploy ${{ matrix.board }} firmware.hex
source mpy-psoc6.sh && openocd_download_install && openocd_board_conf_download ${{ matrix.board }} && mpy_firmware_deploy ${{ matrix.board }} firmware.hex
cd ../..
- name: Run tests
run: cd tests && ./run-tests.py --target psoc6 --device /dev/ttyACM0 -d psoc6
Expand Down
25 changes: 25 additions & 0 deletions docs/psoc6/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,31 @@ The board needs to be specified, and the path and name of the ``.hex`` file:
mpy-psoc6.cmd firmware-deploy CY8CPROTO-062-4343W pathtodir/mpy-psoc6_CY8CPROTO-062-4343W.hex
Erasing the device (external) file system
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Some PSoC6™ boards include an external flash memory which is used by the MicroPython file system. This memory will not be erased when
reprogramming or erasing MicroPython firmware via ``device-setup`` or ``firmware-deploy``.
Use the ``device-erase`` command to erase of the external memory of your PSoC6™ device:

.. tabs::

.. group-tab:: Linux

.. code-block:: bash
./mpy-psoc6.sh device-erase
.. group-tab:: Windows

.. code-block:: bash
mpy-psoc6.cmd device-erase
.. warning::

This command flashes the PSoC6™ controller with a custom program to delete the external memory. Thus, MicroPython will be removed from the
microcontroller. Use any of the script commands described above to reinstall MicroPython.

Getting the firmware
^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion ports/psoc6/boards/CY8CPROTO-062-4343W/makefile_mtb.mk
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ mpy_program: $(MPY_MAIN_BUILD_DIR)/firmware.hex
@:
$(info )
$(info Programming using openocd ...)
$(OPENOCD_HOME)/bin/openocd -s $(OPENOCD_HOME)/scripts -s bsps/TARGET_APP_CY8CPROTO-062-4343W/config/GeneratedSource -c "source [find interface/kitprog3.cfg]; $(SERIAL_ADAPTER_CMD) ; source [find target/psoc6_2m.cfg]; psoc6 allow_efuse_program off; psoc6 sflash_restrictions 1; program $(MPY_DIR_OF_MAIN_MAKEFILE)/build/firmware.hex verify reset exit;"
$(OPENOCD_HOME)/bin/openocd -s $(OPENOCD_HOME)/scripts -s $(MPY_DIR_OF_MTB_ADAPTER_MAKEFILE)/bsps/TARGET_APP_CY8CPROTO-062-4343W/config/GeneratedSource -c "source [find interface/kitprog3.cfg]; $(SERIAL_ADAPTER_CMD) ; source [find target/psoc6_2m.cfg]; psoc6 allow_efuse_program off; psoc6 sflash_restrictions 1; program $(MPY_DIR_OF_MAIN_MAKEFILE)/build/firmware.hex verify reset exit;"
$(info Programming done.)

# Use this target to program multiple attached target devices
Expand Down
120 changes: 94 additions & 26 deletions tools/psoc6/mpy-psoc6.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ setlocal
if "%1"=="quick-start" goto cmd_quick_start
if "%1"=="device-setup" goto cmd_device_setup
if "%1"=="firmware-deploy" goto cmd_firmware_deploy
if "%1"=="device-erase" goto cmd_device_erase
if "%1"=="help" goto help

goto help
Expand All @@ -22,6 +23,10 @@ exit /b 0
call :mpy_firmware_deploy %2 %3
exit /b 0

:cmd_device_erase
call :mpy_device_erase %2 %3
exit /b 0


rem ~~~~~~~~~~~~~~~~
rem Script functions
Expand Down Expand Up @@ -60,6 +65,15 @@ rem ~~~~~~~~~~~~~~~~
echo board PSoC6 prototyping kit name
echo hex_file MicroPython PSoC6 firmware .hex file
echo:
echo device-erase Erase the external memory of the device.
echo Use this command to erase the external memory if available
echo for the selected board.
echo Requires openocd available on the system path.
echo usage: mpy-psoc6.cmd device-erase [board [[\q]]
echo:
echo board PSoC6 prototyping kit name
echo \q Quiet. Do not prompt any user confirmation request
echo:

exit /b 0

Expand All @@ -70,45 +84,33 @@ exit /b 0
set hex_file=%~2

echo Deploying Micropython...
openocd.exe -s openocd\scripts -c "source [find interface/kitprog3.cfg]; ; source [find target/psoc6_2m.cfg]; psoc6 allow_efuse_program off; psoc6 sflash_restrictions 1; program %hex_file% verify reset exit;"

exit /b 0

:hw_firmware_download:

set board=%~1
curl.exe -s -L https://github.com/infineon/micropython/releases/download/v0.3.0/hello-world_%board%.hex > hello-world_%board%.hex

exit /b 0

:hw_firmware_clean

set board=%~1
del hello-world_%board%.hex
openocd.exe -s openocd\scripts -s openocd\board -c "source [find interface/kitprog3.cfg]; ; source [find target/psoc6_2m.cfg]; psoc6 allow_efuse_program off; psoc6 sflash_restrictions 1; program %hex_file% verify reset exit;"

exit /b 0

:mpy_firmware_download:

set board=%~1
set version=%~2
set fw_name=%~1
set board=%~2
set version=%~3

if "%version%" == "latest" (
call set sub_url=latest/download
) else (
call set sub_url=download/%version%
)

echo Downloading MicroPython PSoC6 port %version% for %board% board...
curl.exe -s -L https://github.com/infineon/micropython/releases/%sub_url%/mpy-psoc6_%board%.hex > mpy-psoc6_%board%.hex
echo Downloading %fw_name% %version% for %board% board...
curl.exe -s -L https://github.com/infineon/micropython/releases/%sub_url%/%fw_name%_%board%.hex > %fw_name%_%board%.hex

exit /b 0

:mpy_firmware_clean

set board=%~1
echo Cleaning up micropython hex files...
del mpy-psoc6_%board%.hex
set fw_name=%~1
set board=%~2
echo Cleaning up %fw_name% hex files...
del %fw_name%_%board%.hex

exit /b 0

Expand All @@ -122,6 +124,18 @@ exit /b 0

exit /b 0

:openocd_board_conf_download

set board=%~1
echo Downloading openocd %board% configuration...
cd openocd
mkdir board
cd board
curl.exe -s -L https://github.com/infineon/micropython/releases/download/v0.3.0/qspi_config_%board%.cfg > qspi_config.cfg
cd ../..

exit /b 0

:openocd_uninstall_clean

echo Cleaning up openOCD installation package...
Expand Down Expand Up @@ -162,8 +176,9 @@ exit /b 0

Rem Download flashing tool and firmware
call :openocd_download_install
call :hw_firmware_download %board%
call :mpy_firmware_download %board% %mpy_firmware_version%
call :openocd_board_conf_download %board%
call :mpy_firmware_download hello-world %board% v0.3.0
call :mpy_firmware_download mpy-psoc6 %board% %mpy_firmware_version%

if not [%~3]==[\q] (
echo:
Expand All @@ -178,8 +193,8 @@ exit /b 0
echo Device firmware deployment completed.

call :openocd_uninstall_clean
call :hw_firmware_clean %board%
call :mpy_firmware_clean %board%
call :mpy_firmware_clean hello-world %board%
call :mpy_firmware_clean mpy-psoc6 %board%

if not [%~3]==[\q] (
echo:
Expand All @@ -190,6 +205,59 @@ exit /b 0

exit /b 0

:mpy_device_erase

setlocal enabledelayedexpansion

Rem Board selection
set board=%~1
set board_list[0]=CY8CPROTO-062-4343W
if [%board%]==[] (
echo:
echo Supported MicroPython PSoC6 boards
echo +---------+-----------------------------------+
echo ^| ID ^| Board ^|
echo +---------+-----------------------------------+
echo ^| 0 ^| CY8CPROTO-062-4343W (default^) ^|
echo +---------+-----------------------------------+
echo:
echo No user selection required. Only one choice.
set /a board_index=0
echo:
Rem set /p/( "board_index=Please type the desired board ID. " --> Uncomment and remove preselection above when more options are available
call set board=%%board_list[!board_index!]%%
)
echo MicroPython PSoC6 Board :: %board%

Rem Download flashing tool and firmware
call :openocd_download_install
call :openocd_board_conf_download %board%
call :mpy_firmware_download device-erase %board% v0.3.0

if not [%~2]==[\q] (
echo:
echo Please CONNECT THE BOARD and PRESS ANY KEY to start the firmware deployment...
pause >nul
echo:
)

Rem Deploy on board
call :mpy_firmware_deploy %board% device-erase_%board%.hex
echo Device firmware deployment completed.

call :openocd_uninstall_clean
call :mpy_firmware_clean device-erase %board%

if not [%~2]==[\q] (
echo:
echo Press any key to continue...
pause >nul
echo:
)

exit /b 0


:arduino_lab_download_and_launch

echo Downloading Arduino Lab for Micropython...
Expand Down
Loading
Loading