Author Topic: OpenSTM32 vs STM32Cube IDE - Same code, different results.  (Read 1340 times)

0 Members and 1 Guest are viewing this topic.

Offline gvz

  • Contributor
  • Posts: 8
  • Country: 00
OpenSTM32 vs STM32Cube IDE - Same code, different results.
« on: August 12, 2019, 08:52:53 pm »
Hi !

I am testing a simple free running UART transmission with an STM32 micro-controller, with both Openstm32 and STM32Cube IDE, and I am experiencing different results between these two different Eclipse based IDEs.

The code is this one:

Code: [Select]
#ifdef HSE_VALUE
#undef HSE_VALUE
#define HSE_VALUE 8000000UL
#endif

#include "stm32f4xx.h"
#include "stm32f4xx_hal_rcc.h"
#include "stm32f4xx_hal_gpio.h"
#include "stm32f4xx_hal_uart.h"

UART_HandleTypeDef huart1;

void Error_Handler()
{
;
}

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_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 = 5;
  RCC_OscInitStruct.PLL.PLLN = 200;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLQ = 4;
  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_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV4;

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

static void MX_USART1_UART_Init(void)
{
  huart1.Instance = USART1;
  huart1.Init.BaudRate = 115200;
  huart1.Init.WordLength = UART_WORDLENGTH_8B;
  huart1.Init.StopBits = UART_STOPBITS_1;
  huart1.Init.Parity = UART_PARITY_NONE;
  huart1.Init.Mode = UART_MODE_TX_RX;
  huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  if (HAL_UART_Init(&huart1) != HAL_OK)
  {
    Error_Handler();
  }
}

static void MX_GPIO_Init(void)
{
  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOH_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();
}

int main(void)
{
HAL_Init();

SystemClock_Config();
MX_USART1_UART_Init();
MX_GPIO_Init();

while(1)
HAL_UART_Transmit(&huart1, "*", 1, 0);
}

But flashing the device with OpenSTM32 (right click on project location → Target → Program chip), the device doesn't do anything..
The console output is:

Code: [Select]
22:28:32 **** Programming project ad371_hal_uart_test on chip ****
/usr/local/share/OpenSTM32/plugins/fr.ac6.mcu.externaltools.openocd.linux64_1.23.0.201904120827/tools/openocd/bin/openocd -f stm32.flash.2695625463917824173.cfg -s /home/gvz/projects/AD371/SOFT/stm32/ad371_hal_uart_test -s /usr/local/share/OpenSTM32/plugins/fr.ac6.mcu.debug_2.5.0.201904120827/resources/openocd/st_scripts -c "program Release/ad371_hal_uart_test.elf verify reset " -c shutdown
Open On-Chip Debugger 0.10.0+dev-00021-g524e8c8 (2019-04-12-08:33)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
srst_only separate srst_nogate srst_open_drain connect_assert_srst
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 8000 kHz
adapter_nsrst_delay: 100
Info : clock speed 8000 kHz
Info : STLINK v2 JTAG v31 API v2 SWIM v7 VID 0x0483 PID 0x3748
Info : using stlink api v2
Info : Target voltage: 1.741579
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
Info : Stlink adapter speed set to 4000 kHz
Info : STM32F407VGTx.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08001138 msp: 0x20020000
configuring PLL
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
Info : Stlink adapter speed set to 4000 kHz
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
adapter speed: 4000 kHz
** Programming Started **
auto erase enabled
Info : device id = 0x10076413
Info : flash size = 1024kbytes
target halted due to breakpoint, current mode: Thread
xPSR: 0x61000000 pc: 0x20000046 msp: 0x20020000
wrote 16384 bytes from file Release/ad371_hal_uart_test.elf in 0.626915s (25.522 KiB/s)
** Programming Finished **
** Verify Started **
target halted due to breakpoint, current mode: Thread
xPSR: 0x61000000 pc: 0x2000002e msp: 0x20020000
target halted due to breakpoint, current mode: Thread
xPSR: 0x61000000 pc: 0x2000002e msp: 0x20020000
verified 6004 bytes in 0.101388s (57.830 KiB/s)
** Verified OK **
** Resetting Target **
shutdown command invoked

22:28:33 Build Finished (took 912ms)

STM32Cube IDE only allows Debug option to reflash the chip, but it works... I am not a fan of STM32Cube IDE, because among other things (it has many known issues), it can erase your custom code if you change something from Cube setup and re-genarate code (that's what I experienced).

Do someone have an idea how to solve this issue with OpenSTM32 ?
I think this is due to an openocd script. How can I edit the "Program chip" setup in Eclipse ?
Any hint ?

Thanks.
g.
 

Offline hansd

  • Contributor
  • Posts: 24
  • Country: au
Re: OpenSTM32 vs STM32Cube IDE - Same code, different results.
« Reply #1 on: August 12, 2019, 09:38:59 pm »
Hi, you have to setup your debug configurations. Expand Debug icon and select Debug Configurations. Also STM32CubeIDE does not delete your code it is the integrated CubeMX.
 

Offline gvz

  • Contributor
  • Posts: 8
  • Country: 00
Re: OpenSTM32 vs STM32Cube IDE - Same code, different results.
« Reply #2 on: August 13, 2019, 07:40:15 am »
you have to setup your debug configurations.
What should I do with Debug configuration ? Isn't it already configured ?

[attachimg=1]

[attachimg=2]

[attachimg=3]
 

Offline gvz

  • Contributor
  • Posts: 8
  • Country: 00
Re: OpenSTM32 vs STM32Cube IDE - Same code, different results.
« Reply #3 on: August 13, 2019, 08:08:23 am »
Also STM32CubeIDE does not delete your code it is the integrated CubeMX.
I reconfirm that if you apply some change to IC setup, the STM32CubeMX erase your custom code and re-generate it as its default (retested now with the main.c).
 

Offline gvz

  • Contributor
  • Posts: 8
  • Country: 00
Re: OpenSTM32 vs STM32Cube IDE - Same code, different results.
« Reply #4 on: August 13, 2019, 08:30:12 am »
OK it works.

I was missing code for alternate function of GPIO and clock for the UART.

 :popcorn:
 

Offline thm_w

  • Super Contributor
  • ***
  • Posts: 2213
  • Country: ca
Re: OpenSTM32 vs STM32Cube IDE - Same code, different results.
« Reply #5 on: August 13, 2019, 09:39:30 pm »
I reconfirm that if you apply some change to IC setup, the STM32CubeMX erase your custom code and re-generate it as its default (retested now with the main.c).

I'm assuming here it works the same way as CubeMX, you need to insert your custom code between the tags right:
Code: [Select]
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {

  put your code here ONLY

    /* USER CODE END WHILE */


There were also options in cubemx to make a back up of the old code before regenerating it, maybe the IDE has similar options.
 

Offline gvz

  • Contributor
  • Posts: 8
  • Country: 00
Re: OpenSTM32 vs STM32Cube IDE - Same code, different results.
« Reply #6 on: August 16, 2019, 10:33:41 pm »
thm_w, you are right.  :-+
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf