Problem with STF32 printf

* UPDATE *

here is what i found. Whenever I had this function, it would not actually block the code. what to actually do is make the RTC I2C read function very slow to execute, but the code will work fine, but I had to wait a very long time to go through every time I read RTC. therefore, as a result, an alarm interrupt for RTC occurred, and this caused other I2C interactions inside the ISR, so it looks like he was trying to make two i2c connections at the same time, which slows down the process. I removed the features in the ISR, and now I'm working on continuing the investigation.

I am having this problem when programming the STM32F103 chip using IAR 5.40. I have this feature. If I try to print a local variable, it will cause the code to freeze at another point before it even gets into this function.

What could be the reason for this?

this is a function

u8 GSM_Telit_ReadSms( u8 bSmsIndex )
{
  char bTmpSms[3] = { 0 };

  itoa( bSmsIndex, bTmpSms, 10 ); // converts the smsindex into a string

  printf("index = %s\n", bTmpSms);  //this printf caused the code to get stuck in the RTC // byte read function !!!!!!!

  GSM_Telit_RequestModem( "AT+CMGR=""1", 10, "CMGR", 5, 0 ); 
  return 1;
}

I tried this too and it does not cause the lock I experienced

u8 GSM_Telit_ReadSms( u8 bSmsIndex )
{
  char bTmpSms[3] = { 0 };

  itoa( bSmsIndex, bTmpSms, 10 );
  printf("index = 2\n");


  GSM_Telit_RequestModem( "AT+CMGR=""1", 10, "CMGR", 5, 0 ); 
  return 1;
}

There is no optimization, and the code gets stuck when trying to read a byte from my I2C ITC code, but as soon as I remove this printf("index = %s\n", bTmpSms);or use it instead printf("index = 2\n");, then everything will be happy. Any ideas ???

Edit: bSmsIndex will never be more than 30 in fact, and even then the lock happens wayyyy before calling this function.

+3
7

, , , .

, bTmpSms -, , printf, - itoa. , . , , , . itoa, .

:

u8 GSM_Telit_ReadSms( u8 bSmsIndex )
{
  char bTmpSms[4] = "aaa";    // I still need to find out why this is !!!

  itoa( bSmsIndex, bTmpSms, 10 ); // converts the smsindex into a string

  printf("index = %s\n", bTmpSms);  //this printf caused the code to get stuck in the RTC // byte read function !!!!!!!

  GSM_Telit_RequestModem( "AT+CMGR=""1", 10, "CMGR", 5, 0 ); 
  return 1;
}

itoa, . , . , , -, .

char itoa( int value, char* result, int base )
{
  // check that the base if valid
  if (base < 2 || base > 36) { *result = '\0'; return 0; }

  char* ptr = result, *ptr1 = result, tmp_char;
  int tmp_value;

  do
  {
    tmp_value = value;
    value /= base;
    *ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - value * base)];
  } while ( value );

  // Apply negative sign
  if (tmp_value < 0) *ptr++ = '-';
  *ptr-- = '\0';
  while(ptr1 < ptr)
  {
    tmp_char = *ptr;
    *ptr--= *ptr1;
    *ptr1++ = tmp_char;
  }
  return 1;
}
+1

char bTmpSms[3] "99". bSmsIndex 100 , , .


itoa , (http://www.cplusplus.com/reference/clibrary/cstdlib/itoa/). , . : itoa .

sprintf, snprintf - , .

+2

:

itoa() NUL- , printf , NUL .

pmg .

, itoa(). , bTmpSms. sprintf().

+1

. , - , , ; - , .

*. .

* , - , , . .

+1

bSmsIndex?

99, 3 . , , bTmpSms, , hte printf uis bTmpSms . -.

0

bSmsIndex ?

99, bTmpSms.

, IAR - , printf() , , . , , .

Or as quick troubleshooting, try resizing the array to something big (maybe 8) and see what happens.

0
source

You parsed this area with index = 2 versus index =% s

0
source

Source: https://habr.com/ru/post/1769206/


All Articles