Page 1 of 1

Pin numbers

Posted: Mon May 03, 2021 4:03 pm
by mebab
I have been using Nucleo L476 and I used Arduino-like pins to address Chip Select (CS) of peripherals. Now, I have developed a new board on STM32L476RG and in Arduino IDE I select:
Board: Nucleo 64 and then
Board Part number: Nucleo L476

I can program the new processor. However, it doesn't work as expected. I guess the pin numbers I have already used on Nucleo 64 are not fit correctly in the new board.
I used to write:

Code: Select all

const int CS_SD = 4; // on Nucleo 
What it should be on STM32L476 when it is connected to pin 57?

Many thanks

Re: Pin numbers

Posted: Mon May 03, 2021 4:35 pm
by fpiSTM
First you should use generic L476RG because Nucleo have probably a specific clock config using HSE bypass.
About the pin number simply use the ST pin like PB6.

Re: Pin numbers

Posted: Tue May 04, 2021 2:36 pm
by mebab
Thanks, fpiSTM.
First you should use generic L476RG because Nucleo have probably a specific clock config using HSE bypass.
About the pin number simply use the ST pin like PB6.
I did so. Again, I can upload the program via ST-Link just after I pull up Boot0 to Vcc. However, it cannot be executed. The reason might be HSE configuration as you mentioned.
Since I deal with ArduinoIDE, I don't know if I should use STM32CubeIDE to change HSE and LSE configurations to use Crystal (as is the case in my board) or I have to do it in some other ways?

Re: Pin numbers

Posted: Tue May 04, 2021 3:21 pm
by mlundin
Try a simple 1Hz blink in the loop, no serials or USB or tricky stuff. That will show if the loop is running and the clock frequency.

As for clocks, look in the variant.cpp file corresponding to your selected core/board/variant, its quite easy to see what clock and frequency is selected. If you board is different you can simply copy the clock setup code from another variant into your sketch and call it from setup(); If the crystal frequency is not default that migh have to be specified in "hal_conf_extra.h" for instance I use a 10MHz external Oscillator on a L432 and I have

Code: Select all

/* HAL Configuration */
#define  HSE_VALUE  10000000

Re: Pin numbers

Posted: Tue May 04, 2021 9:05 pm
by mebab
Thanks mlundin. Helpful hints!
I have defined all pins in STM32CubeIDE and generated code, copied the relevant parts of 'main.cpp' in the 'variant_generic.cpp' file.
I am working on it to get a response and will reply as soon as I find the root cause. The main problem is that I use ST-Link and cannot debug the program effectively!

Re: Pin numbers

Posted: Tue May 04, 2021 9:48 pm
by fpiSTM
No no no. Simply use the generic variant which uses the HSI.
Do not modify the variant files. If you want change the clock config redefine it at sketch level as described in the wiki:
https://github.com/stm32duino/wiki/wiki ... ock_config

Re: Pin numbers

Posted: Thu May 06, 2021 11:14 am
by mebab
Thanks a lot, fpiSTM and mlundin.

I just figured out that I have had another problem that was preventing the normal code operation. I fixed it as well and it works fine now. I am ready to apply your comments now.

Thanks again.