Skip to main content
SWenn.1
Senior III
January 28, 2023
Solved

Casting / Pointers creating immense grief???

  • January 28, 2023
  • 5 replies
  • 1308 views

I have the array of character strings that I am trying to printout to Real Term using a Nucleo -F072. The code compiles with no warnings or errors, yet every time I run this it jumps into the HardFault_Handler....Can someone please tell me what am I doing incorrectly??? My lack of knowledge on pointers and casting is somehow the cause.......

char t[][4] = {"1234", "3455", "1121", "0032", "0621"};
 
 
for (k = 0; k < NO_ADC_CH; k++)
{
 //test = hex2Ascii(stream + k);
 HAL_UART_Transmit_IT(&huart2, (uint8_t*)(&test[k]), sizeof(test[k]));
 //HAL_Delay(1);
 while(!ISR.UART_TxComplete);
 ISR.UART_TxComplete = F;
}
 
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
{
	ISR.UART_TxComplete = T;
}

This topic has been closed for replies.
Best answer by Tesla DeLorean

Are test and t the same thing?

Strings tend to NUL terminate so at least a 5 x 5 array there.

What's actually Faulting here?

The sizeof(test[k]) is a bit awkward in this context, but probably Ok

ISR.UART_TxComplete needs to be volatile

Try something like

int k;
for (k = 0; k < 10; k++)
{
 static char string[8];
 ISR.UART_TxComplete = F;
 HAL_UART_Transmit_IT(&huart2, (uint8_t*)string, sprintf(string, "%04X\n", k));
 while(!ISR.UART_TxComplete);
}

5 replies

AScha.3
Super User
January 28, 2023

what is : NO_ADC_CH ? and : test[] ? only t[] shown.

and use xx-transmit without INT , because you wait anyway for finish.

If you feel a post has answered your question, please click on " Best Answer ".
S.Ma
Principal
January 28, 2023

How about looking at brisk sif.c code which works on STM32C0 and manage usart by interrupt to send adc data to teraterm and bluetooth electronics android app? Here

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
January 28, 2023

Are test and t the same thing?

Strings tend to NUL terminate so at least a 5 x 5 array there.

What's actually Faulting here?

The sizeof(test[k]) is a bit awkward in this context, but probably Ok

ISR.UART_TxComplete needs to be volatile

Try something like

int k;
for (k = 0; k < 10; k++)
{
 static char string[8];
 ISR.UART_TxComplete = F;
 HAL_UART_Transmit_IT(&huart2, (uint8_t*)string, sprintf(string, "%04X\n", k));
 while(!ISR.UART_TxComplete);
}

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
SWenn.1
SWenn.1Author
Senior III
January 28, 2023

Wow!!! That works great...would have never thought of the sprintf thing....

I apologize for above as test should have been t....

Anyway I substituted k with analog data in your line 6 and added \r and now it seems to work fine....I will do some more testing just to convince myself but .....

thank you everyone for the help!!

Piranha
Principal III
January 29, 2023

> I substituted k with analog data in your line 6

I can already see in my mind how the sprintf() writes past the buffer... Instead it is higly recommended to use snprintf() and check it's return value.

https://en.cppreference.com/w/c/io/fprintf