cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 ST25DV library

isaacseeto
Associate III

Hi, I recently found this library for the ST25DV and I was wondering if anyone had an example code I could follow. I am interested in using the fast transfer mode of the ST25DV to send data from my STM32 to a phone.

This is the Github library: https://github.com/STMicroelectronics/stm32-st25dv?tab=readme-ov-file 

Thanks 

1 ACCEPTED SOLUTION

Accepted Solutions

Hello, 

You are missing one step to enable the mailbos, which is writing to regsiter MB_CTRL_Dyn, and set the MB_EN bit (bit0) to 1. This is enabling the mailbox.

Please, see post Re: Write on Mailbox via Android APP (ST25DV64KC) - STMicroelectronics Community
which is exactly the same question.

Best regards.

View solution in original post

3 REPLIES 3
Cedric Dalban
ST Employee

Hello Isaac,

looking at your message I have some few comments.

1) The following package on st.com may fit your need: STSW-ST25DV002.
This package contains the FTM component with some example code.
Another package on st.com (STSW-ST25R-LIB) is using the FTM component and is also providing some example code. I warmly recommend you to have a look to both packages and related examples.

 

2) The packages contain a file (...\Middlewares\ST\ST25FTM\Docs\PortingFTM.txt) listing main actions to port the old FTM in your application to the new version (in case the github is not aligned with it).

 

3) Last point, you can find some few documentation on st.com related to the FTM:
- AN5512: details the FTM component APIs
- UM2949: details the FTM protocol
- UM3078: details the use of FTM component on Linux

Hoping all these info will help.

Best regards,
Cedric.

Hi,

I was looking at the STSW-ST25DV002 package but I am having trouble understanding what HAL i2c commands are being called. I can see the general process for enabling FTM but I am getting errors when trying to implement it myself. I have been able to read the IC reference number of the device.

From my understanding this is the process for enabling FTM:

1. Present password to start i2c session

2. Write to MB_Mode register and enable FTM

3. Write to message to the mailbox 

If possible would you have a working example of using the HAL i2c commands to implement the above steps?

(I am getting HAL_ERROR) 

Edit: This is what I have tried to start a i2c session

#include "stm32f1xx_hal.h"
#include "st25dv04k.h" // Include ST25DV header if available

#define ST25DV_I2C_ADDRESS 0x53 // I2C address of the ST25DV
#define I2C_PASSWORD_ADDRESS 0x0900 // I2C_PWD register address
#define I2C_SSO_DYN_ADDRESS 0x2004 // I2C_SSO_Dyn register address
#define I2C_PASSWORD_LENGTH 8 // I2C password is 64 bits (8 bytes)

// Example I2C password (stand in)
const uint8_t i2c_password[I2C_PASSWORD_LENGTH] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};

// Function to present the I2C password twice as per the ST25DV protocol
HAL_StatusTypeDef ST25DV_PresentI2CPassword(const uint8_t *password) {
uint8_t validation_code = 0x09; // Validation code
HAL_StatusTypeDef status;

// Send the I2C password twice, along with validation code
status = HAL_I2C_Mem_Write(&hi2c1, (ST25DV_I2C_ADDRESS << 1) | 0x02, I2C_PASSWORD_ADDRESS, I2C_MEMADD_SIZE_16BIT, (uint8_t *)password, I2C_PASSWORD_LENGTH, HAL_MAX_DELAY);
if (status != HAL_OK) return status; // Check for errors

status = HAL_I2C_Mem_Write(&hi2c1, (ST25DV_I2C_ADDRESS << 1) | 0x02, I2C_PASSWORD_ADDRESS, I2C_MEMADD_SIZE_16BIT, &validation_code, 1, HAL_MAX_DELAY);
if (status != HAL_OK) return status; // Check for errors

// Send the password again (second copy)
status = HAL_I2C_Mem_Write(&hi2c1, (ST25DV_I2C_ADDRESS << 1) | 0x02, I2C_PASSWORD_ADDRESS, I2C_MEMADD_SIZE_16BIT, (uint8_t *)password, I2C_PASSWORD_LENGTH, HAL_MAX_DELAY);

return status; // Return final status
}

// Function to check if the I2C security session is open
HAL_StatusTypeDef ST25DV_CheckI2CSessionOpen(uint8_t *session_status) {
// Read the I2C_SSO_Dyn register (dynamic register to check session status)
return HAL_I2C_Mem_Read(&hi2c1, ST25DV_I2C_ADDRESS << 1, I2C_SSO_DYN_ADDRESS, I2C_MEMADD_SIZE_16BIT, session_status, 1, HAL_MAX_DELAY);
}

int main(void) {
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_I2C1_Init();

HAL_StatusTypeDef status;
uint8_t session_status = 0x00;

// Present the I2C password to open the session
status = ST25DV_PresentI2CPassword(i2c_password);
if (status != HAL_OK) {
printf("Error presenting I2C password\n");
Error_Handler();
}

// Check if the I2C session is open by reading I2C_SSO_Dyn
status = ST25DV_CheckI2CSessionOpen(&session_status);
if (status != HAL_OK) {
printf("Error reading I2C_SSO_Dyn register\n");
Error_Handler();
}

if (session_status == 0x01) {
printf("I2C security session opened successfully\n");
} else {
printf("Failed to open I2C security session\n");
Error_Handler();
}

// Rest of the code for enabling Fast Transfer Mode (FTM) and using the mailbox...

while (1) {
// Main loop
}
}

Regards,

Isaac

Hello, 

You are missing one step to enable the mailbos, which is writing to regsiter MB_CTRL_Dyn, and set the MB_EN bit (bit0) to 1. This is enabling the mailbox.

Please, see post Re: Write on Mailbox via Android APP (ST25DV64KC) - STMicroelectronics Community
which is exactly the same question.

Best regards.