Function USART_send_word_HEX_DBG below fails to work.
- Using AS7 and ATTINY416 nano board.
1. Specifically, the content copied into string outstr (ID'd as "OFFENDING CODE") by strncpy is all 0xff (which looks suspiciously like eeprom content) into the dest string. Function strncpy_F copies all 0's.
2. In size_t len = strlen(desc); strlen returns 0;
Commented code remains because it shows what has been tried. The one test call from main() appears below the function. Toolchain is shown at the very bottom.
What the usart emits confirms that the values for the desc part of the string are 0xff, and strncpy copies into the correct location in the dest string. If I strncpy a different string created within the function, it works as expected. Only when I strncpy from the parameter does it fail.
Stack containing string outstr after the strncpy (previously initialized to 0's):
Debug display for the location of the string contained in parameter desc (seems like a "feature" of the debugger to me):
The debugger tells me the address of the incoming parameter desc is 0x8ff5 (confirmed by r[22:23]) which is in flash but I cannot read that content in the debugger. PROGMEM is too full to use sprintf (the project is nearly done and need to debug one remaining difficult IR bitstream).
My questions please:
1. Where in mem is the const string in the caller's arg (and should it be visible to me in the debugger)? Am I missing some mem map translation?
2. How can I know (or control) where such const strings are stored without debugging? I cannot find rules. Const strings created as function args like this can slip from notice pretty easily.
3. The language spec says a definition like char str = ""; initializes the array, but in this compiler it does not. How can I find out where the compiler does not meet the language spec? Does GCC have a spec or a compliance statement like microsoft publishes?
I have possible undesirable workarounds to try but I really would like this to work as-written.
All advice and commentary is always gratefully received.
//void USART_send_word_HEX_DBG(uint16_t value, const char *desc)
void USART_send_word_HEX_DBG(uint16_t value, const char desc)
// "xxxx: tttttttttt\0"
// where xxxx = value, tttttttttt = desc
size_t len = strlen(desc); // <- OFFENDING CODE
//char outstr = "";
memset(outstr, 0, 17);
CharToHex((char)(value >> 8), &outstr);
CharToHex((char)(value & 0x00ff), &outstr);
outstr = ':'; outstr = ' ';
strncpy(&outstr, desc, len > 10 ? 10 : len); // <- OFFENDING CODE
//strcat(outstr, desc); // <- OFFENDING CODE
//strcpy_P(&outstr, desc); // <- OFFENDING CODE (copies 0's)
USART_send_word_HEX_DBG(0xa5a5, "test word");