Errors compiling SPI.setSSEL()

Post here first, or if you can't find a relevant section!
Post Reply
DrMN
Posts: 22
Joined: Sun Dec 04, 2022 3:37 pm

Errors compiling SPI.setSSEL()

Post by DrMN »

Hi,

I am using a NUCLEO-144 F722ZE. I am trying to enable CS pin management by the SPI engine.

Here is a sample code

Code: Select all

#define SPI_SPEED 50000000
SPISettings spi_settings( SPI_SPEED, MSBFIRST, SPI_MODE0);

const int CNVSTPin = 10;
const int SDIPin = 11;
const int SDOPin = 12;
const int CLKPin = 13;

SPI.setSSEL(CNVSTPin);

// To be called from setup()
void setupSPI() {

#ifndef MANAGED_SPI_SEL
  // SPI library takes care of the other pins
  DIGITALWRITE(CNVSTPin, LOW);
#endif
  
  SPI.begin();
}  
And, here is the first error message:
/home/nelson/Projects/TeensyDataAcquistion/SPI_Instrumenation_Project/Firmware/Arduino_Benchmark_240901/Arduino_Benchmark_240901.ino:425:1: error: 'SPI' does not name a type; did you mean 'SPI1'?
425 | SPI.setSSEL(PC10);
| ^~~
| SPI1

exit status 1
So, we change SPI.setSSEL(PC10); to SPI1.setSSEL(PC10);, and here is the new error message:
In file included from /home/nelson/.arduino15/packages/STMicroelectronics/hardware/stm32/2.8.1/system/Drivers/CMSIS/Device/ST/STM32F7xx/Include/stm32f7xx.h:117,
from /home/nelson/.arduino15/packages/STMicroelectronics/hardware/stm32/2.8.1/cores/arduino/../../libraries/SrcWrapper/inc/stm32_def.h:36,
from /home/nelson/.arduino15/packages/STMicroelectronics/hardware/stm32/2.8.1/cores/arduino/../../libraries/SrcWrapper/inc/clock.h:19,
from /home/nelson/.arduino15/packages/STMicroelectronics/hardware/stm32/2.8.1/cores/arduino/wiring_time.h:23,
from /home/nelson/.arduino15/packages/STMicroelectronics/hardware/stm32/2.8.1/cores/arduino/wiring.h:38,
from /home/nelson/.arduino15/packages/STMicroelectronics/hardware/stm32/2.8.1/cores/arduino/Arduino.h:36,
from /home/nelson/Projects/TeensyDataAcquistion/SPI_Instrumenation_Project/Firmware/Arduino_Benchmark_240901/Arduino_Benchmark_240901.ino:44:
/home/nelson/.arduino15/packages/STMicroelectronics/hardware/stm32/2.8.1/system/Drivers/CMSIS/Device/ST/STM32F7xx/Include/stm32f722xx.h:1106:43: error: expected ')' before '*' token
1106 | #define SPI1 ((SPI_TypeDef *) SPI1_BASE)
| ~ ^
/home/nelson/Projects/TeensyDataAcquistion/SPI_Instrumenation_Project/Firmware/Arduino_Benchmark_240901/Arduino_Benchmark_240901.ino:425:1: note: in expansion of macro 'SPI1'
425 | SPI1.setSSEL(PC10);
| ^~~~
/home/nelson/.arduino15/packages/STMicroelectronics/hardware/stm32/2.8.1/system/Drivers/CMSIS/Device/ST/STM32F7xx/Include/stm32f722xx.h:1106:43: error: expected ')' before '*' token
1106 | #define SPI1 ((SPI_TypeDef *) SPI1_BASE)
| ~ ^
/home/nelson/Projects/TeensyDataAcquistion/SPI_Instrumenation_Project/Firmware/Arduino_Benchmark_240901/Arduino_Benchmark_240901.ino:425:1: note: in expansion of macro 'SPI1'
425 | SPI1.setSSEL(PC10);
| ^~~~

exit status 1

Compilation error: exit status 1
So, what's wrong?

Thank you
by fpiSTM » Tue Sep 17, 2024 7:37 am
DrMN wrote: Mon Sep 16, 2024 6:55 pm So everyone who reads this has the answer, it is pin D24, position 17 in the left column of the 20 pin connector CN7, where it is covered if you use the arduino adapter shield for uno.
To sumup this topic:
First issue was a wrong Class method usage producing a build issue.
Second, the pin used (D10 alias PD14) has no hardware SSEL capability producing a call to an erro handler. Possible value are PA4 or PA15.
Go to full post
Composite
Posts: 12
Joined: Fri Feb 16, 2024 11:09 pm

Re: Errors compiling SPI.setSSEL()

Post by Composite »

fpiSTM
Posts: 1944
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 108
Location: Le Mans
Contact:

Re: Errors compiling SPI.setSSEL()

Post by fpiSTM »

And also you called a method outside a function. Put the call inside the setup function.
DrMN
Posts: 22
Joined: Sun Dec 04, 2022 3:37 pm

