Connect things with code!
Fun with the Infineon Ecosystem
This project was created to participate in the Challenge Connect things with code
For this this project my idea is to connect an Arduino Seeed Grove socket LED module to two Infineon PSoC 6 evaluation kits,
Components used in this project:
MCU:
Infineon PSoC 62S2 evaluation kit (CY8CEVAL-062S2)
Infineon PSoC 62S4 pioneer kit (CY8CKIT- 062S4)
Peripheral:
Grove Socket LED Module
Project SpecificationMy project specification includes the following goals following the main goals of the challenge:
Choose an Infineon MCU
Attach the peripherals that you want to use.
Development Environment
Create a device library.
Test the device library
Share it with the community.
The next sections in the project will elaborate on these 6 goals.
Choose an Infineon MCU development platform.There are many different Infineon MCU development platforms available. I received Bundle C, from infineon for this challenge, but I did not receive it in time for my project. I decided to use the following PSoC MCU kit.that I had on hand.
Infineon PSoC 62S2 evaluation kit (CY8CEVAL-062S2)
I chose this kit, because it has Arduino Form-Factor compatible Headers The board has four Arduino-headers: J1, J2, J3, and J4. You can connect 3.3 V Arduino compatible shields to develop applications based on the shield’s hardware.
Note: 5-V shields are not supported and connecting a 5-V shield may permanently damage the board.
Note: All Arduino header pins are not connected to the same voltage reference. ARD_D[10:13] are powered by VDDIO0 whereas the rest are powered by domains connected to VTARG. Hence arduino shields particularly that use ARD_D[10:13] must not be used when VTARG is 1.8V.
Attach the peripherals that you want to use.Once you have chosen a development platform, you will need to attach the peripherals that you want to use. This may include things like sensors, displays, and communication modules
I connected the Grove LED Socket Kit to the digital 3 pin on the Arduino Header, using the Gove connector shown below:
Dev Environment: Modustoolbox 3.1
I decided to use the latest version of MTB 3, 1 for my development ecosystem for this project.. I have also used earlier versions and I’m still learning all the many ways to use the ToolChain.
To use the Arduino-compatible headers mentioned above, they will need to be assigned using the Pins in the Modustoolbox Device Configurator tool. This tool allows you to connect the pins from the MCU to the Headers.
I will be using the IDE to Create a workspace that will include:
- a library project based on this MCU and the Peripheral mentioned.
- some testing projects to test the library.
Before I can create a library that will blink my Grove LED module, I need to understand how to toggle the digital pin that is connected to the Yellow SIG pin on the Grove Connector. For this I needed to understand how the PSoC 6 does GPIO. I learned that there are two API’s used to do this: HAL (Hardware Abstraction Layer) and PAL (Peripheral Driver Library). The complete reference page can be found at:Hardware Abstraction Layer (HAL)and PSoC 6 Peripheral Driver Library: Getting Started. I also learned that you need to assign GPIO pins in the Device Configurator Tool.
This video will walk you through developing a basic blinking LED application using the GPIO drivers of both the Hardware Abstraction Layer (HAL) and Peripheral Driver Libraries (PDLs). ModusToolbox™ How-To - Creating a Blinky LED.
By the end of this video, you will have a basic understanding of how to use GPIOs and the HAL to create a blinking LED application. You will also have a basic understanding of how to use the PDLs to create higher-level APIs for accessing specific peripherals.
I was able to get the demo from the Blinky video working on my Infineon PSoC 62S2 evaluation kit (CY8CEVAL-062S2)., I decided to use what I learnt from the video to toggle the GPIO digital pin on the Arduino J4 header.
The HAL implementation using the D3 pin does not work for some reason, but the PDL implementation does, so the following function has to be used just like the GREEN LED in the video demo.
You need to use the PDL calls to get it to work. Here is what I did to get the LED on the Grove module to blink.
First connect the Grove connector to the Arduino header as described in the wiring diagram above.
In the Device Configurator you need to check the CYBSP_D3 Pin and on the the parameters tab you need to Set “General/DeviceMode” to Strong Drive Input buffer Off
The following HAL function has to be used just like the GREEN LED from the video demo except you will use defines created in the step above.
In the code you need to use the HAL GPIO function with the following defines.:
Cy_GPIO_Inv(CYBSP_D3_PORT, CYBSP_D3_PIN);
You can get the CYBSP_D3_PORT, CYBSP_D3_PIN defined in the Code Preview in the Device Configurator. as pictured below.
Device Configurator – showing P5(3) being set and the Drive mode set to “Strong Drive, Input Buffer off”
Finally here is the CODE with new function using the D3 pin
I was able to Build and Launch the Firmware to the kit. As you can see in the video below, all the LEDs are blinky, Including the Red Grove LED on the attached module, SUCESS!!
Now it’s time to use what I learned from this exercise and create a library to implement an API to mimic the ARDUINO calls.
Create a device library.A device library is a collection of code that provides access to the features of the MCU and the peripherals that you have attached. For my library, I am going to Implement the Arduino library calls used for accessing the Digital pins.
The following code would be used to access the LED if it was wired to an arduino.
#define LED 2 //connect LED to digital pin2
void setup() {
// initialize the digital pin2 as an output.
pinMode(LED, OUTPUT);
}
void loop() {
digitalWrite(LED, HIGH); // set the LED on
delay(500); // for 500ms
digitalWrite(LED, LOW); // set the LED off
delay(500);
}
I need to implement the following calls in my library:
pinMode(pin,INPUT/OUTPUT)
digitalWrite(LED, HIGH); // set the LED on
delay(500); // for 500ms
digitalWrite(LED, LOW); // set the LED off
The code will implement the PAL (Peripheral Driver Library) to init the pin and set the pin to High or LOW and delay for a given amount of milliseconds.
STATIC Library
I first thought I could use a ModusToolbox Static Library to implement a shared library. I followed the following steps to create a Static Library project.
1. Create a static library project
- File -> New -> Project…” to Open the “New Project” dialog.
- select “Static Library -> Empty Project” and name your project. Make sure you select “ARM Cross GCC” as your toolchain
- Then repeat “Next” and “Finish” to create the project without changing the rest of the configurations.
- Then repeat “Next” and “Finish” to create the project without changing the rest of the configurations.
2. In my newly created project, I create a c file and a header file. In the c file I place #include "cy_pdl.h", so I can use calls to the PAL as I did in the previous section where I was experimenting with the SDK.
3. I now have a problem, because the include is not resolving? I cannot use the calls to the PDL. I inquired to the SDK PSoC Forum to try to find out if the SDK is supported in a Static library and I received the following advice:
I don't recommend to use static library ( pre-compiled ) for your project since there is a possibility of using different BSPs. Each BSP has different register and to use. Static library will be good if we want to build application-function, or specific function that only contains some algorithm or function without using specific BSP.
If you want to build static library that contains function from BSP, you need to add all reference of include files.
Right click on project name > properties.
in Section C/C++ Build > Settings in tab Tools Settings. You need to add the path or workspace of the library file that included the BSP for example mtb_shared/mtb-pdl-cat1/latest-v3.X/drivers/include
I did receive a solution with a complete implementation of the Arduino Digital API.from the same Forum entry, This solution saved me a lot of coding and introduced me to sharable custom libraries in MTB. So I abandoned Static librarie for now and decided to implement this solution. I describe my steps in the next section.
An Arduino API Library for the CY8CKIT- 062S4
I received a solution to my idea of a library that implements the Arduino library calls used for accessing the Digital pins. The forum user supplied me with a.c and. h file in a zip file and a tester example that calls the library. He used the Infineon PSoC 62S4 pioneer kit (CY8CKIT- 062S4) for his example, so I used it to experiment.
NOTE: Every PSOC 6 has different pin assignments for the arduino jumpers, Thus the need for the mapping array in the arduino_gpio.c, C file.If your using a different PSoC 6 kit, alter this array to contain the P<port>_<pin>. For example, for the CY8CKIT- 062S4 kit, D7 maps to P6_3. Indicating port=6 and pin=3.on the MCU.
I performed the following steps and successfully was able to run the example code using the library.
1. Create an empty project
2. Copy the files in the zip files (arduino_gpio.c, arduino_gpio.h) to the project folder.I have included them in the code section.
3. Replace the code in main.c with the main.c in the code action. Again included in the code section.
4. Build the application.
5. Wire the LED module as above except for the YELLOW jumper. Attach this jumper to pin D7 on the CY8CKIT- 062S4
SIG (yellow) goes to Pin P6_3/D7 on J4 header
V3.3 (red) goes to V3.3 on J1 header
GND (black) goes GND on J1 header
6. On a successful build, debug and the LED should be blinking. If it is not, then you have attached the jumpers to the wrong pins.
Source code used for this solution
These files are located in the code section below with the following names
The Library files:
arduino_gpio.c
Arduino_gpio.h
Test
main.c
Test the device library.Once you have created a device library, it is important to test it thoroughly to make sure that it works correctly. You can do this by writing unit tests and by running the device library on a real-world system.
I have included code that will be placed in the main.c file in the project. You have already done this if you were following my steps above.To test you can try different pin numbers. Be sure to attach the yellow pin to the proper digital pin on the arduino jumper. I found digital pin 3 on the CY8CKIT- 062S4 was the only pin that did not respond. I do not know why. The Silkscreen number for this contains an asterisk (*). This could be an indication, I never took the time to find out why. If anyone knows, please send me an explanaton.
The debugger helps to understand the inner workings of the Library and gies an excellent implementation of using the PDL SDK. The calls start with Cy_. The GPIO PDL implementation can be found here: PDL GPIO
Share it with the community.Once you have tested the device library and confirmed that it works correctly, you can share it with the community. This will help other developers to use the Infineon MCUs and the peripherals that you have attached.
To share this library I have included it here in my project. The ease of installing 2 files into a directory and building, makes it really easy to share libraries.
I have used github to share code by using my repo. ModusToolbox examples are stored there and make it really easy to share examples. I’m not familiar with how to create a library and share it in this way yet. If anyone reading this can guide me, I would be interested in learning this. The solution of copying source code to a directory could get tricky with more complex libraries that have several files.
My ConclusionsHere are several conclusions that can be drawn from my experience:
- For the MCU platform I used two PSoC 6 evaluation kits for this project due to their compatibility with Arduino headers, allowing the connection of 3.3V Arduino-compatible shields and Grove Modules, noting that 5V shields are not supported.
- To connect a peripheral, I connected a Grove LED Socket Module to the digital pin 3 on the Arduino Header of the two MCU kits. I mention the use of Grove connectors for this purpose
- Development Environment: I decided to use Modustoolbox 3.1 as the development environment for the project. I was able to figure out how to configure pins and create a workspace that includes a library project based on the MCU and the connected peripheral.
- GPIO Control: I was able to figure out the process of toggling GPIO pins using both Hardware Abstraction Layer (HAL) and Peripheral Driver Library (PDL) APIs. I was able to find and refer readers to resources that guide users in creating a basic blinking LED application using GPIO drivers in both HAL and PDL.
- Library Development: I describe my journey in creating a library to implement an API that mimics Arduino calls for accessing digital pins. I discuss the use of the Peripheral Driver Library (PAL) to initialize pins and implement the necessary functions. This was made possible, thanks to the help of a member on the Infineon Forum.
- Static Library Creation: I attempted to create a static library using Modustoolbox but encountered issues with including PAL calls in the library. I decided to use the example library given to me by the member on the infineon Forum.
- Arduino API Implementation: I received a solution that provided a.c and.h file for implementing Arduino library calls for digital pins. I explain the steps one would take to integrate and test this Library, noting pin mappings for different PSOC 6 kits.
- Testing and Debugging: I briefly describe the testing and debugging of a device library. I provide insights into using the debugger and the Cy_ calls within the library to understand its inner workings.
- Sharing the Library: I express my intention to share the library with the community. I discuss the ease of sharing this simple library with simply copying files and express interest in learning more about sharing libraries.
- I undertook many challenges in this project involving two Infineon PSoC 6 evaluation kit, connected a Grove LED Module, explored GPIO control using HAL and PDL, attempted static library creation, implemented an Arduino API library, tested and debugged the library, and expressed my desire to share my work with the community to fulfill the main goal of this challenge.
Thank you for reading through my project. It was fun. Please comment on your thoughts.
BACK to the introduction blog for this challenge Unleashing the Power of the Infineon Ecosystem
Comments