This is project is to showcase various features, capabilities, pedagogies, scenarios and use-cases around the Infineon PSoC™ 6 MCU Product Family boards and the Infineon XENSIV™ Sensor(s) board.
The project will also employ external peripheral components like ArduCam or ESP32-Cam or any Camera module using I2C or SPI interfaces.
Project Outline:What will be covering in this project: ( What problem we are solving?)
Chapter 1: Port MicroPython to CY8CKIT-062S2-43012 Board
Chapter 2: Make CY8CKIT-062S2-43012 BSP accessible from MicroPython-AI
Chapter 3: End-to-End Machine Learning = = MicroPyhon4AI + CY8CKIT-062S2-43012
Chapter 4: Visual Drag & Drop Programming with CY8CKIT-062S2-43012 (Scratch-AI Based Environment)
Chapter 5: SPI/I2C Camera interface for CY8CKIT-062S2-43012 6.) I2S Gestures and serial communications
We will showcase given Infineon hadrware CY8CKIT-062S2-43012 Board along with Infineon IoT Sense Expansion Kit for various use cases and scenarios we have listed below here:
Our Propsed Applications:
- Thermal Ranger: A MicroPyhon-AI fire application alert for home
- ProximityMe: CircuitPython-AI on CY8CKIT-062S2-43012 (edge to SensMIL)
- Abnormal: AI Activity Recognition Alert (MicroPython on CY8CKIT-062S2-43012)
- Object Detection AI (Interface CY8CKIT-062S2-43012 with SPI Camera module)
- Positional and Fall detection AI gym with BMX160 Absolute Orientation Sensor
NOTE: We will try to showcase each of the above applications under each outline chapter but we may repeate some of them in more than one chapter. Somtimes for comparison, for analysis or What if then, etc... Many thanks!
Features explotation:- Exploit PSoC™ 62S2 Pioneer Board capacitive sensing interfaces in mutual-capacitive-sensing with AI (ProximityMe)
- Exploit PSoC™ 62S2 Wi-Fi/BLE for IoT at Edge with the IoT Sense Expansion kit
- Exploit the serial I2C/SPI interface to incorporate Camera (ArduCam or ESP32-Cam or any Camera module)
- Demonstrate how to collect datasets, train data at edge with cloud visualisation (AIoT)
- Use ModusToolbox as "Native Machine (AI) code in MicroPython
Software Platforms:
We will be using the Infineon ModusToolbox platform along with other external 3rd parties library and those that we have derived or adapted ourselve when we cannot find anything that satifies us or what we want/like to do.
We will be using:
- MicroPyhon (or CircuitPython)
- BIPES (Block based MicroPython)
- Snek(another alternative to MicroPython but for more leaner embedded MCU.
On the data handling side for our machine-learning, we will employ the services of the following platforms:
- SensiML: (Cloud based machine-learning platform)
- Picovoice: (voice API for AI)
We ourselve are AI (ML, DL, RL, GAN, etc..) hacker, we may present some other platforms like tinyML clones, Neural Network in C in this project for simplicity and accessibility for absolute beginners and young age-group to ML. (for example ML4Kids or ML4Everyone paradigms)
The ModusToolBox:
If you come across someone who says that the Infineon ModusToolBox is an hardware configuration and code generation environment. That person description is not far fetch. The first I started playing around the toolbox, I felt same that the toolbox enables you to configure various parameters, properties and features that you want to use on your intended Infineon hardware. It then generates codes for all your configured and supporting specifications (BSP: Board Supporting Packages). If you have used the Arduino IDE environment or that of YOCTO or Buildroot or even Platformio, then you have good understanding of BSP and all the advantages that you can have. Another good thing about BSP is incremental features add-in/removal, continuos integration/contnuos development (CI/CD), interface generation (e.g. enable/disable some GPIOs, I2C, SPI) and pin mappings and many more...
If you can add an Editor and toolchain on top of ModusToolbox then you have got a complete ALL-in-One (Suite) IDE that you have use to hack those gorgeous Infineon hardware. Please dream on!
According to ModusToolbox guides, BSP is a central feature of the platform. with BSP, several critical items for an application can be obtained including but not limited to the followings:
- hardware configuration files for the device (for example, design.modus)
- startup code and linker files for the device
- other libraries that are required to support a kit (this particular feature is of interest to us as we want to bring the followings:=> MicroPython/CircuitPython, Snek, BIPES and other enhancement. Think FFI (Foreing Function Interfaces)
Getting Started: Software Setup
While awaiting the arrival of the hardware gears, we will start by setting up the software part of the project, play and thinker with those software to see on how they will manifest through connecting buses, wires and bring alive those slilicon chips.
ModusToolbox Setup
ModusToolBox Setup
There are few ways to setup Infineon ModusToolbox on Windows, Mac OSX or on Linux.
You can go it either through the GitHub scripts and do it manually. This is important if you want to customise or extend the toolbox for specific purpose. If you choose to go via this route, see the repositories here: https://github.com/Infineon/modustoolbox-software and https://github.com/Infineon/Code-Examples-for-ModusToolbox-Software.
Don’t forget to go through the training materials here: https://github.com/Infineon/training-modustoolbox I spent few days combing through them for skills needed for this competition. I explore you to do the same! There is an extensive user-guide on this link: https://www.cypress.com/ModusToolboxUserGuide, feel free to explore that as well.
You can also setup through a packaged installer as outlined below here. For this I will be doing the setup on Microsoft Windows 10 but the toolbox is completely platform and operating systems independent.
📷The installer can be downloaded from here: https://www.infineon.com/cms/en/design-support/tools/sdk/modustoolbox-software/ I will advise you to register on the website. It’s free!
📷Access the website, click the download button to get to the package options page:
Be patient while the download commences and progress, it’s a whoppy 1.2GB, so your mileage and download time will vary based on your internet connection and bandwith.
Next go to your download directory; double click on ModusToolbox_2.4.0.5972-windows-install.exe file start the installation process:
📷Select Yes, allow if your Windows O/S prompts you. Click the next button on the installation welcome page. Select accept the agreement option and click next
Accept the default folder for installation. Do not try to install on folders with spaces e.g. Program Files and sort of. Also you may need to turn off your Anti-virus temporarily during the installation and development phase of this project. Remember, you are Microsoft Windows! Okay! So put your shoes on ….. :)
Click next to allow the installation to run to completion. Did we tell you that you need about 3.09GB of disk space? So sorry to alert you at this point in time but on the happy side you are given free kits to hack on, test driven those kits and feedback on your experience. What more do you want? Happy hacking!
📷When the installation process ends, I encourage you to navigate through the ModusToolbox directory and it’s sub-directories. Part of learning is to be inquisitive, curious and tinkering with objects at hand. The Toolbox is based on Eclipse IDE environment but it come with its Java JRE packaged along huh!
The tools_2.4 folder contains various tools; some of them are actual standalone and can the used on their own while other tools work in-conjunction with other ones. Resources like smartio configuration, Bluetooth configuration, usbdev, ml (machine-learning), device configuration, compilers like gcc and python, to name but few of the vastly available tools in hybrid packaged together. I spent few hours poking around the tools sub-folders. Surprisingly most tools have documentation in their respective sub-folders. Kudos! to Infineon for this!
The document folder contains the user-guide and most other information that you will need to start using the Toolbox.
Lastly the ide sub-folder houses the eclipse IDE that is making use of the gcc compilers in concert along with the Python compilers. There is also QT in one of the subfolder doing some GUI stuff out there.
Let’s us take the ModusToolBox for a spin and start configuring our PSoC™ 6 62S2 Wi-Fi BT board along with the IoT sense expansion kit to work for us in our projects.
MicroPyhon
We
will be porting MicroPython to PSoC™ 6 62S2 Wi-Fi BT board using for some of our AI prototypes and case-studies.
NOTE: MicroPython and CircuitPython have come very close recently that we can either use any of them. CircuitPython is based on MicroPython and it extends MicroPython with many embedded hardware libraries or ports. Think hardware library or a port like... a BSP (Board Support Packages) in Python language and Arduino world/platform. Strong hardware support and plentorial libraries and more low level are what set CircuitPython apart from MicroPython. Also it brought shared modules and bindings, supervisor and added more tools beyond MicroPython. The good news is that both highly compatible and can be used to extend one another. More about this later in this project.
Porting-Part-1:
MicroPython on PsoC 6
installing Cmake on Ubuntu Linux 22.04. on terminal run the following steps:
wget https://apt.kitware.com/kitware-archive.sh
This will download Cmake and other required packages from kitware repository for our use
Next add to the bash command,
sudo bash kitware-archive.sh
if you get the error that only 16.04 and 20.04 are supported, then we need to work around this issues:
A walk around is to manually set Cmake and other build tools, so run the following commands:
sudo apt-get install --no-install-recommends git cmake ninja-build gperf \
ccache dfu-util device-tree-compiler wget \
python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file libpython3.8-dev \
make gcc gcc-multilib g++-multilib libsdl2-dev
we need a minimum version of Cmake 3.20.0, check your system-wide for what is installed:
cmake –version
it should say cmake 3.20.0 or higher. Mine is 3.22.1 as shown below:
Next we need the Zephyr, its SDK and other toolchains installed and on our path:
so we get zephyr build and flash tool installed as stated below:
pip3 install --user -U west
echo 'export PATH=~/.local/bin:"$PATH"' >> ~/.bashrc
source ~/.bashrc
Now, we create a scratch folder for our MicroPython porting platform, currently I am doing things via Zephyr RTOS subversion.
Create a folder called zephyrproject in home directory:
mkdir ~/zephyrproject
Note: that the folder name could be anything you want to call it. I have many porting projects running on my server but I was always start them from this folder before moving things on from default settings.
Next run: west init ~/zephyrproject
The west package manager will download some dependencies for you and initialise your project folder.
This will take sometime depend on your internet speed and bandwidth, so be patient!
Next update the newly setup project:
cd ~/zephyrproject
west update
note: if you get error message about: update failed for project libmetal, re-run west update again then hopefully all dependencies will be resolved.
Now we need to export a Zephyr CMake package to allow CMake to automatically load boilerplate code required for building Zephyr applications.
west zephyr-export
More now we update our project requirements installing additionally required toolchains
pip3 install --user -r ~/zephyrproject/zephyr/scripts/requirements.txt
we get a lot of python, west project build resources for our project.
Now we need to get the SDK in place, in order to get the latest sdk, you need to download it from Zephyr GitHub:
https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.14.2/zephyr-sdk-0.14.2_linux-x86_64.tar.gz
or
wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.14.2/zephyr-sdk-0.14.2_linux-x86_64.tar.gz
extract the downloaded package, navigate inside it and the setup.sh file to start the installation, answer on screen options to select the tools needed for zephyr project on Ubuntu Linux box
We need to add privilege for access hardware as a user under Linux by installing udevrules, which allow you to flash most Zephyr boards as a regular user:
sudo cp ~/zephyr-sdk-0.14.2/sysroots/x86_64-pokysdk-linux/usr/share/openocd/contrib/60-openocd.rules /etc/udev/rules.d
sudo udevadm control --reload
Taking things out for a spin:
Hello-World: Initial board test
cd into the project folder
cd ~/zephyrproject/zephyr
run: west build -p auto -b cy8ckit_062_wifi_bt_m0 samples/basic/blinky
this will get a sample project built for our PsoC 6 board. If everything went as it should be then a build result should be as shown in the screenshot below:
Note: that the PsoC 6 board will usually run from its Cortext M0+ core by default and you will need to program it to use Cortex M4 through the flash. Although both cores share the same Flash/RAM/MMIO address space.
Flash the hello-world sample onto the board:
west flash
Note: if you get errors relating to an incomplete flash, timeout, etc… you may need to put the board in flashing state using switch 3 to select the debug mode. The LED 2 for KitProg3 status should be flash to indicate that mode.
Error screenshot:
Also try and see if the board already being programmed:
in the terminal run:
lsusb
add yourself to the dialout group for low-level device access:
sudo usermod -a -G dialout, plugdev $USER
Next poke the system for your board:
dmesg | grep tty
note: you may need to log out and log-in again for this to take effect otherwise just use it with sudo
As you can see our board is accessable from port ttyACM0, e.g. /dev/ttyyACM0
You can use any terminal like minicom, tera-term and so on….
Install minicom with the commands:
sudo apt-get install minicom
Next run minicom => sudo minicom -s
Now do and adjust the serial device ==> A - Serial Device : /dev/ttyACM0
save configuration dfl and get back to terminal
Press the reset button on the PsoC 6 board. This is switch 1 or XRES label device.
You should see the board outputting the Hello World message on minicom terminal. If this is the case then congratulation! You have got zephyr rtos running on your PsoC 6 Wi-Fi Pionner board. This is a breathtaking routines but it is the bases for our next porting and getting MicroPython to run on our PsoC 6 board. Kudos!
Play with board LED blinking proram by following the onscreen information to pause and resume the LED blinking mode. See the screenshot and the video below:
Once again, place PsoC 6 board into CMSIS-DAP mode. You will LED-2 flashing to indicate that you are in this mode.
We are going to modify our code and flash the board again. Lets go:
updating the firmware:
From ModusToolbox/tools_2.4/fw-loader/bin
run: ./fw-loader --device-list
then follow by:
./fw-loader --update-kp3
I think these steps should get your board firmware updated
Building MicroPython Port for CY8CKit 062 WiFi BT board
First we git clone MicroPython onto our home directory
git clone https://github.com/micropython/micropython.git
Next navigate into ~/zephyrproject/zephyr
run: source zephyr-env.sh
Now build MicroPython port:
west build -b cy8ckit_062_wifi_bt_m0 ~/micropython/ports/zephyr
Next flash the board
west flash
issues: difficult to reset the board
=============
Additional Peripherals:
SCCB/I2C Cameras Setup:
We have two cameras but actually we have some more but we want to focus on the following two cameras first. others will serve as backup should in case we fry things up, hacking sometimes comes with own cost but that is what you get being an hardware hacker. :)
Our first camera module is the OV2640 2.0MP mini Camera Shield module 3.3V.
According to the maker, the camera has the following attributes and specification:
Description:
- Image sensor features 2 megapixels (1600x1200 pixels)
- High sensitivity, high flexibility, support for JPEG output and so on.
- Support exposure, white balance, color, saturation, contrast, etc...
- Sensor size: 1/4 inch
- Pixels: 1600 * 1200 (200W)
Specification:
- Size: Approx. 27*27*25mm / 1.06x1.06x0.98inch
- Material: Plastic
- Output format: RGB565 / JPEG / YUV / YCbCr and so on
- Control interface: SCCB (Serial Camera Control Bus is said to be compatible with I2C but one thing to be noted here is that you cannot have more than 1 address on the same bus if you are using SCCB (NOTE: we may get away with this limitation when we get MicroPython ported since we can use pySerial or Firmata. More on this con later in our project).
- Working voltage: 3.3V
blah
blah
Infineon PSoC and Sensor Expansion Kit Setup:
Unboxing:The Eagle has landed! Well here comes the PSoC 6252 board arrived with the Sense Expansion kit. Thank you so much for the kit. My hands are itching and can't wait any further. Let's get it on.....
Note:
This runs very well on kitprog2 but I had issues with the latest tools_2.4 and tools_2.3 with all my flashing haging at the end due to memory layout and difficult to set configurations e.g. psoc6.cfg and psoc6_2m.cfg and other are all throwing various errors to me during my hack.
It is an amazing development kit. I will definitely work more on this kit beyond this competition as it opens up plentora of exploration most especially on IoT, ML and computer science explorations.
Also it will be nice to have dedicated flashing tools for this family of boards mostly especially the dual-cores. Confusion on defualt core among PSoC6 family, in some datasheet, it said M0+ and in some it M4. While there are plenty documentation, guides, tutorials and videos, things may need to be collated, refined to make developer's life a bit easier as more boards are being added to the list. Thank you!
=======================================================================
ProjectResource/Files/Code on GitHub repository:
1.) https://github.com/sanyaade-teachings/zephyr
2.) https://github.com/sanyaade-teachings/micropython_psoc6-wifi-bt
Need to upload more resource there....
=======================================================================
Appendix A:ModusToolBox Setup in Ubuntu 22.04 LTS
Errors and issues:
issue 1:
soln 1:
download this from https://packages.debian.org/stretch/libssl1.1
sudo dpkg -i libssl1.1*.deb
the run./project-creator-cli from the tools_2.4/project-creator directory or run its gui mode from inside Eclipse IDE:
issue 2:
Soln 2:
issue 3:
trying to run project-creator from a system-wide e.g. from your mtw workspace folder will result in an error unless you add it to system environmental path(e.g..bashrc or bash_profile)
soln 3:
after struggling with project creator for several days in an on/off situations, I decided to install the SDK locally, according to this online bug report on the Infineon MTB community forum:
NOTE: if you are on ubuntu Linux box like me then you need the ~/.profile i.e. without the bash_
in Ubuntu Linux ~/.profile ==> ~/.bash_profile in other Linux or MacOS but check your platform environmental configuration scheme
I also added the above line into my ~/.bashrc just to be sure that things are getting setup!
Our next issue is the libssl1.1.1 which was another hair pulling and took some internet googling to get it resolved. See my report on this below:
The issue:
My solution:
after the above steps the libssl1.1.1 was installed but hold your breath yet again, as the boat is still rocking along, hacking is hair pulling routines, sometimes it just work, but sometimes would not?
Note: Do not forget to restart your project-creator or Eclipse IDE
A rerun of project-creator-cli from Eclipse terminal for the CY8CKIT-062-WIFI-BT psoc6-hello-world sample now work:
lot of libraries files, dependencies resolved but alas you need a live internet connections for all these to happen. The paradigm here is to Rust and cargo or just like any cloud based remote repository but we are using a public GitHub not Infineon private repository.
Aside, if you are curious and want a fully customised environment or interested in porting to other Infineon board, making SDK, BSP, etc… then the whole shebang used in cooking all the IDE, SDK, BSP stuffs are here: https://www.infineon.com/cms/en/design-support/software/free-and-open-source-software-foss/#!support
to be honest, I will be playing around those stuffs as I want some customised resources for my teachings this summer. Thank you all!
Here is a quick brief about the basic hello-world equivalent for our board:
Version 2.4 of the ModusToolbox has shared libraries incorporated to minimise dependencies duplication among boards. 185MB was an hair pulling for a single embedded board, space eating as well
Comments