Code doesn't seem to run Nucleo-F401RE

Post here all questions related to STM32 core if you can't find a relevant section!
quasio
Posts: 1
Joined: Fri Jul 17, 2020 10:47 am

Code doesn't seem to run Nucleo-F401RE

Post by quasio »

Hi All,
been trying to get this STM32 Nucleo - F401RE working. Downloaded the stm32 core libraries (1.9.0) for arduino 1.8.9.

Managed to update STLink to V2.J37.M26 ( attached picture) as the flasher asked to.
flashed_stlink.png
flashed_stlink.png (42.39 KiB) Viewed 9157 times
The settings i used to flash:
settings.jpg
settings.jpg (58.42 KiB) Viewed 9157 times
And then it seemed to be able to flash the Nucleo F401RE using STM32Cubeprogrammer(SWD) , the default program of blinking led light dissapeared.
flashswd.png
flashswd.png (24.88 KiB) Viewed 9157 times
However it doesn't seem the program runs. I did the default blink led sketch and nothing, and then tried to look at the serial monitor (for other programs with serial.println and also nothing.)

Anyone know what i'm doing wrong?

(thanks in advance)
User avatar
fpiSTM
Posts: 1723
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Code doesn't seem to run Nucleo-F401RE

Post by fpiSTM »

Hi,

all seems right. I've tested with the latest STLink FW V2.J37.M26 and it works.

Did you made some change on the jumper configuration or soldier bridge?

Could you try with the mass storage upload method ?
pablomuro
Posts: 5
Joined: Wed Nov 18, 2020 1:27 pm

Re: Code doesn't seem to run Nucleo-F401RE

Post by pablomuro »

Hi,
Did You solved the problem?
I have the same problem here, my Nucleo F401RE works perfectly on STM32 Cube IDE, but in Arduino, all the responses from IDE are ok, but the programs not run, even if I click on the reset button. However, if I select in the boards manager, the "Core Board F401RCT6" all the functions works, but the serial communication didn't work. The upload method that I'm using is STM Cube Programmer(SWD).
I will attach the images below.
Best regards.
Configs.png
Configs.png (82.28 KiB) Viewed 8552 times
IMG_20201118_105641455~2.jpg
IMG_20201118_105641455~2.jpg (80.32 KiB) Viewed 8552 times
mlundin
Posts: 94
Joined: Wed Nov 04, 2020 1:20 pm
Answers: 6
Location: Sweden

Re: Code doesn't seem to run Nucleo-F401RE

Post by mlundin »

For the Nucleo board use "Nucleo-64" and not "Generic STM32F4 series", then select "Nucleo F401RE"

What code are you trying to run?
pablomuro
Posts: 5
Joined: Wed Nov 18, 2020 1:27 pm

Re: Code doesn't seem to run Nucleo-F401RE

Post by pablomuro »

Thanks.
But if I set "Nucleo-64" and not "Generic STM32F4 series", then select "Nucleo F401RE", nothing works, the response of Arduino is ok, but the board didn't work.
pablomuro
Posts: 5
Joined: Wed Nov 18, 2020 1:27 pm

Re: Code doesn't seem to run Nucleo-F401RE

Post by pablomuro »

const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin = PA5; // Analog output pin that the LED is attached to

int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)

void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}

void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(analogOutPin, outputValue);

// print the results to the Serial Monitor:
Serial.print("sensor = ");
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);

// wait 2 milliseconds before the next loop for the analog-to-digital
// converter to settle after the last reading:
delay(2);
}
mlundin
Posts: 94
Joined: Wed Nov 04, 2020 1:20 pm
Answers: 6
Location: Sweden

Re: Code doesn't seem to run Nucleo-F401RE

Post by mlundin »

The photo looks like an X3 crystal has been added, in that case the clock configuration must be changed in SystemClock_Config(void) defined in variant.cpp
pablomuro
Posts: 5
Joined: Wed Nov 18, 2020 1:27 pm

Re: Code doesn't seem to run Nucleo-F401RE

Post by pablomuro »

I added the 8MHz crystal and it's capacitors triyng to solve the problem, but this didn't help. I think that the problem is the clock configuration, becouse even if I use the clock from the st-link(default source clock), the results are the same. I will try to do that you recomended and post the results here.
Thanks.
ag123
Posts: 1653
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: Code doesn't seem to run Nucleo-F401RE

Post by ag123 »

