Showing results for 
Search instead for 
Did you mean: 

STM32U585 Smart Card Communication


Hi All
We are testing the STM32U585 Smart Card mode with clock and trying to connect with external SAM module. We are able to get the USART-ISO7816 frame format from the controller but we are unable to capture the ATR value from the module in a correct manner. From the logic analyzer with the setup connected we are getting correct ATR values but inside the controller the ATR values are in the wrong format. Following is the expected card ATR response:


This waveform is obtained from the card reader connected to the STM32U585 board. and the ATR waveform is the correct format as described in the standards. the same signals we are capturing in the STM32U585 debug mode and getting the data as shown in the below figure.


We have used the Smart Card with card clock mode in STM32 side with the following configuration:

  /* USER CODE END USART3_Init 1 */
  hsmartcard3.Instance = USART3;
  hsmartcard3.Init.BaudRate = 9758;
  hsmartcard3.Init.WordLength = SMARTCARD_WORDLENGTH_9B;
  hsmartcard3.Init.StopBits = SMARTCARD_STOPBITS_1_5;
  hsmartcard3.Init.Parity = SMARTCARD_PARITY_EVEN;
  hsmartcard3.Init.Mode = SMARTCARD_MODE_TX_RX;
  hsmartcard3.Init.CLKPolarity = SMARTCARD_POLARITY_LOW;
  hsmartcard3.Init.CLKPhase = SMARTCARD_PHASE_1EDGE;
  hsmartcard3.Init.CLKLastBit = SMARTCARD_LASTBIT_DISABLE;
  hsmartcard3.Init.OneBitSampling = SMARTCARD_ONE_BIT_SAMPLE_DISABLE;
  hsmartcard3.Init.Prescaler = 22;
  hsmartcard3.Init.GuardTime = 0;
  hsmartcard3.Init.NACKEnable = SMARTCARD_NACK_DISABLE;
  hsmartcard3.Init.TimeOutEnable = SMARTCARD_TIMEOUT_DISABLE;
  hsmartcard3.Init.BlockLength = 0;
  hsmartcard3.Init.AutoRetryCount = 0;
  hsmartcard3.Init.ClockPrescaler = SMARTCARD_PRESCALER_DIV1;
  hsmartcard3.AdvancedInit.AdvFeatureInit = SMARTCARD_ADVFEATURE_NO_INIT;

This is the first time we are working with ISO7816 protocol. We need the guidance from the team to find were we went wrong either in the configuration side or in any other side. Awaiting your valuable support in this regard.
Thanks and Regards

Senior II

Values in SmartCard_ATR_Table are 240, 240, 0, 240, 240, 0, ... It seems values are 'noise'. The memory was not written and have previous values. How many bytes do you receive?

If this is not the case, maybe baud rate or smartcard clock are wrong. But I believe this is not the case due to the sequence 240, 240, 0.

The logic analyzer is configured with baud rate 9600 or it auto detects the baud rate?

Hi @AA1 

The logic analyzer detects the baud rate automatically. I think it is some configuration mistake in STM side and that's the reason of not able to receive correct baud rate.
What is the ideal card clock and baud rate for ISO 7816 operation during ATR.
Is there any specific implementation or details wrt STM32U585.
Please suggest.

Guenael Cadier
ST Employee

Hi @PJose.4 
What is the clock frequency provided to the USART instance in STM32U585, that is used for communication with the smartcard ? I would suspect a configuration issue ...
As you are using SMARTCARD_PRESCALER_DIV1, it should be quite low, right ?


Hi @Guenael Cadier 

We have tried with 9758 baud rate and 3.75Mhz clock frequency based on the calculation as shown below:


Fi = 372
Di = 1
ETU = 372/1 * (1/3.63x10^6) = 0.00010247 usec
f = 1/T = 1/0.00010247 us = 9758 bits/sec


The Cube MX configuration setup is as shown below:


And the clock supplied for UART3(SmartCard) is 160MHz



Guenael Cadier
ST Employee

Hi @PJose.4 
This looks correct. I didn't get exactly same value, but I'm not sure it could explain the issue.

I'm trying to explain the method i used.

In your project, you have USART3 clocked with PCLK1 at 160Mhz. On this, a Prescaler (value 22) is applied, leading to have SCLK signal supplied to Smartcard equal to 160/(22*2) => 3.63Mhz.
At startup, communication with smartcard will be based on a F/D ratio of 372/1 (372 clock cycles per etu).
This 372/1 ratio in U5 SMARTCARD ip (USART3) is achieved by implementing a corresponding baudrate of 3.63/372 => 9775.

So in my opinion, I think the exact value of the baudrate to be set in USART3 configuration in Smartcard mode, with a initial clock of 160Mhz, a prescaler equal to 44 (22*2), should be 9775. Not so far from 9758. Sorry :(
For reference, you could have a look at a Smartcard example available on STM32U575 Evaluation board, that is available here.
In this case HSI 16Mhz is used, divided by 4 (prescaler = 2), which provides a 4Mhz clock to the smartcard : baudrate set to 10752 (equals 4.000.000/372).

Hello @Guenael Cadier ,

I am working with @PJose.4 on the same issue. We have actually tried configuring clock w.r.t to the example (ComDMA) i.e 4Mhz @ 10752 bps. Still the issue remains the same. Is there any other things we need to be looking at apart from this. Please do let us know on the same.


Hello @Guenael Cadier,

I have also tried with different microcontroller NUCLEO-STM32U575-Q board. With the configuration mentioned for (ComDMA) i.e 4Mhz @ 10752 bps. Still we are getting same data. PFA for the same.

Waveforms captured via logic analyzer

Data read from u575 STM board




Guenael Cadier
ST Employee

Hi @AdarshTR 
Just tested again the Smartcard example available on STM32U575 Evaluation board using a basic smartcard, and got proper data :


Maybe worth to check configuration of GPIO used for USART3_TX ?
Could it be that reception buffer is filled prior real ATR is sent by the card ?
Just some ideas ...

Hello @Guenael Cadier,

I wanted to know if you are getting this output by using ST8024 IC. As I have researched there is a 11k internal pullup on IOUC line. So can you please let us know what is the configuration done for the same.
This is my current configuration