trying to write a blink sketch for STM32F4 discovery board

Discussions concerning TrueSTUDIO for STM32 9.0.0 and later versions.

Moderators: Markus Girdland, Mattias Norlander

vixo
Posts: 1
Joined: Mon Jan 07, 2019 5:21 pm

trying to write a blink sketch for STM32F4 discovery board

Postby vixo » Mon Jul 08, 2019 2:01 pm

Hi, I'm trying to write a simple blink sketch using an STM32F4(07) discovery board, CubeMX and Atollic truestudio. I can't find any walkthrough guides which cover this exact constellation of products, so I'm trying to mix and match and I can't get my code to build properly.

I used the cubeMX program to select pd12-15 as GPIO output and then the debug in sys mode to debug wire (i'm assuming this is appropriate for my discovery board?). The clock configuration seems to be set so I can't alter it (I'm guessing because i've chosen the discovery board which has default settings?) I don't know what to do with the tools section, I just left it blank. I select truestudio in the toolchain/IDE section and open the project.

This creates a project with a lot of stuff that I have no idea about contained within it. it is much more complicated than the code snippet recommended in this tutorial - http://embeddedsystemengineering.blogsp ... e-led.html which is very simple and easy to understand. Instead I get this -

Code: Select all

#include "main.h"
 
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
 
int main(void)
{
 
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
 
  /* Configure the system clock */
  SystemClock_Config();
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
 
  while (1)
  {
    
  }
}
 
 
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 CPU, AHB and APB busses clocks
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
  /** Initializes the CPU, AHB and APB busses clocks
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
 
  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  {
    Error_Handler();
  }
}
 
static void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
 
  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOD_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();
 
  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15, GPIO_PIN_RESET);
 
  /*Configure GPIO pins : PD12 PD13 PD14 PD15 */
  GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
 
}
 
 
void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
 
  /* 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,
     tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */


Which i almost understand, but I don't know how the code in the other example built for the same discovery board (although with a different IDE) can be so simple in comparison. Nevertheless, this code does not compile - trueStudio says "fatal error: arm_math.h: no such file or directory" Which I don't understand because a) i don't know why I need math.h (it's not called anywhere in the program) and b) if I follow the dropdown boxes in the left bar I can go in to drivers>CMSIS>DSP>source>BasicMathFunctions> arm_shift_q15.c and math.h is listed under there, all of these foldeers are highlighted by a red 'x' in a box, but the compiler can't seem to find the file which I can see following those links??

I also tried to paste the code from the simpler example (from the link above) but this also creates an error.

can anyone help me out?

frank_ee
Posts: 103
Joined: Wed Apr 05, 2017 5:08 pm
Location: USA

Re: trying to write a blink sketch for STM32F4 discovery board

Postby frank_ee » Sun Jul 21, 2019 7:11 pm

Hello,

A very simple way is:
1. Create a new basic Atollic project based on the STM32F4 MCU, not the board.
2. Compile the project and fix any missing file errors.
3. Download the basic project to the board. This will require a debug setup.
4. Create a CubeMX project for the STM32F4 board add the GPIO feature. Make sure the clock settings are correct.
5. Copy the generated code into the Atollic project folder.
6. Compile and fix any problems.
7. Download to flash and test.


Return to “TrueSTUDIO for STM32 discussions”

Who is online

Users browsing this forum: No registered users and 0 guests