just 2cents, and out of curiosity not tested

try to find
variants/NUCLEO_F4x1RE/variant.cpp
in the location of your installed core source codes
https://github.com/stm32duino/Arduino_C ... t.cpp#L137

Code: Select all

WEAK void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {};

  /* Configure the main internal regulator output voltage */
  __HAL_RCC_PWR_CLK_ENABLE();
#ifdef ARDUINO_NUCLEO_F401RE
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
#else /* ARDUINO_NUCLEO_F411RE */
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
#endif
  /* Initializes the CPU, AHB and APB busses clocks */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
#ifdef ARDUINO_NUCLEO_F401RE
  RCC_OscInitStruct.PLL.PLLM = 8;
  RCC_OscInitStruct.PLL.PLLN = 336;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
  RCC_OscInitStruct.PLL.PLLQ = 7;
#else /* ARDUINO_NUCLEO_F411RE */

next try my little python script that play with frequencies
viewtopic.php?f=41&t=78
copy that code by clicking 'select all', then control-C
you would need to edit that to start searching at a lower frequency say fmin 80mhz
then goto say https://www.python.org/shell/
and run it there, sample output:

Code: Select all

Python 3.8.0 (default, Nov 14 2019, 22:29:45) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> #!/usr/bin/python3
... #FHSE in mhz
... FHSE = 8
>>> 
>>> #cpu search frequency range
... fmin = 80
>>> fmax = 110
>>> 
>>> #clk1 = clk / m
... m = list(range(1,64))
>>> #vco = clk1 * n
... n = list(range(0,512))
>>> #vco / p = system clock - mcu speed (not systick)
...
FHSE: 8 m: 1 n: 24 p: 2 (RCC_PLLP_DIV2) q: 4 fusb: 48.0 fcpu: 96.0
FHSE: 8 m: 1 n: 42 p: 4 (RCC_PLLP_DIV4) q: 7 fusb: 48.0 fcpu: 84.0
FHSE: 8 m: 1 n: 48 p: 4 (RCC_PLLP_DIV4) q: 8 fusb: 48.0 fcpu: 96.0
FHSE: 8 m: 1 n: 54 p: 4 (RCC_PLLP_DIV4) q: 9 fusb: 48.0 fcpu: 108.0
FHSE: 8 m: 2 n: 48 p: 2 (RCC_PLLP_DIV2) q: 4 fusb: 48.0 fcpu: 96.0
FHSE: 8 m: 2 n: 84 p: 4 (RCC_PLLP_DIV4) q: 7 fusb: 48.0 fcpu: 84.0
...
FHSE: 8 m: 7 n: 378 p: 4 (RCC_PLLP_DIV4) q: 9 fusb: 48.0 fcpu: 108.0
FHSE: 8 m: 8 n: 192 p: 2 (RCC_PLLP_DIV2) q: 4 fusb: 48.0 fcpu: 96.0 <<<
FHSE: 8 m: 8 n: 336 p: 4 (RCC_PLLP_DIV4) q: 7 fusb: 48.0 fcpu: 84.0 <<<
FHSE: 8 m: 8 n: 384 p: 4 (RCC_PLLP_DIV4) q: 8 fusb: 48.0 fcpu: 96.0
FHSE: 8 m: 8 n: 432 p: 4 (RCC_PLLP_DIV4) q: 9 fusb: 48.0 fcpu: 108.0
FHSE: 8 m: 9 n: 216 p: 2 (RCC_PLLP_DIV2) q: 4 fusb: 48.0 fcpu: 96.0...
>>> 
for
FHSE 8 mhz
m : 8
n: 336
p: 4 (RCC_PLLP_DIV4)
q: 7
you get a 84mhz system clock on the stm32f401 which is according to specs
Last edited by ag123 on Wed Nov 18, 2020 5:56 pm, edited 2 times in total.
mlundin
Posts: 94
Joined: Wed Nov 04, 2020 1:20 pm
Answers: 6
Location: Sweden

Re: Code doesn't seem to run Nucleo-F401RE

Post by mlundin »

Since the external 8MHz signal from the STLink has been replaced by an 8MHz crystal, the internal oscillator must be active and not bypassed. Therefore I think you must replace the line:

Code: Select all

  RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
with

Code: Select all

RCC_OscInitStruct.HSEState = RCC_HSE_ON;
Post Reply

Return to “General discussion”