Skip to main content
AT.1
Associate
November 25, 2020
Solved

Issue in debug mode when use Uart

  • November 25, 2020
  • 2 replies
  • 1651 views

Hello,

I'm creating application with STM32F072, with ADC DMA, USB, Timers and Uart.

Last one is used to communicate with PC but i verify a strange behavior.

First of all general information:

  • generating this software with STM32cubeMx.
  • using IDE openstm32
  • priority level USB = 0
  • priority level TIM3 = 1
  • priority level DMA = 2
  • priority level UART = 3

The strange behavior is present when i'm debugging application for checking uart peripherals.

I sent chars from MCU to PC, when these chars arrived on minicom see chars differets.

When PC sent chars to MCU, MCU goes in error for noise.

This happend in debug mode.

In Run mode ( same configuration debug) this behavior not is present yet.

Can you explain what i missed?

Thank you in advanced

Andrea

This topic has been closed for replies.
Best answer by AT.1

Hello,

i solved this issue.

I found the problemi is in USART inizialization parameters and clock source .

Clock source chaging:

Before with issue

 PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK1;

After without issue

 PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_HSI;

USART inizialization parameters chaging:

Before with Issue:

huart1.Instance = USART1;

 huart1.Init.BaudRate = 38400;

 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;

After without issue:

huart1.Instance = USART1;

 huart1.Init.BaudRate = 38400;

 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_RXOVERRUNDISABLE_INIT|UART_ADVFEATURE_DMADISABLEONERROR_INIT;

 huart1.AdvancedInit.OverrunDisable = UART_ADVFEATURE_OVERRUN_DISABLE;

 huart1.AdvancedInit.DMADisableonRxError = UART_ADVFEATURE_DMA_DISABLEONRXERROR;

Now in Debugging i can see correct bytes trasmit and receive on PC and in debug watch live IDE expression.

B.R.

Andrea

2 replies

AT.1
AT.1AuthorBest answer
Associate
November 27, 2020

Hello,

i solved this issue.

I found the problemi is in USART inizialization parameters and clock source .

Clock source chaging:

Before with issue

 PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK1;

After without issue

 PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_HSI;

USART inizialization parameters chaging:

Before with Issue:

huart1.Instance = USART1;

 huart1.Init.BaudRate = 38400;

 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;

After without issue:

huart1.Instance = USART1;

 huart1.Init.BaudRate = 38400;

 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_RXOVERRUNDISABLE_INIT|UART_ADVFEATURE_DMADISABLEONERROR_INIT;

 huart1.AdvancedInit.OverrunDisable = UART_ADVFEATURE_OVERRUN_DISABLE;

 huart1.AdvancedInit.DMADisableonRxError = UART_ADVFEATURE_DMA_DISABLEONRXERROR;

Now in Debugging i can see correct bytes trasmit and receive on PC and in debug watch live IDE expression.

B.R.

Andrea

ST Technical Moderator
November 27, 2020

Hello @AT.1​ ,

Welcome to the STM32 Community :smiling_face_with_smiling_eyes:.

Thanks for sharing the solution! It is much appreciated and it should be helpful for the Community.

Imen

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks