OpenSTM32 vs STM32Cube IDE - Same code, different results. - Page 1
Forum section: electronics / general

author: gvz
author_rank: Contributor
timestamp: August 12, 2019, 08:52:53 pm
content: 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:#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: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 shutdownOpen On-Chip Debugger 0.10.0+dev-00021-g524e8c8 (2019-04-12-08:33)Licensed under GNU GPL v2For bug reports, readhttp://openocd.org/doc/doxygen/bugs.htmlsrst_only separate srst_nogate srst_open_drain connect_assert_srstInfo : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWDadapter speed: 8000 kHzadapter_nsrst_delay: 100Info : clock speed 8000 kHzInfo : STLINK v2 JTAG v31 API v2 SWIM v7 VID 0x0483 PID 0x3748Info : using stlink api v2Info : Target voltage: 1.741579Info : Unable to match requested speed 8000 kHz, using 4000 kHzInfo : Stlink adapter speed set to 4000 kHzInfo : STM32F407VGTx.cpu: hardware has 6 breakpoints, 4 watchpointsInfo : Listening on port 3333 for gdb connectionstarget halted due to debug-request, current mode: ThreadxPSR: 0x01000000 pc: 0x08001138 msp: 0x20020000configuring PLLInfo : Unable to match requested speed 8000 kHz, using 4000 kHzInfo : Stlink adapter speed set to 4000 kHzInfo : Unable to match requested speed 8000 kHz, using 4000 kHzadapter speed: 4000 kHz** Programming Started **auto erase enabledInfo : device id = 0x10076413Info : flash size = 1024kbytestarget halted due to breakpoint, current mode: ThreadxPSR: 0x61000000 pc: 0x20000046 msp: 0x20020000wrote 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: ThreadxPSR: 0x61000000 pc: 0x2000002e msp: 0x20020000target halted due to breakpoint, current mode: ThreadxPSR: 0x61000000 pc: 0x2000002e msp: 0x20020000verified 6004 bytes in 0.101388s (57.830 KiB/s)** Verified OK **** Resetting Target **shutdown command invoked22: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.

author: hansd
author_rank: Contributor
timestamp: August 12, 2019, 09:38:59 pm
content: 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.

author: gvz
author_rank: Contributor
timestamp: August 13, 2019, 07:40:15 am
content: Quote from: hansd on August 12, 2019, 09:38:59 pmWhat should I do with Debug configuration ? Isn't it already configured ?

author: gvz
author_rank: Contributor
timestamp: August 13, 2019, 08:08:23 am
content: Quote from: hansd on August 12, 2019, 09:38:59 pmI 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).

author: gvz
author_rank: Contributor
timestamp: August 13, 2019, 08:30:12 am
content: OK it works.I was missing code for alternate function of GPIO and clock for the UART.

author: thm_w
author_rank: Super Contributor
timestamp: August 13, 2019, 09:39:30 pm
content: Quote from: gvz on August 13, 2019, 08:08:23 amI'm assuming here it works the same way as CubeMX, you need to insert your custom code between the tags right:Code:/* 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.

author: gvz
author_rank: Contributor
timestamp: August 16, 2019, 10:33:41 pm
content: thm_w, you are right.