NUCLEO-F413ZH STM32F413ZHT6 144 pins - blink problem

All about boards manufactured by ST
User avatar
konczakp
Posts: 18
Joined: Sat Jul 25, 2020 8:22 pm

NUCLEO-F413ZH STM32F413ZHT6 144 pins - blink problem

Post by konczakp »

I'm new happy owner of the NUCLEO-F413ZH with some problems at the beginning :/ I have an experience with blue pill and black pill boards with stm32 microprocessor but never worked with Nucleo board. I managed to communicate with the board under Arduino IDE and I'm able to upload compiled program to the board but it seams it is not working. For the beginning I've tried a blink example on one of the built in led but without any success. Here is the sketch:

Code: Select all

void setup() {
  pinMode(PB_0, OUTPUT);
}

void loop() {
  digitalWrite(PB_0, HIGH);   
  delay(1000);                       
  digitalWrite(PB_0, LOW);    
  delay(1000);                       
}

Code: Select all

Sketch uses 15108 bytes (0%) of program storage space. Maximum is 1572864 bytes.
Global variables use 928 bytes (0%) of dynamic memory, leaving 326752 bytes for local variables. Maximum is 327680 bytes.
      -------------------------------------------------------------------
                        STM32CubeProgrammer v2.11.0                  
      -------------------------------------------------------------------

ST-LINK SN  : 066FFF525282494867182729
ST-LINK FW  : V2J39M27
Board       : NUCLEO-F413ZH
Voltage     : 3.25V
SWD freq    : 4000 KHz
Connect mode: Under Reset
Reset mode  : Hardware reset
Device ID   : 0x463
Revision ID : Rev A
Device name : STM32F413/F423
Flash size  : 1.5 MBytes
Device type : MCU
Device CPU  : Cortex-M4
BL Version  : --



Memory Programming ...
Opening and parsing file: sketch_oct17a.ino.bin
  File          : sketch_oct17a.ino.bin
  Size          : 15.25 KB 
  Address       : 0x08000000 


Erasing memory corresponding to segment 0:
Erasing internal memory sector 0
Download in Progress:


File download complete
Time elapsed during download operation: 00:00:00.473

RUNNING Program ... 
  Address:      : 0x8000000
Application is running, Please Hold on...
Start operation achieved successfully
and here are my board setting under Arduino IDE
Board -> Generic STM32F4 series
Port -> /dev/ttyACM0
Debug symbols and core logs -> none
Optimize -> Smallest (-Os default)
Board Part Number -> Generic F413ZHTx
C Runtime Library -> Newlib nano (default)
Upload Method -> STM32CubeProgrammer (SWD)
USB Support -> none
U(S)ART Support -> Enabled (Generic "Serial")
USB Speed -> Low/Full speed

Any help on this?

And second question is how to print on serial (this one connected to board programmer) on black/blue pill it was simple like Serial.begin(9600); Serial.println("test"); ?
by fpiSTM » Wed Oct 19, 2022 7:17 am
Maybe the default system core clock is not correct. You could try to define your own void SystemClock_Config(void).
Copy the one from the Cube project you had in the sketch:

Code: Select all

extern "C" void SystemClock_Config(void) {
//code from cube project
}
Go to full post
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: NUCLEO-F413ZH STM32F413ZHT6 144 pins - blink problem

Post by fpiSTM »

Your sketch is not correct you have to use pin number PB0 instead of pinName PB_0:

Code: Select all

void setup() {
  pinMode(PB0, OUTPUT);
}

void loop() {
  digitalWrite(PB0, HIGH);   
  delay(1000);                       
  digitalWrite(PB0, LOW);    
  delay(1000);                       
}
About Serial as you used the generic and it is automatically generated. Serial default pins are the first one found in the UART array.
So you have to set the correct pins. You can use Serial.setRX() and Serial.setTX() before the Serial.begin() call.
User avatar
konczakp
Posts: 18
Joined: Sat Jul 25, 2020 8:22 pm

Re: NUCLEO-F413ZH STM32F413ZHT6 144 pins - blink problem

Post by konczakp »

This is not working too. I've tried that at the beginning. I also tried with LED 2 and 3. None of them works. When I bought this Nucleo board everything worked just fine (with the vendor firmware installed on board) I was able to choose which led to switch on and the speed of blinking with a on board user button. After I uploaded new sketch from Arduino IDE nothing is working (I don't know how to get this working)