Re: Errors compiling SPI.setSSEL()

Post by DrMN »

Okay, it is moved inside the setup routine. I tried that originally. It doesn't work.

In this excerpt, with managed ssel not enabled, setup() completes and the message in loop() "waiting for command" is received and displayed in the serial monitor. But if setSSEL() is called, no messages appear in the serial monitor. So, apparently it does not complete setup().

Code: Select all

    #define SPI_SPEED 50000000
    SPISettings spi_settings( SPI_SPEED, MSBFIRST, SPI_MODE0);

    const int CNVSTPin = 10;
    const int SDIPin = 11;
    const int SDOPin = 12;
    const int CLKPin = 13;
    
    //#define MANAGED_SPI_SEL
    
    // To be called from setup()
    void setupSPI() {
    
      pinMode(CNVSTPin,     OUTPUT);   
      DIGITALWRITE(CNVSTPin, LOW);

    #ifdef MANAGED_SPI_SEL
      SPI.setSSEL(CNVSTPin);
    #endif
  
      SPI.begin();
    }  

and,

Code: Select all

void setup() {

  // initialize the digital pins
  pinMode(INPIN,INPUT);
  pinMode(OUTPIN,OUTPUT);
  pinMode(SPAREPIN,OUTPUT);

  // ------------------------------
  // Setup the MCU Cycle Counter
  setupCYCCNT();
  elapsed_cycles_start();

  // ------------------------------
#ifdef HAS_TIMER
  setupTimer();
#endif
  
  // ------------------------------
  // Setup the onboard ADCs
  adcSetup();

  // ------------------------------
  // SPI library takes care of the other pins
  setupSPI();
  
  // ------------------------------
  Serial.begin(9600);
  delay(100);
  
  // Messages displayed at startup
  Serial.println( versionstr );
  Serial.println( authorstr );

  Serial.print("// F_CPU: "); Serial.print(F_CPU/1e6);  Serial.println(" MHz.");
#ifdef F_BUS
  Serial.print("// F_BUS: "); Serial.print(F_BUS/1e6);  Serial.println(" MHz.");
#endif

#ifdef ADC_F_BUS
  Serial.print("// ADC_F_BUS: "); Serial.print(ADC_F_BUS/1e6); Serial.println(" MHz.");
#endif

  measureoverhead();

}

Code: Select all

    void loop() {
    
      uint16_t nlen = 0;
      char *pc;
    
      uint8_t pin;
    
      uint16_t u16tmp;

      Serial.println("waiting for command");
  
      if ((nlen=Serial.readBytesUntil('\n',rcvbuffer,sizeof(rcvbuffer)-1))) {
    
        blink();

       etc....
[\code]
fpiSTM
Posts: 1944
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 108
Location: Le Mans
Contact:

Re: Errors compiling SPI.setSSEL()

Post by fpiSTM »

I think you used the maple core which does not have this api.
DrMN
Posts: 22
Joined: Sun Dec 04, 2022 3:37 pm

Re: Errors compiling SPI.setSSEL()

Post by DrMN »

Where is the control for that?

And how would it compile if the symbol does not exist?
fpiSTM
Posts: 1944
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 108
Location: Le Mans
Contact:

Re: Errors compiling SPI.setSSEL()

Post by fpiSTM »

Ok. Sorry I misread and thought you always got build issue. Your sketch seems not complete and some syntac are strange like DIGITALWRITE.
I will test next week.

Which core version you used?
fpiSTM
Posts: 1944
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 108
Location: Le Mans
Contact:

Re: Errors compiling SPI.setSSEL()

Post by fpiSTM »

Looking at the pinout, D10 on STM32F722 is PD14 which does not have the hardware SPI CS so that is normal your code hangs.
If you had enabled the core logs or enable the Optimize for debugging,

You will see this message:

Code: Select all

Error: ./libraries/SrcWrapper/src/stm32/pinmap.c (299)
when core tried to initialize the pin for SSEL, it could not find it as it is not correct. It is up to user to provide correct pin.
DrMN
Posts: 22
Joined: Sun Dec 04, 2022 3:37 pm

Re: Errors compiling SPI.setSSEL()

Post by DrMN »

So everyone who reads this has the answer, it is pin D24, position 17 in the left column of the 20 pin connector CN7, where it is covered if you use the arduino adapter shield for uno.
fpiSTM
Posts: 1944
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 108
Location: Le Mans
Contact:

Re: Errors compiling SPI.setSSEL()

Post by fpiSTM »

DrMN wrote: Mon Sep 16, 2024 6:55 pm So everyone who reads this has the answer, it is pin D24, position 17 in the left column of the 20 pin connector CN7, where it is covered if you use the arduino adapter shield for uno.
To sumup this topic:
First issue was a wrong Class method usage producing a build issue.
Second, the pin used (D10 alias PD14) has no hardware SSEL capability producing a call to an erro handler. Possible value are PA4 or PA15.
Post Reply

Return to “General discussion”