cancel
Showing results for 
Search instead for 
Did you mean: 

After restart device UART_3 printing some rubbish ţ˙ţţţţţţţţüţüüüüüüüüüüüüüüüüüü

KWiśn.2
Associate II

Dear,

Microcontroler STM32H742 (stm32CubeIDE)

When i plug out and plug in device, this printing on UART_3:

ţ˙ţţţţţţţţüţüüüüüüüüüüüüüüüüüü

or:

ţ

NVT: FF FE FE

ţţ{FF}

i this problem was not watched on same device with stm32F205(Rowley crossworks).

I clear all buffer 

char bufRcv[256] {'\0'}; but it nothing change

Could you have some solution

Many thanks

18 REPLIES 18
KWiśn.2
Associate II

from time to time i have:

ţ

NVT: FF FE FE

ţţ{FF}

KWiśn.2
Associate II

I try with delay, and i have less character but problem doesn't resolved, also big value delay

int main(void)
{
	assert(sizeof(Product) == 136);
	assert(sizeof(User) == 124);
	assert(sizeof(TareRec) == 60);
	assert(sizeof(WazenieRec) == 192);
	assert(sizeof(RaportSuszenia) == 264);
	assert(sizeof(PomiarSuszenia) == 68);
	assert(((sizeof(sParams) * 2) + 128) < PC::BUF_SIZE);//czy parametry mieszcza sie w buforze, zeby wyslac je w postaci HEX
 
	delay_ms(1000);
  HAL_Init();
//  HAL_Delay(1000);
  SystemClock_Config();
  PeriphCommonClock_Config();
  //HAL_Delay(100);

> When i plug out and plug in

What exactly do you mean by "plug out and plug in"?

And what do you observe, mcu's UART_Rx (how do you observe that?), or mcu's UART_Tx connected in some way to a PC/terminal?

JW

KWiśn.2
Associate II

I mean Plug the power cord to the mains.

I have RS232 on mainboard in computer and i use db9 cable.

problem is only after Plug the power cord to the mains.

I use Hercules RS232 terminal:

https://www.hw-group.com/software/hercules-setup-utility

I have open rs232 port in hercules and turn on and turn off device.

Device and computer is connect to the same power strip.

We watch the problem after plugin Zebra printer, when scale was plug the power cord to the mains, printer printing this string

LCE
Principal

You you are clearing

char bufRcv[256] {'\0'};

which sounds like a receive buffer.

What about the transmit buffer? That's doing the printf.

So your UART and buffer init and TX functions might be interesting to see.

KWiśn.2
Associate II

Yes I clear all device and buffer rec and transmit sorry i past rec buffer, but to show how i do this, mayby better is use memset(localBuf, '\0', sizeof(localBuf));

char bufContinuesTransmition[32] {'\0'};

char buf[BUF_SIZE] {'\0'};

char printBuf[PC_PRINT_BUF_SIZE] {'\0'};

static char localBuf[50] {'\0'};

We use c11 and c++11 in this project.

KWiśn.2
Associate II

//------------------------------------------------- First plug the power cord to the mains --------------------------------

ţ

NVT: FF FE FE

ţţţţţţţţţüüţüüüüüüüţüüüţü

//------------------------------------------------- Second plug the power cord to the mains -------------------------

ţ

NVT: FF FE FF

ţţţţţţţ˙ţţ

//------------------------------------------------- 3 plug the power cord to the mains -------------------------------

ţ˙ţţţţţţüüüüüüüüüüüüüüüüüüüü

//------------------------------------------------- 4 plug the power cord to the mains -------------------------------

ţ˙ţţţţţţüüüüüüüüüüüüüüüüüüüüţ˙ţ

NVT: FF FE FE

ţţţţţţţţüţüţüţüţüţü

NVT: FF FC FF

ü

//------------------------------------------------- 5 plug the power cord to the mains -------------------------------

ţ˙ţţţţţţţţţüüţüüüüüüüţüüüţüţ

LCE
Principal

You are working with hardware, so you cannot just assume that thrwoing out printf / cout gives you what you want.

There must be some kind of hardware linking functions, something like this, so the weak _write is linked to actual hardware with Uart3DmaTx():

/* printf uses syscall function "_write()",
 * which is declared as __weak,
 * replace it with uart output function
 */
int _write(int file, char *data, int len)
{
	/* printf to UART */
	if( 0 == Uart3DmaTx((uint8_t *)data, len, 0) ) return len;
	return 0;
}
 

KWiśn.2
Associate II

//**************************************************************************************

UART_3 Com1;

UART_HandleTypeDef huart3;

DMA_HandleTypeDef hdma_usart3_tx;

//--------------------------------------------------------------------------------------

void UART_3::Init()

{

 __HAL_RCC_DMA1_CLK_ENABLE();

 //koniguracja portow oraz dma nastepuje w HAL_UART_MspInit

 ConfigureUsart();

 HAL_NVIC_SetPriority(DMA1_Stream3_IRQn, 3, 0);

 HAL_NVIC_EnableIRQ(DMA1_Stream3_IRQn);

 /* Peripheral interrupt init */

 HAL_NVIC_SetPriority(USART3_IRQn, 2, 0);

 HAL_NVIC_EnableIRQ(USART3_IRQn);

 __HAL_UART_ENABLE_IT(&huart3,UART_IT_RXNE);

}

//--------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------

void UART_3::ConfigureUsart()

{

 uint16_t parity = DecodeParity(Params.Com1_Parity);

 huart3.Instance = USART3;

 huart3.Init.BaudRate = DecodeBaudrate(Params.Com1_Baudrate);

 huart3.Init.WordLength = (parity == PARITY_NONE) ? UART_WORDLENGTH_8B : UART_WORDLENGTH_9B;

 huart3.Init.StopBits = UART_STOPBITS_1;

 huart3.Init.Parity = parity;

 huart3.Init.Mode = UART_MODE_TX_RX;

 huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;

 huart3.Init.OverSampling = UART_OVERSAMPLING_16;

 huart3.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;

 huart3.Init.ClockPrescaler = UART_PRESCALER_DIV1;

 huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;

 if (HAL_UART_Init(&huart3) != HAL_OK) Error_Handler();

 if (HAL_UARTEx_SetTxFifoThreshold(&huart3, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) Error_Handler();

 if (HAL_UARTEx_SetRxFifoThreshold(&huart3, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) Error_Handler();

 if (HAL_UARTEx_DisableFifoMode(&huart3) != HAL_OK) Error_Handler();

}

//--------------------------------------------------------------------------------------