EDIT:
I also updated the onboard st-link under STm32Cube IDE and uploaded some example with led blinking to the board. Under Cube IDE everything works fine. The main difference in uploading sketch to the board is that when uploading in Cube IDE communication led blinks few times red and green. When uploading in Arduino IDE communication led stays red all the time. Some communication error? Maybe it is just erasing the microprocessor but not uploading new sketch ? What I can check?
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: NUCLEO-F413ZH STM32F413ZHT6 144 pins - blink problem

Post by ag123 »

try using Sketch > export compiled binary?
it'd leave the .bin file in your sketch folder.

after that you can use stm32-cube-programmer to flash that bin file using the tool alone.
This could help find out where it breaks
User avatar
konczakp
Posts: 18
Joined: Sat Jul 25, 2020 8:22 pm

Re: NUCLEO-F413ZH STM32F413ZHT6 144 pins - blink problem

Post by konczakp »

Without any luck :/ I've checked the datasheet of the stm32f413zht6 and found that A0 pin on board footprint is connected directly to pin number 37 which is PA3. I've tried to put HIGH on this pin but it is also not responding for the code. So still I have no idea if it is uploading the code correctly and if the pinout is correct or maybe there is something more ... any further advice on this ?

EDIT: Under STM32Cube IDE PA3 works normally and it blinks, same as led 1, 2 and 3 - I've just checked
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: NUCLEO-F413ZH STM32F413ZHT6 144 pins - blink problem

Post by fpiSTM »

Maybe the default system core clock is not correct. You could try to define your own void SystemClock_Config(void).
Copy the one from the Cube project you had in the sketch:

Code: Select all

extern "C" void SystemClock_Config(void) {
//code from cube project
}
User avatar
konczakp
Posts: 18
Joined: Sat Jul 25, 2020 8:22 pm

Re: NUCLEO-F413ZH STM32F413ZHT6 144 pins - blink problem

Post by konczakp »

@fpiSTM BINGO! Blink is working now just fine from Arduino IDE. Is there any place (file) under Arduino IDE that I could change to set this SystemClock_Config ? I don't want to put this config in every each sketch that I'm opening etc. BTW it wierd that there is no need to call this function in setup() function. It is somehow executing while the program starts. Second thing is that the maximum microprocessor speed that I'm able to set up is 96MHz while maximum should be 100MHz (I've tried to set 100 under STM32CubeIDE but the software was not able to find any solution to set this speed) Here is the code that it is working.

Code: Select all

