Loading...
 

SW4STM32 and SW4Linux fully supports the STM32MP1 asymmetric multicore Cortex/A7+M4 MPUs

   With System Workbench for Linux, Embedded Linux on the STM32MP1 family of MPUs from ST was never as simple to build and maintain, even for newcomers in the Linux world. And, if you install System Workbench for Linux in System Workbench for STM32 you can seamlessly develop and debug asymmetric applications running partly on Linux, partly on the Cortex-M4.
You can get more information from the ac6-tools website and download (registration required) various documents highlighting:

System Workbench for STM32


printf with openocd on makefile project

Hello, I want to compile a project which uses printf() through openocd on my linux machine by using a makefile. I am working with a STM32F031C6 (STEVAL-PTOOL1V1). I have follow some tutorials to do that but I’m getting linking errors. I followed what is described in ((https://www.openstm32.org/forumthread164#threadId798|this comment)) and my code looks like this.

#include "main.h"
#include <stdio.h>
#include <stdlib.h>

/* Private variables ---------------------------------------------------------*/
UART_HandleTypeDef huart1;

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART1_UART_Init(void);
extern void initialise_monitor_handles(void);

/* Private user code ---------------------------------------------------------*/
int _write(int file, char *ptr, int len){
  HAL_UART_Transmit(&huart1, (unsigned char*)ptr, len, HAL_MAX_DELAY);
  return len;
}

int main(void)
{
  initialise_monitor_handles();
  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
  MX_USART1_UART_Init();
  int counter = 0;
  while (1)
  {
    printf("Current count = %d\r\n", counter++);
    HAL_Delay(500);
  }
}


void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};

  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  {
    Error_Handler();
  }
  PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1;
  PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK1;
  if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  {
    Error_Handler();
  }
}

static void MX_USART1_UART_Init(void) {
  huart1.Instance = USART1;
  huart1.Init.BaudRate = 9600;
  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;
  huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  if (HAL_UART_Init(&huart1) != HAL_OK)
  {
    Error_Handler();
  }
}

static void MX_GPIO_Init(void)
{
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();
}

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

void assert_failed(uint8_t *file, uint32_t line)
{
}
#endif /* USE_FULL_ASSERT */


I also added the liker flags as described in the post as follows:
{CODE}
LDFLAGS = $(MCU) -specs=nosys.specs -specs=nano.specs -specs=rdimon.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,cref -Wl,gc-sections -lc -lrdimon
{CODE}

And I’m getting this error:
{CODE}
in function `_lseek’:
syscalls.c:(.text._lseek+0x0): multiple definition of `_lseek’
{CODE}

I have read that I need to remove the file syscalls.c from my project but I don’t have any file called like this. Any idea of how can I solve this? Thank you !!

I had to remove the nosys flags. My makefile looks now like this and compiles:

# libraries
LIBS = -lc -lm -lrdimon
LIBDIR = 
LDFLAGS = $(MCU) -specs=nano.specs -specs=rdimon.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections


I loaded the code on the STM32F031C6 (STEVAL-PTOOL1V1) and it works. I check the TX pins I have set manually (PB6 for TX and PB7 for RX) and I can see the UART frame. However, nothing is shown on my opencd server terminal when I call printf. I’m not prettu sure if the problem is t the st link Im using. I’m using a ST Link MB1440B which I have updated with the right FW as described in its docs. Then I connect TX and RX to CN9 pins but still not getting anything on the terminal... what am I missing?


 

Newest Forum Posts

  1. SW4STM32 installation on Ubuntu 20.04 LTS by mahnac72, 2022-01-17 09:12
  2. STM32G0B1 support by Nevada, 2022-01-14 18:47
  3. compiling date/time by yang@omniverter.com, 2022-01-13 20:07
  4. compiling date/time by tang, 2022-01-13 10:51
  5. compiling date/time by yang@omniverter.com, 2022-01-12 19:19
  6. STM32429 Discovery board Linux problem by llcheng, 2022-01-10 10:38
  7. STM32F030K6T6 Pa7 Question by jobhunter, 2022-01-07 10:20
  8. System workbench how to configure openocd debug by gxz, 2022-01-03 15:49
  9. Auto generate build/version number by katarcza, 2022-01-01 11:00
  10. Charger firmware by kacio, 2021-12-30 09:04

Last-Modified Blogs