Code Examples Forum Discussions
The ECDSA (Elliptic Curve Digital signature algorithm) is a cryptographic algorithm that used to authenticate the data if it is coming from known source and the data is not tampered while transferring. This algorithm relies on hardness of solving discrete logarithm problem to make sure adversaries cannot generate an authentic signature nor tamper the message without noticing.
Scope
This code example demonstrates the usage of various ECDSA (Elliptic Curve Digital signature) operations using CRYPTO block of PSoC 6TM MCU devices.
It provides a prompt to the user via UART and waits for user input. Based on the input and the data provided by the user, appropriate tasks (create key pair, Sign the data, verify the signature, export the public key) are performed.
Design and implementation
The code example uses The PDL library to perform the following operations in ECC.
- Set ECC curve and hash mode - Ask the user to select the ECC curve and hash mode and set the parameters accordingly.
- ECC key gen - Creates ECC Public/private key pairs.
- Sign data – Reads the data from the user. Computes the hash and signs the hash with the created private key.
- Verify data - Reads the data and signature from the user. Computes the hash of the data, verifies the hash using the stored public key.
- Export p - Sends the public key (x, y coordinates) in big endian format over UART.
- Print ECC parameters - Sends the ECC curve name and hash mode in UART.
File: source/ecc.h:
- Definition of structure ecc_params to store the ecc parameters.
- Declarations of functions to perform ECC operations.
- Declarations of functions to convert ECC signature from raw to DER format and vice versa.
File: source/ecc.c:
- Definitions of functions to perform ECC operations.
- Definitions of functions to convert ECC signature from raw to DER format (signature_raw_to_der) and DER to raw format (signature_der_to_raw).
Verify signature outside of PSoCTM 6 MCU
- You can also verify the signature of message outside of PSoC 6TM MCU (E.g. From PC).
- For this you need to first get the signature, public key from PSoC 6TM MCU.
- scripts/verify_signature.py can be used to verify the signature as follows.
- Save the public key:
- Get the public key from PSoC 6TM MCU using Export public key command and copy it.
- Execute the following python command:
python.exe scripts/verify_signature.py save-pubkey -k pub_key.pem
- The above script will ask for public key, paste the public key received from PSoC 6 MCU. The public key will be saved as pub_key.pem
- Verify the signature:
- Get the signature from PSoC 6TM MCU using Sign data command.
- Execute the following python command to verify the message:
python.exe scripts/verify_signature.py verify-signature -k pub_key.pem
- The script will ask for message, signature and hash mode as inputs.
- Result of the signature verification is returned.
Show Less
Hi,
I have always wanted to use printf in projects created with CY8CKIT-041S-MAX on Modus tool box.
It was very convenient once I figured out how to use it.
However, I spent a lot of time trying to figure out what settings were necessary and what were not.
So I thought I would share this with you to help you understand.
I modified the "Hello_World" that I got from BSP.
I also referred to this topic:
https://community.infineon.com/t5/Blogs/Using-the-retarget-io-library-to-enable-printf/ba-p/247044
The following steps will enable you to use printf().
STEP1. Add a library
Hello_world project obtained from BSP is missing a header file to use printf.
Therefore, add the necessary libraries from the Library Manager and make the file structure the same as in the image below.
STEP2. Setting up with device configurator
Uncheck the preconfigured UART checkbox.
STEP3. Write the main code
When writing the main code, the following points are important
- Prototype declaration in #include "cy_retarget_io.h
- Specify the Rx and Tx ports of the UART
- Call cy_retarget_io_init()
NOTE:
CY_RETARGET_IO_BAUDRATE, which sets the baud rate, did not need to be declared in the main code.
It is already defined in "cy_retarget_io.h".
If you need to change the baud rate, the easiest way is to change the value of CY_RETARGET_IO_BAUDRATE defined in "cy_retarget_io.h".
main.c
/******************************************************************************
* File Name: main.c
*
*****************************************************************************
/*******************************************************************************
* Include header files
******************************************************************************/
#include "cy_pdl.h"
#include "cybsp.h"
#include "cy_retarget_io.h"
/*******************************************************************************
* Macros
*******************************************************************************/
#define LED_DELAY_MS (1000u)
#define CY_ASSERT_FAILED (0u)
#define CYBSP_DEBUG_UART_TX (P0_5)
#define CYBSP_DEBUG_UART_RX (P0_4)
/*******************************************************************************
* Function Name: main
********************************************************************************
*
* Parameters: none
*
* Return: int
*
*******************************************************************************/
int main(void)
{
cy_rslt_t result;
/* Initialize the device and board peripherals */
result = cybsp_init();
/* Board init failed. Stop program execution */
if (result != CY_RSLT_SUCCESS)
{
CY_ASSERT(CY_ASSERT_FAILED);
}
result = cy_retarget_io_init(CYBSP_DEBUG_UART_TX, CYBSP_DEBUG_UART_RX, CY_RETARGET_IO_BAUDRATE);
if (result != CY_RSLT_SUCCESS)
{
CY_ASSERT(CY_ASSERT_FAILED);
}
/* Enable global interrupts */
__enable_irq();
for(;;)
{
/* Toggle the user LED state */
Cy_GPIO_Inv(CYBSP_USER_LED1_PORT, CYBSP_USER_LED1_PIN);
/* Wait for 0.5 seconds */
Cy_SysLib_Delay(LED_DELAY_MS);
printf("\rいつもお世話になっております\r\n");
}
}
/* [] END OF FILE */
STEP4. Modifying make file
Write CY_USING_HAL in DEFINES at approximately line 104.
STEP5. Build and load
I use Terra Term.
If the terminal is set up correctly, the string stored in pringf will be displayed.
Finally,I have written main.c to output simple code that is easy to understand even for the beginning user.
In the future, I would like to try different codes using the printf function.
Thank you for reading this post.
Best Regards,
Show Less
According to the KBA: ModusToolbox ™ Manifests Repositories, you can infer from it that the official ModusToolbox ™ Manifests Repositories are hosted on github.com.
According to this KBA: ModusToolbox ™ Manifests Repositories, you can learn that the official ModusToolbox ™manifest repository is hosted on github.com.
Sometimes the service of github.com is not available in some Countries/Regions. Hence I mirrored them to gitee.com. another website providing Git repo services.
However, the github.com service is sometimes not available in some countries. So I mirrored a copy of these manifest repositories and put them on gitee.com. gitee.com is a website similar to github.com which also provides Git repository services.
If you can't access the official manifests, you can turn to the mirror repos for help.
If you don't have access to the official list, you can rely on these mirror repositories.
Usage is kept the same with the KBA above. All you need is to replace the official links with the mirror links below and follow all other steps. You may need to combine these two articles to get what you need.
The method of use is the same as the KBA above. All you need to do is replace the official link address with the mirror link address below, and the rest of the steps remain exactly the same. You may need to combine these two articles to get the information you need.
Infineon's standard manifests (mirror)
Infineon's standard manifests are the basic manifests for ModusToolbox ™. They denote the core boards, example projects, libraries, and library dependencies of ModusToolbox ™.
Manifest repo root | Super-manifest links of the repo |
https://gitee.com/dreamscaperia/mtb-super-manifest/raw/master/mtb-super-manifest-fv2.xml https://gitee.com/dreamscaperia/mtb-super-manifest/raw/master/mtb-super-manifest.xml |
Infineon's supplemental manifests (mirror)
Infineon's supplemental manifests are the supplemental manifests for ModusToolbox ™. They denote the additional boards, example projects, libraries, and library dependencies of ModusToolbox ™ which are not covered in the standard edition .
smartconx_target@Q!w2e3r4t5y6u7i8o9p0||/t5/%E4%BE%8B%E7%A8%8B/Mirror-of-the-ModusToolbox-Manifests-Repositories/td-p/498281
Show LessHi, Support.
I obtained a file named "files for command line utility.zip " from the forum, which includes a method for generating firmware and programming for CY7C65211. In the Decryption Utility directory, using the tool provided, I managed to generate default_CY7C65213-32LTXI_decrypted.cyusbd
from default_CY7C65213-32LTXI.cyusb
.However, after programming this firmware into the CY7C65211 device under Linux, the device can no longer be recognized by Linux.
My goal is to enable USB to SPI functionality support on the CY7C65211 chip. I am unable to generate the corresponding firmware version on Windows in my current situation. Could you provide me with a .cyusb
file that supports USB to SPI functionality for the CY7C65211 chip? Thank you very much.
smartconx_target@Q!w2e3r4t5y6u7i8o9p0||/t5/%E4%BE%8B%E7%A8%8B/CY7C65211-Generate-Firmware/td-p/733987
Show LessI planned this program to show the minimum usage of the basic components of PSoC
and to help testing a new board or peripheral when application is yet to be written.
このプログラムは PSoC を初めて使用する方に基本的なコンポーネントの使い方をお見せするとともに
新しく作った基板や周辺をアプリケーションが出来る前に試せるようにと考えて作ってみました。
More than a couple weeks has passed since I posted CY8CKIT-044 version of this program.
And what I learned during this period is that PSoC 6 is different from PSoC 4!
Anyway, here is the first PSoC 6 version of this program.
このプログラムの CY8CKIT-044 版を投稿してから、既に2週間以上が経ってしまいました。
その間で学んだことは、PSoC 6 は PSoC 4 とは違う!という事でした。
何はともあれ、このプログラムの PSoC 6 用の初版です。
When you build and program or debug, you will see something like below.
Basically the same help message is displayed.
Except the last one and the prompt.
プロジェクトをビルドして書込むかデバッグを開始すると下記のような表示になります。
基本的に前回のものと同じです、
最後の命令とプロンプトを除いては。
Assuming that the E-Ink Shield is mounted on your CY8CKIT-062-BLE.
Enter "i2c" at the prompt.
Now prompt changes to "CM0P:i2c>"
Enter "scan" to scan the I2C bus... it finds a device at 0x68, which is the BMI160 on the E-Ink Shield.
We can read its ID from the register address 0.
So enter "readreg 0", then expected ID of D1 is returned.
CY8CKIT-062-BLE に付いてくる E-Ink シールドを接続した状態で
プロンプトに "i2c" と入力します。
するとプロンプトは "CM0P:i2c>" にかわります。
更に "scan" と入力すると I2C バス上にあるデバイスを探し始め... 0x68 にデバイスがあることが分かります、
これは E-Ink シールドに乗っている BMI160 センサーです。
このセンサはレジスタアドレス 0 を読むと ID を返すことになっています。
そこで "readreg 0" と入力すると、予定通り ID の D1 が返されました。
Now let's try the catch of the day!
Either push "reset" key or Enter "return" to return to the "CM0P:>" prompt.
Then enter "cm4" to switch the core to the CorTex-M4.
The splash says that it is "MCU Tester (CM4)..." and the last command is now "cm0".
Here we can use all commands in the previous mode, except "cm4".
For example, if you enter "i2c" same set of commands are available.
それでは今回の目玉を実験しましょう!
基板の RST ボタンを押すか、"return" コマンドを入力して "CM0P:>" プロンプトに戻ってください。
そこで "cm4" と入力すると、使用コアが CorTex-M4 に変わります。
オープニングメッセージも "MCU Tester (CM4) ..." となってコマンドリストの最後は cm0 に変わっています。
ここで cm0 の時に使えたコマンドは cm4 を除き全て同様に使用できます。
例えば ”i2c" と入力すると I2C モードで使用できた全てのコマンドがここでも使えます。
To return the root prompt, enter "return".
Then enter "mem" to test the Memory Mode.
According to the TRM of PSoC 6/62 SRAM seems to be starting from 0x08000000.
So please enter "dump 0x08000000" to see what in the memory now.
トップレベルのプロンプトに戻るには、"return" を入力します。
次にメモリーモードを試したいので、"mem" と入力してください。
PSoC 6/62 の TRM によると、SRAM は 0x08000000 から始まっているようなので
"dump 0x08000000" と入力して、今、メモリーの中に何が入っているのか見てください。
Enter "return" to go back to the root prompt.
Then enter "cm0" to switch the core to CorTex-M0+.
Now we are home.
再度、トップレベルのプロンプトに戻るのに "return" と入力してください。
その後、"cm0" と入力すると CorTex-M0+ のコアに戻ることができます。
ただいま!
To explain all the commands will take some time and energy, so let me cheat by saying that...
For other commands, please refer to the page of the previous version below.
コマンド全ての説明はかなり長くなってしまいますので、各コマンドについては
先のヴァージョンの説明がある以下の URL をご参照ください。
MCU Tester, a Swiss Army Knife for PSoC (CY8CKIT-044 version)
moto
27-May-2020 First introduction lines were added
28-May-2020 Sensor name corrected to BMI160
28-May-2020 There were source/header for spi and i2c missing with the first attachment. Attached file was replace with 200528A version.
2-Feb-2021 A version for CY8CKIT-062-WiFi-BT was added.
15-Feb-2021 A version for CY8CPROTO-063-BLE was added.
Show Less
Hi,
Recently in a discussion below, I found a Multi-funciton shield (for Arduino).
It has 4 digit hex LEDs, 3 push switches, POT, 4 LEDS, and (probably) a Buzzer.
As it seems to be pretty affordable and I ordered a couple of them.
And I hacked a first version of sample for CY8CKIT-044 and CY8CKIT-046.
Note: Alas, currently I can not upload any more images, so I will try only by text.
(0) When program started, the Hex LEDs show some graphical movements. (Let's call this main)
In main, three buttons (S1, S2, S3) have the following fucntion
S1: Enter ADC Test mode
S2: Enter Stopwatch mode
S3: Enter Clock mode
(1) In ADC Test mode
Measured POT voltage is displayed in 0.000 format.
Changing POT will change the voltage and the value will be reflected.
S1: Return to main
(2) In Stopwatch mode
In Stopwatch mode, measured time is displayed in "00.00" format.
S1: Return to main
S2: Clear the count
S3: Start/Pause the stopwatch
(3) Clock mode
24 hour clock is emulated.
S3: In normal mode, Enter adjust mode
In adjust mode, each click change mode as below
adjust 10 hour place -> adjust 1 hour place -> adjust 10 minute place -> adjust 1 minute place -> normar mode
S2: In adust mode, increment the value of current place.
S1: Return to main.
Note: In this sample, I did not use Buzzer.
moto
P.S. Since the shield assumes 5V I/O, please set the I/O level to 5V with the jumper J9.
Leaving J9 to 3.3V seemed to be not harmfull, but in my case the buzzer was buzzing all the time no matter which level (H/L) of the Buzzer pin. (Probably it requires 5V to be silent) >_<
Show Less
This is an example of the DDS sine signal generator running on PSoC4200M CY8CKIT-044 Pioneer Board.
Like the previous example, this project also uses Double-Buffered DMA to update the IDAC8. The data are being calculated in the real time by DDS, and the IDAC is operated in bidirectional mode, which requires setting IDAC's direction (sign) and magnitude. Project features:
- 32-bit DDS accumulator provides frequency resolution clk_1/2^32 = 480kHz/2^32=0.0001Hz
- Usable range 0 - 20kHz, with some tweaks up to 100kHz
- The output sine is centered around Vref (here Vdd/2 was used)
- The sine amplitude is controlled by a singe resistor R1, default is +/-1V
- Uses CPU to populate the RAM buffer and DMA to update the IDAC
The CPU is used to populate the control and wave data in the temporary RAM buffer {CTRL, data}. The CPU load, however, is quite low, reaching in current example only ~25% of all processor time.
The Double-Buffered DMA uses intermediate RAM Buffer of length 64+64 made of two equal halves, to store the data coming from the data source. The DMA1 consists of two chained Transfer Descriptors TD0 and TD1, copying 2 bytes from the Buffer to the IDAC on each clock. Once TD0 finishes copying the data from the first half of the Buffer, it chains to the TD1, which copies data from the second half of the Buffer and loops back to TD0.
Once TD0 (or TD1) is completed, an interrupt is fired, signaling that this Buffer half needs replenishment (while the other one is busy). At this point processor need to fill the half-Buffer with generated waveform, and wait for the next data request, while the Buffer content is being continuously played without interruption.
Sine wave is generated in real-time using 32-bit software DDS, which return 8-bit sine waveforms based on the lookup table.
The IDAC is used in bipolar mode, both Source and Sink, controlled by the sign of the input data. The IDAC current is converted into voltage using 3.3k resistor and buffered by the Opamp in the transimpedance mode. The Opamp output is centered around the reference voltage (Vdd/2): Vout = 0.5Vdd +/- 1.0V.
By default the project is configured to start playing sine waveform on startup, continuously sweeping the frequency between 1kHz and 2 kHz with period of 20sec.
Project attached contains all necessary files. It was tested using both Creator 4.0 and Creator 4.4.
Figure 1. Project schematic. The sine waveform is generated by DDS_1 and stored in the RAM buffer. It then transferred from the Buffer to the IDAC using DMA. The IDAC output current direction is controlled by the sign of the data. The IDAC operates in transimpedance mode using using 3.3k feedback resistor, producing 0.5Vdd +/- 1.0V signal.
Figure 2. Output waveform. DDS set frequency 1kHz. Yellow - DDS output, centered around Vdd/2. The half-Buffer length to be populated is 64, and DMA sampling clock is 480 kHz, which results in 7.5 kHz DMA TD interrupt rate (period 133 usec). DDS routine calculations to fill the half-buffer takes about 32usec, resulting in a processor load of about 24%.
Figure 3. FFT of the DDS output. Set frequency 1 kHz. The 3-rd harmonic suppression is -45dB, and "side band" suppression is -55dB.
Figure 4. Example of continuously sweeping the DDS frequency between 1kHz and 2 kHz. Scope display persistency time is set to 1 sec.
Figure 5. Project annotation using the PSoC Annotation Library v1.0 and KIT-044. The Red LED pin was used for the performance testing; it raises on ISR routine entry, and lowers on exit. The duty cycle on this pin shows the processor load (~25%). The reference voltage is "stolen" from the hidden Pin_5[0], which is connected to the Vdd/2 onboard source. Capacitors shown are optional and don't affect output significantly.
Show Less
Overview
The purpose of this code example is to show the users how they can handle the different sector architecture types in Infineon serial NOR flash devices.
Requirements
Tool: PSoC® Creator™ 4.4
Programming Language: C (Arm® GCC 5.4.1)
Related Hardware: S25FS512S SPI NOR flash memory, PSoC 6 BLE Pioneer Kit
Software and Driver: Infineon Low Level Driver for SPI Flash
Hardware Setup
This example requires the PSoC 6 MCU’s VDD supply voltage to be set to 1.8V, since the FS-S NOR flash device family works at 1.8V power supply.
Software Setup
This example requires a serial terminal emulator such as PuTTY or Tera Term. Tera Term was used in this example.
Operation
Refer to KBA233140 Hybrid sector architecture of Infineon FL/FS-S serial NOR flash devices to get a better understanding of sector architecture.
The default configuration of the S25FS-S device can be determined by reading the third bit of Non-Volatile Configuration Register 3. The default value of CR3NV[3] bit is 0 indicating hybrid sector architecture. When the device is in hybrid sector architecture mode, the Parameter 4 KB-Sector Erase command (P4E 20h) is used to erase the 4-KB parameter sectors. If Sector Erase command (SE D8h) is applied on the 4-KB parameter sector, it is not affected by the erase. The CR3NV[3] bit is user programmable and can be set to 1 to change the device configuration to uniform sector architecture mode. However, this can be done only once as the bit is One Time Programmable (OTP). When the device is in uniform sector architecture mode, the overlay of the 4-KB parameter sectors is removed and all the sectors in the device are of uniform size (256KB). In this mode, the Sector Erase (SE D8h) command should be used to erase each individual sector and the Parameter 4 KB-Sector Erase command (P4E 20h) does not have any effect on the uniform sectors.
In this code example we have chosen the S25FS512S SPI NOR flash and interfaced it with PSoC 6 using SPI protocol.
Steps performed in the example:
- Initialize UART and SPI
- Read Device ID to make sure HW connections are okay
- Read 5 bytes from the starting address (0x000000). By default, the 4-KB parameter sectors are overlaid at the bottom location
- Program 5 bytes at starting location (0x000000)
- Read 5 bytes from starting location to confirm
- Erase first sector with P4E (0x20) command
- Read 5 bytes from starting location to confirm (erase is successful)
- Read CR3NV register
- If CR3NV[3] bit is 0 (device is in hybrid sector architecture mode)
- Program 5 bytes at starting location
- Read 5 bytes from starting location to confirm
- Erase first sector with SE (0xD8) command
- Read 5 bytes from starting location to confirm (erase is not performed on parameter sector)
- Program CR3NV[3] bit to 1 (change device configuration to uniform sector architecture mode)
- Read CR3NV register to confirm
- Erase first sector with SE (0xD8) command again
- Read 5 bytes from the starting location to confirm (erase is successful)
- Else if CR3NV[3] bit is 1 (device is already in uniform sector architecture mode)
- Print that device is in uniform sector architecture mode
Design and Implementation
Connections:
S25FS512S Flash |
CY8CKIT-062-BLE |
MISO |
P12[1] |
MOSI |
P12[0] |
SCK |
P12[2] |
CS# |
P12[3] |
VCC |
P6_VDD |
VSS |
GND |
PSoC Creator Schematic:
Note: The Slave Select (SS) pin of the SPI block (SPIM_Flash) was disabled. The same pin (P12[3]) was used as a GPIO (Flash_CS) in the project so that the flash CS# line can be controlled manually, as per the requirement of the Infineon sLLD.
Expected Output:
When the example is executed on a fresh S25FS512S NOR flash device (CR3NV[3] = 0)
When the example is re-executed on the same device (CR3NV[3] = 1)
Show Less
OV_THR How should this value be set and understood?
4.6 V / VOVUV_LSB = 3AEH
Why is the 4.6V setting 3AE?
smartconx_target@Q!w2e3r4t5y6u7i8o9p0||/t5/%E4%BE%8B%E7%A8%8B/TLE9012DQU-0x02%E5%9C%B0%E5%9D%80-%E8%AE%BE%E7%BD%AE%E8%BF%87%E5%8E%8B%E9%98%80%E5%80%BC%E5%A6%82%E4%BD%95%E7%90%86%E8%A7%A3/td-p/712120
Show Less
Actually this is a sibling sample of my previous post
I assumed "PCF8574" for I2C - LCD interface modue.
And this time, I tried to create a project from "Empty Project".
Fisrt specify the workspace
MTB WorkBench shows up
Create a new project using Meanu: File > New > ModusToolbox Application
Choose a bsp, this time unfold the "PSoC 6 BSPs"
Selected a board "CY8CPROTO-063-BLE" for BSP
For Application template, I checked "HAL I2C Master" from "Peripherals"
and I named the project "HAL_I2C_CharLCD"
Now a new project is created.
Then we need to import the following source and header files from the attached archive file "i2c_new_files.zip"
i2c_clcd.h, i2c_clcd.c, i2c_utils.h, i2c_utils.c
Then overwrite main.c with the one in the attached archive file.
Actually these could be done just copy and paste these 5 files into the project folder.
Now connect, VCC, GND, SCL(P6[4]), SDA (P6[5]) between the I2C Module and CY8CPROTO-063-BLE.
Building and downloading the project will show "Hello" for 2 seconds then start counting.
moto
Show Less