cancel
Showing results for 
Search instead for 
Did you mean: 

Smartcard problem about HAL_SMARTCARD_Receive function

hasan bucak
Associate II

Posted on December 05, 2017 at 12:11

Hi,

I am studying on a smartcard project with STM32f429I- discovery and I've been using st's smartcard software which is in 'STM32Cube MCU Package for STM32F4 series' (you can easily find on st's website).

My purpose is to get ATR and make APDU process. The code gets ATR for me but makes nothing about APDUs.

I can see ATR on I/O line by Logic analyzer. 

but when I debug so that I figure problem out ; I can't see ATR on I/O line and it stucks function of HAL_SMARTCARD_Receive() . This function is supposed to return HAL_OK but it returns as HAL_TIMEOUT. That's why it became little bit inextricable situation for me. 

Could anyone help me or suggest something that I shoud try?

code is below,

this function(HAL_SMARTCARD_Receive() ) is called in SC_AnswerReq(SC_State *SCState, uint8_t *card, uint8_t length) like; 

SC_AnswerReq(SC_State *SCState, uint8_t *card, uint8_t length)

{

...

...

...

HAL_SMARTCARD_Receive(&SCHandle, card, length, SC_RECEIVE_TIMEOUT);

...

...

...

}

the HAL_SMARTCARD_Receive function is below,

HAL_StatusTypeDef HAL_SMARTCARD_Receive(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout)

{

uint16_t* tmp;

uint32_t tickstart = 0U;

if(hsc->RxState == HAL_SMARTCARD_STATE_READY)

{

if((pData == NULL) || (Size == 0))

{

return HAL_ERROR;

}

/* Process Locked */

__HAL_LOCK(hsc);

hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;

hsc->RxState = HAL_SMARTCARD_STATE_BUSY_RX;

/* Init tickstart for timeout managment */

tickstart = HAL_GetTick();

hsc->RxXferSize = Size;

hsc->RxXferCount = Size;

/* Check the remain data to be received */

while(hsc->RxXferCount > 0U)

{

hsc->RxXferCount--;

if(SMARTCARD_WaitOnFlagUntilTimeout(hsc, SMARTCARD_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)

{// it enters into this if structure 

return HAL_TIMEOUT; 

}

tmp = (uint16_t*) pData;

*tmp = (uint8_t)(hsc->Instance->DR & (uint8_t)0xFF);

pData +=1U;

}

/* At end of Rx process, restore hsc->RxState to Ready */

hsc->RxState = HAL_SMARTCARD_STATE_READY;

/* Process Unlocked */

__HAL_UNLOCK(hsc);

return HAL_OK;

}

else

{

return HAL_BUSY;

}

}

0 REPLIES 0