extern "C" void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Configure the main internal regulator output voltage
  */
  __HAL_RCC_PWR_CLK_ENABLE();
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLM = 8;
  RCC_OscInitStruct.PLL.PLLN = 384;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
  RCC_OscInitStruct.PLL.PLLQ = 8;
  RCC_OscInitStruct.PLL.PLLR = 2;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

  /** Initializes the CPU, AHB and APB buses clocks
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK)
  {
    Error_Handler();
  }
}

// PB0 - LED1
// PB7 - LED2
// PB14 - LED3
#define LED_PIN PB14

void setup() {
  //SystemClock_Config();
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_PIN, HIGH);   
  delay(1000);                       
  digitalWrite(LED_PIN, LOW);    
  delay(1000);                       
}
Moreover, there are some other standard settings in the main.c generated by the STM32CubeIDE (code below) Do You thing that there is something I should also copy to Arduino IDE to avoid any future problems?

Code: Select all

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2022 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/
UART_HandleTypeDef huart3;

PCD_HandleTypeDef hpcd_USB_OTG_FS;

/* USER CODE BEGIN PV */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART3_UART_Init(void);
static void MX_USB_OTG_FS_PCD_Init(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART3_UART_Init();
  MX_USB_OTG_FS_PCD_Init();
  /* USER CODE BEGIN 2 */

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
	  // LED ON
	        HAL_GPIO_WritePin(GPIOB, LD1_Pin, GPIO_PIN_SET);
	        HAL_Delay(1000);
	        // LED OFF
	        HAL_GPIO_WritePin(GPIOB, LD1_Pin, GPIO_PIN_RESET);
	        HAL_Delay(1000);
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Configure the main internal regulator output voltage
  */
  __HAL_RCC_PWR_CLK_ENABLE();
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLM = 8;
  RCC_OscInitStruct.PLL.PLLN = 384;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
  RCC_OscInitStruct.PLL.PLLQ = 8;
  RCC_OscInitStruct.PLL.PLLR = 2;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

  /** Initializes the CPU, AHB and APB buses clocks
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK)
  {
    Error_Handler();
  }
}

/**
  * @brief USART3 Initialization Function
  * @param None
  * @retval None
  */
static void MX_USART3_UART_Init(void)
{

  /* USER CODE BEGIN USART3_Init 0 */

  /* USER CODE END USART3_Init 0 */

  /* USER CODE BEGIN USART3_Init 1 */

  /* USER CODE END USART3_Init 1 */
  huart3.Instance = USART3;
  huart3.Init.BaudRate = 115200;
  huart3.Init.WordLength = UART_WORDLENGTH_8B;
  huart3.Init.StopBits = UART_STOPBITS_1;
  huart3.Init.Parity = UART_PARITY_NONE;
  huart3.Init.Mode = UART_MODE_TX_RX;
  huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart3.Init.OverSampling = UART_OVERSAMPLING_16;
  if (HAL_UART_Init(&huart3) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN USART3_Init 2 */

  /* USER CODE END USART3_Init 2 */

}

/**
  * @brief USB_OTG_FS Initialization Function
  * @param None
  * @retval None
  */
static void MX_USB_OTG_FS_PCD_Init(void)
{

  /* USER CODE BEGIN USB_OTG_FS_Init 0 */

  /* USER CODE END USB_OTG_FS_Init 0 */

  /* USER CODE BEGIN USB_OTG_FS_Init 1 */

  /* USER CODE END USB_OTG_FS_Init 1 */
  hpcd_USB_OTG_FS.Instance = USB_OTG_FS;
  hpcd_USB_OTG_FS.Init.dev_endpoints = 6;
  hpcd_USB_OTG_FS.Init.speed = PCD_SPEED_FULL;
  hpcd_USB_OTG_FS.Init.dma_enable = DISABLE;
  hpcd_USB_OTG_FS.Init.phy_itface = PCD_PHY_EMBEDDED;
  hpcd_USB_OTG_FS.Init.Sof_enable = ENABLE;
  hpcd_USB_OTG_FS.Init.low_power_enable = DISABLE;
  hpcd_USB_OTG_FS.Init.lpm_enable = DISABLE;
  hpcd_USB_OTG_FS.Init.battery_charging_enable = ENABLE;
  hpcd_USB_OTG_FS.Init.vbus_sensing_enable = ENABLE;
  hpcd_USB_OTG_FS.Init.use_dedicated_ep1 = DISABLE;
  if (HAL_PCD_Init(&hpcd_USB_OTG_FS) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN USB_OTG_FS_Init 2 */

  /* USER CODE END USB_OTG_FS_Init 2 */

}

/**
  * @brief GPIO Initialization Function
  * @param None
  * @retval None
  */
static void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};

  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOH_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();
  __HAL_RCC_GPIOD_CLK_ENABLE();
  __HAL_RCC_GPIOG_CLK_ENABLE();

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_3, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOB, LD1_Pin|LD3_Pin|LD2_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(USB_PowerSwitchOn_GPIO_Port, USB_PowerSwitchOn_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin : USER_Btn_Pin */
  GPIO_InitStruct.Pin = USER_Btn_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(USER_Btn_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pin : PA3 */
  GPIO_InitStruct.Pin = GPIO_PIN_3;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /*Configure GPIO pins : LD1_Pin LD3_Pin LD2_Pin */
  GPIO_InitStruct.Pin = LD1_Pin|LD3_Pin|LD2_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /*Configure GPIO pin : USB_PowerSwitchOn_Pin */
  GPIO_InitStruct.Pin = USB_PowerSwitchOn_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(USB_PowerSwitchOn_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pin : USB_OverCurrent_Pin */
  GPIO_InitStruct.Pin = USB_OverCurrent_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(USB_OverCurrent_GPIO_Port, &GPIO_InitStruct);

}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

/**
  * @brief  This function is executed in case of error occurrence.
  * @retval None
  */
void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
  __disable_irq();
  while (1)
  {
  }
  /* USER CODE END Error_Handler_Debug */
}

#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: NUCLEO-F413ZH STM32F413ZHT6 144 pins - blink problem

Post by fpiSTM »

OK. Thanks for the test. It means the default clock config for the generic has an issue. Could you open an issue on Github.
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: NUCLEO-F413ZH STM32F413ZHT6 144 pins - blink problem

Post by fpiSTM »

You could update it here:
https://github.com/stm32duino/Arduino_C ... ic_clock.c

Looking at this config, it is not correct as it use the HSE for generic mcu while it should use HSI by default.
User avatar
konczakp
Posts: 18
Joined: Sat Jul 25, 2020 8:22 pm

Re: NUCLEO-F413ZH STM32F413ZHT6 144 pins - blink problem

Post by konczakp »

@fpiSTM Okey, I've made changes locally to my Arduino IDE and it is working fine so made same changes on github with a pull request. I hope I did everything okey on github as I never used it in this way :) Please check
Post Reply

Return to “STM boards (Discovery, Eval, Nucleo, ...)”