AnsweredAssumed Answered

NSS hardware control works on 407VG, but not on 405RG

Question asked by Aberg.Denny on Feb 4, 2016
Latest reply on Feb 5, 2016 by waclawek.jan
I want to use the hardware control of SPI3-NSS pin. I wrote a code for it on the Discovery board with the STM407VG and it works as intended. I use the drivers from the older Discovery bundle, not the STMCube. Upon the command 'SPI_Cmd(SPI3, ENABLE);' the NSS pin goes down as intended, and upon the command 'SPI_Cmd(SPI3, DISABLE);' the NSS pin goes back up, just as it should. But when I download the code to the STM405RG chip which is the target for the Project, nothing happens on the pin. I can't find an errata, does anyone know if the 405RG is defect?

Update: I was sure the problem was solved, and edited the post. However, the problem remains: with identical code and using pull-up or no-pull on the target boards make no difference. The code works on the 407 but not on the 405. Here below is the relevant setup code I use.


  // Initilize SPI
  SPI_InitTypeDef SPI_InitStruct;

  // Set default values in SPI_InitStruct:
  // SPI_InitStruct->SPI_Direction = SPI_Direction_2Lines_FullDuplex;
  // SPI_InitStruct->SPI_Mode = SPI_Mode_Slave;
  // SPI_InitStruct->SPI_DataSize = SPI_DataSize_8b;
  // SPI_InitStruct->SPI_CPOL = SPI_CPOL_Low;
  // SPI_InitStruct->SPI_CPHA = SPI_CPHA_1Edge;
  // SPI_InitStruct->SPI_NSS = SPI_NSS_Hard;
  // SPI_InitStruct->SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
  // SPI_InitStruct->SPI_FirstBit = SPI_FirstBit_MSB;
  // SPI_InitStruct->SPI_CRCPolynomial = 7;

  // Customize:
  SPI_InitStruct.SPI_Mode = SPI_Mode_Master;
#ifdef targetSTMF405RG
  SPI_InitStruct.SPI_NSS = SPI_NSS_Soft; //workaround for the 405 target
  SPI_InitStruct.SPI_DataSize = SPI_DataSize_16b;
  SPI_InitStruct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256;

  // Initilize GPIO for SPI
  //GPIO_InitTypeDef GPIO_InitStruct;
  // Reset GPIO init structure parameters values
  // GPIO_InitStruct->GPIO_Pin  = GPIO_Pin_All;
  // GPIO_InitStruct->GPIO_Mode = GPIO_Mode_IN;
  // GPIO_InitStruct->GPIO_Speed = GPIO_Speed_2MHz;
  // GPIO_InitStruct->GPIO_OType = GPIO_OType_PP;
  // GPIO_InitStruct->GPIO_PuPd = GPIO_PuPd_NOPULL;
  //GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_12;
  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_5;
  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_Init(GPIOB, &GPIO_InitStruct);

  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_4;
  GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP; // borde vara PuPd_UP enl Maximkortet
#ifdef targetSTMF405RG
  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT; //workaround
  GPIO_Init(GPIOA, &GPIO_InitStruct);
  // See datasheet DM00037051.pdf, Table 9 columns AF5 and AF6 for pin mapping
#ifdef targetSTMF407VG
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource4, GPIO_AF_SPI3); // SPI3_NSS
#ifdef targetSTMF405RG
  GPIO_SetBits(GPIOA, GPIO_Pin_4);
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource3, GPIO_AF_SPI3); // SPI3_SCK
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource5, GPIO_AF_SPI3); // SPI3_MOSI

  SPI_Init(SPI3, &SPI_InitStruct);
#ifdef targetSTMF407VG
  SPI_SSOutputCmd(SPI3, ENABLE);