cancel
Showing results for 
Search instead for 
Did you mean: 

Casting / Pointers creating immense grief???

SWenn.1
Senior III

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;
}

1 ACCEPTED SOLUTION

Accepted Solutions

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
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

5 REPLIES 5
AScha.3
Chief II

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 "Accept as Solution".
S.Ma
Principal

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

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
Up vote any posts that you find helpful, it shows what's working..
SWenn.1
Senior III

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
Chief II

> 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