cancel
Showing results for 
Search instead for 
Did you mean: 

UM1848 Documentation needs to be updated. It is from February 2016 (DoclD027273 Rev 2) and STM32CubeIDE has changed a lot since then.

KiptonM
Lead

I just bought a NUCLEO-F104RE and the X-NUCLEO-IHM01A1.

The main problem is have is where to put the en.x-cube-spn1 files.

The instructions in Section 3.3 need to be a little clearer and more specific.

Also there is no .ioc file in the software.

Do you build a default (in my case) Nucleo-F401RE board project then start over writing files from the files in en.x-cube-spn1? It does not say.

The compiled help files like X-CUBE-SPN1-HELP.chm does not work right.

I can see the contents, but no text under the contents. Please just give a .pdf of the detailed information and screw the help file.

0693W00000WKvCHQA1.png 

Paragraph 3.3.1.1

Where do the files from the BSP folder go? Do you create a BSP folder in the project? Where? Under Drivers? Or under Core? Or does the .h files go into the /Core/Inc and the .h files go under /Core/Src? Or somewhere else?

Paragraph 3.3.1.2

First paragraph talks about MotorControl/motorcontrol.c/h files.

I searched the entire directory structure and could not find motorcontrol.c or motorcontrol.h!

I did find the motor.h but not where to put it. from the second paragraph.

Paragraph 3.3.1.3

Found the files, but not sure where to put them.

Paragraph 3.3.2

Most of these I was able to figure out because they were already in the project. However I am very concerned about overwriting files like .project and .cproject from 2016 into a Version 1.11.0 STM32CubeIDE because a lot has happened with the IDE since 2016.

16 REPLIES 16
KiptonM
Lead

I copied the file clock_f4.c from the D:\en.x-cube-spn1\STM32CubeExpansion_SPN1_V1.11.0\Projects\Multi\Examples\MotionControl\IHM01A1_ExampleFor1Motor\Src directory to the project Core/Src/ directory. Now it says it cannot create it.

There is no

11:24:21 **** Incremental Build of configuration Debug for project IHM01A1_demo ****

make -j12 all 

arm-none-eabi-gcc -mcpu=cortex-m4 -g3 -c -I"../../../Inc" -I"../../../../../../../../Drivers/BSP/STM32F4xx-Nucleo" -I"../../../../../../../../Drivers/BSP/X-NUCLEO-IHMxx" -I"../../../../../../../../Drivers/BSP/Components/Common" -I"../../../../../../../../Drivers/BSP/Components/l6474" -I"../../../../../../../../Drivers/CMSIS/Include" -I"../../../../../../../../Drivers/CMSIS/Device/ST/STM32F4xx/Include" -I"../../../../../../../../Drivers/STM32F4xx_HAL_Driver/Inc" -x assembler-with-cpp -MMD -MP -MF"startup/startup_stm32f401xe.d" -MT"startup/startup_stm32f401xe.o" --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -o "startup/startup_stm32f401xe.o" "../startup/startup_stm32f401xe.s"

make: *** No rule to make target 'C:/Users/Moravec-Kipton.DOMNDTX/STM32CubeIDE/Src/clock_f4.c', needed by 'Example/User/clock_f4.o'. Stop.

make: *** Waiting for unfinished jobs....

"make -j12 all" terminated with exit code 2. Build might be incomplete.

There is no Example/user/ directory for clock_f4.o. I am guessing the .project or .cproject is not right or I put things in the wrong place because the documentation is not right or incomplete or just 6 years old.

You guys can do better than this.

KiptonM
Lead

The file in question clock_f4.c is the clock initialization that should be in main.c.

void SystemClock_Config(void)
{
  RCC_ClkInitTypeDef RCC_ClkInitStruct;
  RCC_OscInitTypeDef RCC_OscInitStruct;
 
  /* Enable Power Control clock */
  __PWR_CLK_ENABLE();
  
  /* The voltage scaling allows optimizing the power consumption when the device is 
     clocked below the maximum system frequency, to update the voltage scaling value 
     regarding system frequency refer to product datasheet.  */
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
  
  /* Enable HSE Oscillator and activate PLL with HSI as source */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = 16;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  RCC_OscInitStruct.PLL.PLLM = 16;
  RCC_OscInitStruct.PLL.PLLN = 336;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
  RCC_OscInitStruct.PLL.PLLQ = 7;
  if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler(0);
  }
  
  /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 
     clocks dividers */
  RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | 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_2) != HAL_OK)
  {
    Error_Handler(1);
  }
}

If code was being generated by the .ioc file.

This is going to be painful.

KiptonM
Lead

I decided to start over. I hope it is worth it.

I created a standard nucleo-f401re project.

I went into the MX part and configured the clock to give the same results as the Clock_f4.c

I also made the I/O on CN5 and CN9 match the schematics of X-NUCLEO-IHM01A1 in the MX program.

Then I generated the code and compiled. So far so good.

I looked at the two stm32f4xx_hal_msp.c. One from the zip file and the one from the IDE. Lots of differences.

It looks like the files are very different.

The file from the IDE defines the following routines.

void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);

void HAL_MspInit(void)

void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* htim_pwm)

void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)

void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef* htim_pwm)

void HAL_UART_MspInit(UART_HandleTypeDef* huart)

void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)

The one from the Example has:

void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi)

void HAL_SPI_MspDeInit(SPI_HandleTypeDef *hspi)

void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* htim_pwm)

void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef* htim_pwm)

void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim)

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)

Merging will be more of a problem.

KiptonM
Lead

For now I decided to skip the stm32f4xx_hal_msp.c.

