AnsweredAssumed Answered

Migrating SPI from stm32f4xx(407, 417) to stm32f7xx(746) - please help

Question asked by pustobayev.roman on Jan 13, 2016
Latest reply on Jan 16, 2016 by pustobayev.roman

Hi to everybody! Sorry in advance forduplicating already existing theme ([DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Porting%20STM32F4%20SPI%20-%20STM32F7%20SPI&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=132]This), but, think i have a problem with a different kind.
I use STM32f7xx HAL, CMSIS libraries. Next i will show some code, there isnothing special, but only initialization of SPI/GPIOS and trying toreceive/transmitt from/to (ENC28j60 
Datasheet - the target to comm. with, TSC2046 Datasheet - target to test spi). 

Initialization of spi :

    SpiHandle_Enc28j60.Instance                         = SPI4;
    SpiHandle_Enc28j60.Init.BaudRatePrescaler           = SPI_BAUDRATEPRESCALER_8;
    SpiHandle_Enc28j60.Init.Direction                             = SPI_DIRECTION_2LINES;
    SpiHandle_Enc28j60.Init.CLKPhase                 = SPI_PHASE_1EDGE;
    SpiHandle_Enc28j60.Init.CLKPolarity             = SPI_POLARITY_LOW;
    SpiHandle_Enc28j60.Init.CRCCalculation    =SPI_CRCCALCULATION_DISABLE;
    SpiHandle_Enc28j60.Init.CRCPolynomial                  = 7;
    SpiHandle_Enc28j60.Init.DataSize                             =SPI_DATASIZE_8BIT;
    SpiHandle_Enc28j60.Init.FirstBit                                =SPI_FIRSTBIT_LSB;
    SpiHandle_Enc28j60.Init.NSS                                      = SPI_NSS_SOFT;
    SpiHandle_Enc28j60.Init.TIMode                               = SPI_TIMODE_DISABLE; (for TSC2046 ti mode must beenabled)
    SpiHandle_Enc28j60.Init.Mode                                  =SPI_MODE_MASTER;  

    SpiHandle_Enc28j60.Init.NSSPMode             =SPI_NSS_PULSE_DISABLED;

if(HAL_SPI_Init(&SpiHandle_Enc28j60) !=HAL_OK)
{
}
SPI initialization code for enc28j60 chip and tsc2046 differs only inTI/Motorolla modes (motorolla for enc28j60) 

With my clock config i've got an 6.20 MBauds/s spi speed.

Initialization of GPIOS :


/*definitions*/
enum DeviceIOPins {
    
    enc28j60_reset_pin  = GPIO_PIN_8,   /*PI*/
    enc28j60_int_pin     = GPIO_PIN_13, /*PC*/
    
    spi4_miso_pin       = GPIO_PIN_5, /*PE*/
    spi4_mosi_pin       = GPIO_PIN_6, /*PE*/
    spi4_sck_pin         = GPIO_PIN_2, /*PE*/
    spi4_cs_pin           = GPIO_PIN_3,/*PE*/
    
};


#define enc28j60_reset_port GPIOI
#define enc28j60_int_port   GPIOC


#define spi4_miso_port      GPIOE
#define spi4_mosi_port      GPIOE
#define spi4_sck_port       GPIOE
#define spi4_cs_port        GPIOE
/*definitions*/



gpio_alt_init(spi4_miso_port, spi4_miso_pin,GPIO_SPEED_HIGH,                      GPIO_MODE_INPUT,GPIO_AF5_SPI4);
gpio_alt_init(spi4_mosi_port, spi4_mosi_pin, GPIO_SPEED_HIGH,                      GPIO_MODE_OUTPUT_PP,GPIO_AF5_SPI4);
gpio_alt_init(spi4_sck_port, spi4_sck_pin, GPIO_SPEED_HIGH,                GPIO_MODE_OUTPUT_PP,GPIO_AF5_SPI4);
gpio_pin_init(spi4_cs_port, spi4_cs_pin, GPIO_SPEED_HIGH, GPIO_MODE_OUTPUT_PP);


/*
PS: in stm32f7xx datasheet i found that theneeded pins of spi's are mapped throught GPIO_AF5 function
*/

first time i had to try receive/transmitt func throught 
HAL_SPI_TransmitReceive(&SpiHandle, buf,buf, n, timeout);

but programm get stuck inside this function when waiting for RXNE flag resetstate:

/..../
    if((hspi->RxXferCount > 0)&& ((hspi->Instance->SR &SPI_FLAG_RXNE) == SPI_FLAG_RXNE))
      {
       if(hspi->RxXferCount > 1)
        {
         *((uint16_t*)hspi->pRxBuffPtr) = hspi->Instance->DR;
         hspi->pRxBuffPtr += sizeof(uint16_t);
         hspi->RxXferCount -= 2;
         if(hspi->RxXferCount <= 1)
          {
            /*set fiforxthreshold before to switch on 8 bit data size */
           SET_BIT(hspi->Instance->CR2, SPI_RXFIFO_THRESHOLD);
          }
        }
        else
        {
         (*hspi->pRxBuffPtr++) =  *(__IO uint8_t *)&hspi->Instance->DR;
         hspi->RxXferCount--;
        }
      }
      if(Timeout !=HAL_MAX_DELAY)
      {
        if((Timeout == 0)|| ((HAL_GetTick()-tickstart) > Timeout))
        {
         hspi->State = HAL_SPI_STATE_READY;
         __HAL_UNLOCK(hspi);
          returnHAL_TIMEOUT;
        }
      }
    }
/...../


and program can wait forever, i try to connect CS wire to any another pin andhas the same result. I also want to admitt, that i'm also followed to themoderator recomendations from previous post (
[DEAD LINK http://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Porting%20STM32F4%20SPI%20-%20STM32F7%20SPI&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=132]This) :

1- how it doesnot work exactly? 
2- Where it getstuck?
3- Whendebugging, are there any error flags or missed configuration bits? - any errors or somethingsuspicuous
4- TheSTM32F42xxx/F43xxx and STM32F74xxx/F75xxx implement different features on theSPI, I suggest you to have a look to the SPI paragraph in the AN4660 Application note about Migration of microcontroller applicationsfrom STM32F42xxx/STM32F43xxx to STM32F74xxx/STM32F75xxx - Yes, i considered allis written there about spi's.
Also try tostart from SPI examples under STM32Cube F7 package, it may be very helpful:
STM32Cube_FW_F7_V1.1.0\Projects\STM32746G-Discovery\Examples\SPI- The same result...

for TSC2046 and ENC28j60 i can't got it work... - TSC2046 already testedwith 
stm32f417vet6 chip. I have my own designed developing board, and there i hadalready check the electric signals goes from MCU to testing chips. I can watchthe SPI SCK pulses with low-noisly fronts, CS signal also fine, data that comesout from mosi pin is also valid.
PS : i always (where it can be rational) use CMSIS HAL libraries.
Please Help ! Best regards, Roman, DPR.

PS: Sorry for my disgusting english, Thx in advance, You 're doing a big work:)

PS: I had found some info in erratasheet (it refers to i2c errata)- 

/.../
When the following sequence is used, the condition of the synchronization issue isprevented and the BSY bit works correctly. The BSY flag then can be used to recognizeend of any transmission transaction (including the case of bidirectional mode whenRXNE is not raised):
– Write last data to data register.
– Poll TXE till it becomes high to ensure the data transfer has started.
– Disable SPI by clearing SPE while the last data transfer is still on going.
– Poll the BSY bit till it becomes low
/.../

What is that means? I need to poll for BSY  flag ?

Outcomes