cancel
Showing results for 
Search instead for 
Did you mean: 

NUCLEO-F401RE and a X-NUCLEO-IHM03A1

addebito
Associate II

Hi at all,

I bought a NUCLEO-F401RE and a X-NUCLEO-IHM03A1.

I've created a STM32CubeIDE project starting from the example "IHM03A1_ExampleFor1Motor" included inside the "STM32CubeExpansion_SPN3_V1.6.0" package.

I downloaded the project on Nucleo F401RE board and everything works fine.

Now I'm trying to integrate this motor example on my project that manage:

- TIM2 32 bit counter (external encoder 1)

- TIM5 32 bit counter (external encoder 2)

- 2 external interrrupt (encoders index to reset the counter values)

- USB OTG used to communicate with a computer as virtual com port

But when I download this new project the firmware hang when I call

BSP_MotorControl_Init(BSP_MOTOR_CONTROL_BOARD_ID_POWERSTEP01, NULL);

Obviusly my project without the motor section works fine.

I think there are some mismatch between the the sample motor project and my project configurations.

Eg:

this is the clock config of the motor sample project

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)
  {
    MyErrorHandler(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)
  {
    MyErrorHandler(1);
  }
}

This is my clock config auto generated by STM32CubeIDE

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_SCALE2);
  /** 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 = 4;
  RCC_OscInitStruct.PLL.PLLN = 72;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLQ = 3;
  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_2) != HAL_OK)
  {
    Error_Handler();
  }
}

0693W000004GmCSQA0.png

0693W000004GmDBQA0.png

I've also welded a XTAL 8 Mz + 2 capacitors on my NUCLEO F401RE and cut off the ST-Link debugger.

Any suggestions will be greatly appreciated.

Thank you so much.

12 REPLIES 12
addebito
Associate II

Thank you all for your kind reply.

I have resolved.

I forgot some configurations inside these init functions.

void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
{
...
}
 
void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* htim_pwm)
{
...
}

addebito
Associate II

Hi @Laurent Ca...​ , I've tasting victory too early....

I've done some test with some commands and the stepper motor works fine but I've another problem that I didn't have before.

Through the computer by the USB Virtual Com Port I send some ascii command to the STM32, but now I can't open the com port on my OS.

Yes, I get an error (10) when I try to open the com port.

This is the QT case error (10 = ERROR_INVALID_PARAMETER).

    case ERROR_INVALID_PARAMETER:
        error.errorCode = QSerialPort::UnsupportedOperationError;
        break;

I've done some test to investigate, follow some informations:

OS: Windows 10

Framework: QT 5.14.2 with QSerialPort class to communicate

STM32: PA11, PA12 (you can see on my first picture in the first post)

Board: NUCLEO-STM32F401RE and X-NUCLEO-IHM03A1

I know, seems like a QT problem, but if I download the old firmware, without all the motor section / initializations the communication works fine !!

if it helps, I can send you the 2 STM32 projects:

  • 1st the USB communication works but without motor
  • 2nd the USB communication doesn't work but with motor

Thank you for your support.

addebito
Associate II

Hi @Laurent Ca...​ , @Karl Hönemann​ , @Community member​ ,

I've done the follow steps.

1) Update the fw package to the last one 1.25.1 inside the ProjectManager0693W0000059YUrQAM.pngTry again but I've the same error

2) Apply the patch called "en.patch_cubef4.zip"

Try again but I've the same error

3) Added these lines of code into the "CDC_Control_FS" function inside the "usbd_cdc_if.c" (thanks google).

    case CDC_GET_LINE_CODING:
    	if (length == 7)
    	{
    		uint32_t bitrate = 9600;
 
    		pbuf[0] = (uint8_t)(bitrate);
    		pbuf[1] = (uint8_t)(bitrate >> 8);
    		pbuf[2] = (uint8_t)(bitrate >> 16);
    		pbuf[3] = (uint8_t)(bitrate >> 24);
    		pbuf[4] = 0; // 1 stop bit
    		pbuf[5] = 0; // parity none
    		pbuf[6] = 8; // datatype
    	}
    break;

Try again and now it's working !!

I'd like to ask you, in your opinion this is the correct way or is a band-aid solution?

Do you have any other suggestions?

Thank you for your support & your time.