I copied the BSP directory under the project Drivers directory. Thhen I started having problems with the files for other processors, so I deleted them.

I also had to go to File->Properties->C/C+Build->Settings->Include paths and add paths for /Drivers/BSP/Components/Common,

/Drivers/BSP/Components/l6477

/Drivers/BSP/STM32F4cc-Nucleo

/Drivers/BSP/X-NUCLEO-IHMxx

So far it compiles without error, but does not do anything.

KiptonM
Lead

So now I am going to work on the /Core/Inc directory. This is the project.

Starting with main.h generated by the Device Configuration tool.(i.e.the .ioc file)

I will edit my project main.h and use the main.h from the zip file.

First copy the lines

#include "x_nucleo_ihmxx.h"
#include "l6474.h"
#ifdef USE_STM32F4XX_NUCLEO
#include "x_nucleo_ihm01a1_stm32f4xx.h"
#endif
#ifdef USE_STM32F0XX_NUCLEO
#include "x_nucleo_ihm01a1_stm32f0xx.h"
#endif
#ifdef USE_STM32L0XX_NUCLEO
#include "x_nucleo_ihm01a1_stm32l0xx.h"
#endif
#ifdef USE_STM32F3XX_NUCLEO
#include "x_nucleo_ihm01a1_stm32f3xx.h"
#endif

from the zip files main.h to just after the lines

/* Private includes ----------------------------------------------------------*/

/* USER CODE BEGIN Includes */

And copy

void SystemClock_Config(void);

void Error_Handler(void);

To under /* Exported functions prototypes ---------------------------------------------*/

(around line 67)

I think that is it. Except you have to select the project in Project Explorer,

Then File->Proprties->c?C++ Build ->Settings -> MCU GCC Compiler ->Preprocessor and add USE_STM32F4XX_NUCLEO to the define symbols

I compiled the project no errors so far.

KiptonM
Lead

Next file in the CORE/Inc directory is stm32f4xx_hal_conf.h

I am just going to ignore the differences for now, the files are structured differently. But what I did notice was there were some changes in what was defined. Specifically the TIM module was not enabled.

The first one uses TIM3. In the Device configuration tool I had Set Channel 2 to PWM Generation CH2 but had forgotten to set the clock source. It should be "Internal Clock". The rest of the parameters I do not know yet.

Went to Project -> Generate Code

Then Project -> Build Target

Still no errors. and HAL_TIM_MODULE_ENABLED is defined.

KiptonM
Lead

Next file is \Core\Inc\stm32f4xx_it.h interrupt handler.

The one from the zip file has 3 Export function prototypes the one generated does not have

void EXTI15_10_IRQHandler(void);

void TIM2_IRQHandler(void);

void TIM4_IRQHandler(void);

I am just going to move them over eventhough I do not think I will need them,

I do not want to mess with it for now.

I will just put them under the

/* USER CODE BEGIN EFP */

The section looks like this now:

/* Exported functions prototypes ---------------------------------------------*/
void NMI_Handler(void);
void HardFault_Handler(void);
void MemManage_Handler(void);
void BusFault_Handler(void);
void UsageFault_Handler(void);
void SVC_Handler(void);
void DebugMon_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
void TIM3_IRQHandler(void);
void SPI1_IRQHandler(void);
/* USER CODE BEGIN EFP */
void EXTI15_10_IRQHandler(void);
void TIM2_IRQHandler(void);
void TIM4_IRQHandler(void);
/* USER CODE END EFP */

 I recompiled and still no errors.

KiptonM
Lead

Now to go to the more complicated Core\Src directory.

I will skip main.c for now. and save that for last.

Looking next at Core/Src/stm32f4xx_it.c for the interrupts.

Looks the same with a couple of extra interrupts.

I went to the device Configuration tool

I had already set up some of the PWM now I have to set up all of them just to make it easy.

But first I will go to System Core -> NVIC and check EXTI Line [15:10] interrupts

Now will go down to Timers -> TIM2

Clock Source -> Internal Clock

Channel 3 -> PWM_Generation CH3

Configuration -> NVIC Interrupt Table -> TIM2 global interrupt -- Check to enable.

Timers -> TIM3

Clock Source -> Internal Clock

Channel 2 -> PWM_Generation CH2

Configuration -> NVIC Interrupt Table -> TIM3 global interrupt -- Check to enable.

Timers -> TIM4

Internal Clock -- Check the box

Channel 2 -> PWM_Generation No Output

Configuration -> NVIC Interrupt Table -> TIM4 global interrupt -- Check to enable.

Go to the PA10 pin, make it an EVENTOUT, and Name it FLAG (User Label)

It looks like something is weird with the timer functions. I will probably have to come back to them.

Meantime Project -> Generate Code

Project -> Build Project

No compile errors.

KiptonM
Lead

Looking at the \Core\Scr\system_stm32f4xx.c

When I compare it to the version in the zip file the new one has some extra stuff for initializing the clock. But I don't think it is anything to worry about.

So no changes.

It looks like stm32f4xx_hal_msp.c has a lot of differences.

The one generated has the following functions:

void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);

void HAL_MspInit(void)

void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi)

void HAL_SPI_MspDeInit(SPI_HandleTypeDef *hspi)

void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)

void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)

void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)

void HAL_UART_MspInit(UART_HandleTypeDef* huart)

void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)

The one in the zip file has:

void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)

void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)

void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* htim_pwm)

void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef* htim_pwm)

void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim)

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)

It looks like I can try to just copy the last 4 routines in the zip file to the end of the generated file.

We will do that and see what happens.

It does compile so far so good.