Changing hardware

Post here all questions related to STM32 core if you can't find a relevant section!
Post Reply
mebab
Posts: 115
Joined: Mon Aug 24, 2020 12:42 pm
Answers: 4

Changing hardware

Post by mebab »

Hi
I have changed my hardware from STM32L476 to STM32L433 and the connections to SPI devices have been tested which are all correct. The new pin numbers have been correctly set. The same program works on STM32L476 but not on STM32L433.
I use Arduino IDE to program the hardware. It looks like either MISO, MOSI, or SCK in SPI1 are the source of this issue because there is nothing else relevant to my test. I have also used/unused pull-up resistors to MISO and MISo and pull-down resistor to SCK but no success!
I didn't do anything to activate SPI1 (used in my application) in STM32L476 and neither did I in STM32L433. Does anybody know what might be different between these two platforms (other than assigned pins)?
Since every pin can be set for some different tasks, how to make sure SPI1 related pins (PA5, PA6, and PA7) are correctly set to be SCK, MISO, and MOSI via Arduino IDE?


Thanks for any help.
by fpiSTM » Thu Oct 28, 2021 9:24 am
As said, you don't specify which board you select, is it the generic L476RG vs the Generic L433RCTxP?
If yes then the default SPI instance does not use the same pins.
For STM32L476RG:

Code: Select all

#ifndef PIN_SPI_MOSI
  #define PIN_SPI_MOSI          PA7
#endif
#ifndef PIN_SPI_MISO
  #define PIN_SPI_MISO          PA6
#endif
#ifndef PIN_SPI_SCK
  #define PIN_SPI_SCK           PA5
#endif

But for STM32L433RCTxP:

Code: Select all

#ifndef PIN_SPI_MOSI
  #define PIN_SPI_MOSI          PA7
#endif
#ifndef PIN_SPI_MISO
  #define PIN_SPI_MISO          PA6
#endif
#ifndef PIN_SPI_SCK
  #define PIN_SPI_SCK           PA1
#endif
As you can see the SCK pin is not the same!
You can try to do SPI.setSCLK(PA5);
Go to full post
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: Changing hardware

Post by mrburnette »

mebab wrote: Tue Oct 26, 2021 1:36 pm ...
I have changed my hardware from STM32L476 to STM32L433 and the connections to SPI devices have been tested which are all correct. The new pin numbers have been correctly set. The same program works on STM32L476 but not on STM32L433.
...
I would suggest going back to basics; that is, use an example program to create a simple test case... First for the -L476 and then move to the -L433. If the test program works, investigate further. If not, post the test program in the forum so that users with both hardware can have a reference program to look into the issue. Ops (that is you) need to provide some software to highlight suspected hardware issues. The more work you do, the better the forum can assist you.
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: Changing hardware

Post by ag123 »

I think normally SPI class itself initialize the pins and hardware SPI.
I've a habit of blinking a LED in all my apps, I'd think it is good practice. If the LED don't even blink or that it blink at a different rate, it points to a problem, e.g.with clocks etc.

After that is working, normally I'd have a section of 'debug' codes, where I probe the external device connected across SPI, e.g. a status register etc.
it should return sane (expected) values. If it doesn't again it points to a problem, likely at the SPI side, e.g. clocks out of sync at the device?
For my tests on ILI9341 LCD, it turns out that the LCD requires pulling a hardware reset pin on the LCD low to trigger that reset.
viewtopic.php?p=5769#p5769
Thereafter, things get in sync, and the LCD works.

And of course, check specs, ref manuals etc. there may be surprises for what you assumed as 'similar' soc.

Hope it helps.
mebab
Posts: 115
Joined: Mon Aug 24, 2020 12:42 pm
Answers: 4

Re: Changing hardware

Post by mebab »

Thanks
ag123 and mrburnette
I tried to write on an SD card. However, I get the same problem. For SD card, it gets stuck in the following code:

Code: Select all

if (!SD.begin(PA3)) {
    Serial.println("initialization failed!");
    }
    


Regardless of the type of SPI device, I am sure that SPI1 (PA5..PA7) that I use is not activated by default. I have to activate it. I didn't have the same problem with STM32L476 where the problem arises with STM32L433!

Do you know how to activate SPI1 via Arduino code?
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Changing hardware

Post by fpiSTM »

Well both variant defines its own default pins for default instance.
As we don't know exactly which target you select, hard to tell.
mebab
Posts: 115
Joined: Mon Aug 24, 2020 12:42 pm
Answers: 4

Re: Changing hardware

Post by mebab »

In STM32L476 that works fine, I use SPI1:
PA5: CK
PA6: MISO
PA7: MOSI
PB5: CS of SD card

In STM32L433 that doesn't work fine, I use the same pins in SPI1:
PA5: CK
PA6: MISO
PA7: MOSI
PA3: CS of SD card

A simple code for writing on SD card is in the following where Initialization fails on SD.begin:

Code: Select all

#include <SPI.h>
#include <SD.h>

File myFile;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
 
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.print("Initializing SD card...");

  if (!SD.begin(PA3)) {
    Serial.println("initialization failed!");
    while (1);
  }
  Serial.println("initialization done.");

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test.txt", FILE_WRITE);

  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3.");
    // close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }

  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop() {
  // nothing happens after setup
}
What I see on Scope:
MOSI = Low ; WIth Pull-up resistor (10k)
MISO = HIGH ; WIth Pull-up resistor (10k)
CLK = LOW ; WIth Pull-down resistor (10k)
CS = HIGH ; WIth Pull-up resistor (10k)
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Changing hardware

Post by fpiSTM »

As said, you don't specify which board you select, is it the generic L476RG vs the Generic L433RCTxP?
If yes then the default SPI instance does not use the same pins.
For STM32L476RG:

Code: Select all

#ifndef PIN_SPI_MOSI
  #define PIN_SPI_MOSI          PA7
#endif
#ifndef PIN_SPI_MISO
  #define PIN_SPI_MISO          PA6
#endif
#ifndef PIN_SPI_SCK
  #define PIN_SPI_SCK           PA5
#endif

But for STM32L433RCTxP:

Code: Select all

#ifndef PIN_SPI_MOSI
  #define PIN_SPI_MOSI          PA7
#endif
#ifndef PIN_SPI_MISO
  #define PIN_SPI_MISO          PA6
#endif
#ifndef PIN_SPI_SCK
  #define PIN_SPI_SCK           PA1
#endif
As you can see the SCK pin is not the same!
You can try to do SPI.setSCLK(PA5);
mebab
Posts: 115
Joined: Mon Aug 24, 2020 12:42 pm
Answers: 4

Re: Changing hardware

Post by mebab »

Thanks fpiSTM!

In fact, there were two problems that are solved now and the system works great:

1. As you mentioned, the default pin number had to be changed for SCK in the new hardware (STM32L433). However, SPI1 didn't work yet.
2. The setting of SystemClock_Config was the second problem. I used to have LSI and MSI as the clock sources in STM32L476. But tried to use LSI and PLLCLK in the new platform and changed the clock frequency values.

I understand that SPI frequency should be suitable for peripheral SPI devices. However, still don't know why it works with PLLCLK and not with MSI in the same clock frequencies.


Thanks again for all the comments and guidance!
Post Reply

Return to “General discussion”