knew stm32duino days ago. What about applicability?

Post Reply
oyster
Posts: 1
Joined: Wed Apr 07, 2021 1:05 am

knew stm32duino days ago. What about applicability?

Post by oyster »

Actually I have learned 8051 many many years ago and know how to program ESP32 via micropython, I started to learn STM32 this year for a project to acquire some data via ADC, process the data in MCU, then the processed data is used both for controlling via DAC and for displaying on TFT.

But the code in keil is not to my taste, ok, maybe I should say, is some hard to remember and tedious for my current knowledge and limited spared time.

I just found stm32duino days ago. It looks easier than coding in keil. I have checked FAQ( including FAQ in web.archive.org) of this forum, but I think I did not find all the answers to my following considerations. So can anyone correct me or give some lights? Thanks.

1. what is the maturity of stm32duino on STM32F103 and STMF407? I think I will meet ADC, DAC, FFT, TFT display with SPI interface, timer and interrupt, RTC, SD storage and PWM in my current project
  • 1.4 as for ADC, DAC and interrupt, does stm32duino support them?
  • 1.5 FFT or the algorithms showed be coined by myself

2. as for TFT display, I knew there are many driver codes for Arduino. Does these codes work on STM32 without modification, well I don't think it is a modification if we only specify which pin is used? Or as a broad question, can stm32duino use other libraries for Arduino?


3. will the code produced by stm32duino share the same or similar speed and binary file size with the code by keil?
  • 3.2 it may be hard to tell the difference between bin file size due to the fact that no one write a full application twice but in 2 different languages/IDEs, i.e. stm32duino and keil

4. can the code, produced by stm32duino, used for closed-source, commercial project. I am lost after reading https://github.com/stm32duino/Arduino_C ... License.md


5. has stm32duino been used in any stable or commercial project?


6. is the code, made by stm32duino, as hard to be cracked as the code by keil?


Thanks
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: knew stm32duino days ago. What about applicability?

Post by mrburnette »

oyster:

Others in the forum may be able to help with specifics, but I am going to make a few general statements:

- This is the tool chain underneath the ArdinoIDE
https://github.com/stm32duino/Arduino_C ... troduction

- "Arduino" is an IDE, a set of CLI build scripts, and a paradigm for keeping things simple. For example, Arduino does "function prototyping" automatically, so this throws some users off. Arduino is generally implemented as a set of wrappers around HAL and CMSIS. As such you may witness some performance concerns but STM has been very diligent to keep wrappers lean.

- Arduino was introduced as an 8-bit implementation and a good deal of 8-bit hardware still exists. Early user libs were generally 8-bit'centric where an "int" was 16-bits. Most modern libs for Arduino check to target architecture (environmental) and can correctly handle int as 32-bits and 16-bits. But not all.

- Lastly, you will need to validate every library to extract specific license. All of these core libraries are under many different licenses.


Good luck,

Ray
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: knew stm32duino days ago. What about applicability?

Post by mrburnette »

oyster:

Others in the forum may be able to help with specifics, but I am going to make a few general statements:

- This is the tool chain underneath the ArdinoIDE when working with STM32
https://github.com/stm32duino/Arduino_C ... troduction

- "Arduino" is an IDE, a set of CLI build scripts, and a paradigm for keeping things simple. For example, Arduino does "function prototyping" automatically, so this throws some users off. Arduino is generally implemented as a set of wrappers around HAL and CMSIS. As such you may witness some performance concerns but STM has been very diligent to keep wrappers lean.

- Arduino was introduced as an 8-bit implementation and a good deal of 8-bit hardware still exists. Early user libs were generally 8-bit'centric where an "int" was 16-bits. Most modern libs for Arduino check to target architecture (environmental) and can correctly handle int as 32-bits and 16-bits. But not all.

- Lastly, you will need to validate every library to extract specific license. All of these core libraries are under many different licenses.


Good luck,

Ray
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: knew stm32duino days ago. What about applicability?

Post by ag123 »

well it is more about personal preferences. some of the codes in particular Arduino based open sourced codes and libraries are released on open sourced licenses such as GPL etc. hence, the derivative works are released under the same licenses. of course if it is GPL, you would run a 'risk' of users asking for your source codes for your 'commercial' product.

stm32duino is a thin layer on top of HAL, it gives you the familiar arduino api that a lot of people prefers as it is simplier
https://www.arduino.cc/reference/en/

but just let say you decide to use STM32Cube IDE which is the 'official' alternative to say an arduino sketch.
a HAL based code could look like this, this just blink a led

Code: Select all

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * <h2><center>© Copyright (c) 2021 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "usb_device.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/

/* USER CODE BEGIN PV */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USB_DEVICE_Init();
  /* USER CODE BEGIN 2 */
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
	HAL_GPIO_WritePin(GPIOC, LED_Pin, ! HAL_GPIO_ReadPin(GPIOC, LED_Pin));
	HAL_Delay(500);

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

/**
  * @brief System Clock Configuration
  * @retval None
  */
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 = 25;
  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();
  }
  /** 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();
  }
}

/**
  * @brief GPIO Initialization Function
  * @param None
  * @retval None
  */
static void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};

  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOH_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin : LED_Pin */
  GPIO_InitStruct.Pin = LED_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(LED_GPIO_Port, &GPIO_InitStruct);

}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

/**
  * @brief  This function is executed in case of error occurrence.
  * @retval None
  */
void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
  __disable_irq();
  while (1)
  {
  }
  /* 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,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
then the arduino sketch (stm32duno core) equivalent

Code: Select all

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_BUILTIN, ! digitalRead(LED_BUILTIN));
  delay(500);
}
so you take your pick ;)
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: knew stm32duino days ago. What about applicability?

Post by fpiSTM »

ag123 wrote: Thu Apr 08, 2021 8:36 am then the arduino sketch (stm32duno core) equivalent

Code: Select all

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_BUILTIN, ! digitalRead(LED_BUILTIN));
  delay(500);
}
so you take your pick ;)
And for all STM32 based boards :mrgreen:
Post Reply

Return to “Let us know a bit about you and your projects”