cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_SPI error is not reported even with failed cases in STML4 device

anandhram1988
Associate II

 

HAL_SPI_Transmit(&hspi1, NULL, 0, 0);
uint32_t error = HAL_SPI_GetError(&hspi1);
HAL_SPI_StateTypeDef spiState = HAL_SPI_GetState(&hspi1);

 

above lines of code i expect error = error code
spiState must be error state , but i still gets  error  = 0, spistate = Ready 
anyone knows the reason?

10 REPLIES 10

@anandhram1988 wrote:

spiState must be error state 


Must it?

Why?

 

PS: How to insert source code 

anandhram1988
Associate II

thats the problem i am facing, but not sure why if any error module to be additionally included, but i have added the necessary driver code. 

But why do you think that error should be anything other than zero ?

And why do you think that spistate should be anything other than Ready?

On what do you base those assumptions?

AIUI, error only relates to faults in the actual SPI hardware operation.

In your case, no hardware operation happens - so .error remains at zero, and spistate remains Ready.

 

anandhram1988
Associate II

i can understand this scenario , but in this case i have removed the slave device , in this case the error must be reported?

 

anandhram1988
Associate II

for this test: removing slave i am using the below code:

        spiState1 = HAL_SPI_Transmit(&hspi1, (uint8_t*)buffer[0], 1, 10);
    
    uint32_t error = HAL_SPI_GetError(&hspi1);
    spiState = HAL_SPI_GetState(&hspi1);

That's irrelevant - the code you showed never accesses the SPI at all:

HAL_SPI_Transmit( &hspi1, NULL, 0, 0 );
//                        ^^^^^^^ Look!!

You've given a NULL buffer pointer, and zero length - there is nothing to transmit!

This is an invalid call - it does nothing!

anandhram1988
Associate II

test 1:  L4 with slave device connected 

 

   spiState1 = HAL_SPI_Transmit(&hspi1, (uint8_t*)buffer[0], 110);
    
    uint32_t error = HAL_SPI_GetError(&hspi1);
    spiState = HAL_SPI_GetState(&hspi1);
result : all good
 

test 2:  L4 with no  slave device connected 

 

   spiState1 = HAL_SPI_Transmit(&hspi1, (uint8_t*)buffer[0], 110);
    
    uint32_t error = HAL_SPI_GetError(&hspi1);
    spiState = HAL_SPI_GetState(&hspi1);
result :no error reported.
 
test 3:  L4 with slave device connected but trying to simulate introduce error to get error codes
HAL_SPI_Transmit(&hspi1, NULL, 0, 0);
uint32_t error = HAL_SPI_GetError(&hspi1);
HAL_SPI_StateTypeDef spiState = HAL_SPI_GetState(&hspi1);

 

result  : no error reported

Again, please see How to insert source code 

 


@anandhram1988 wrote:
test 2:  L4 with no  slave device connected 

Think about it: how would the hardware detect that there is no slave attached?

It can't.

You will have to add that in your application.

 


@anandhram1988 wrote:
test 3:  L4 with slave device connected but trying to simulate introduce error to get error codes

So what, exactly, did you do for this "simulation"?

Again, think about whether it produces anything that the SPI hardware could actually detect.

 

These are the possible error codes which can be reported by HAL_SPI_GetError:

/** @defgroup SPI_Error_Code SPI Error Code
  * @{
  */
#define HAL_SPI_ERROR_NONE              (0x00000000U)   /*!< No error                               */
#define HAL_SPI_ERROR_MODF              (0x00000001U)   /*!< MODF error                             */
#define HAL_SPI_ERROR_CRC               (0x00000002U)   /*!< CRC error                              */
#define HAL_SPI_ERROR_OVR               (0x00000004U)   /*!< OVR error                              */
#define HAL_SPI_ERROR_FRE               (0x00000008U)   /*!< FRE error                              */
#define HAL_SPI_ERROR_DMA               (0x00000010U)   /*!< DMA transfer error                     */
#define HAL_SPI_ERROR_FLAG              (0x00000020U)   /*!< Error on RXNE/TXE/BSY/FTLVL/FRLVL Flag */
#define HAL_SPI_ERROR_ABORT             (0x00000040U)   /*!< Error during SPI Abort procedure       */
#if (USE_HAL_SPI_REGISTER_CALLBACKS == 1U)
#define HAL_SPI_ERROR_INVALID_CALLBACK  (0x00000080U)   /*!< Invalid Callback error                 */
#endif /* USE_HAL_SPI_REGISTER_CALLBACKS */
/**
  * @}
  */

See stm32l4xx_hal_spi.h


@anandhram1988 wrote:
test 3:  L4 with slave device connected but trying to simulate introduce error to get error codes
HAL_SPI_Transmit(&hspi1, NULL, 0, 0);
uint32_t error = HAL_SPI_GetError(&hspi1);
HAL_SPI_StateTypeDef spiState = HAL_SPI_GetState(&hspi1);

 

result  : no error reported

We've already been through that one - I explained that the code is invalid, and the results are as expected.