This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software:
I'm using the stock sensor_CC1310_LAUNCHXL_tirtos_ccs example project. In order to see how often messages were being sent out over RF, I thought I'd add a timestamp to the Board_Lcd_writeString* functions (I'm not using the LCD...just the UART). So, after adding the appropriate #define along with adding posix support in the kernel config file, I added this to the top of Sensor_init in sensor.c:
#ifdef DEBUG_PRINT_TIMESTAMP #define STARTTIME 1729719936 Seconds_set(STARTTIME); struct timespec ts; ts.tv_sec = STARTTIME; ts.tv_nsec = 0; clock_settime(CLOCK_REALTIME, &ts); #endif
I then added this code to board_lcd.c:
#if defined(DEBUG_PRINT_TIMESTAMP) #include <stdio.h> void print_timestamp(void) { char buf[81]; uint32_t t; t = Seconds_get(); time_t t1 = time(NULL); #if 0 struct tm *ltm; char *curTime; ltm = localtime(&t1); curTime = asctime(ltm); strcpy(buf,curTime); #else Util_ltoa(t1, (uint8_t *)buf, 10); #endif t = strlen((char *)buf); buf[t] = ':'; buf[t+1] = ' '; buf[t+2] = 0; System_printf((xdc_CString)buf); } #endif
That code is called from Board_Lcd_writeString and Board_Lcd_writeStringValue.
Here's the weird part...As is, it works just fine. It adds a numeric timestamp in front of every output uart string (although it is the secs since 1/1/1900, which is interesting).
If I try to pretty things up and use the localtime(), asctime() stuff by flipping that #if 0, it no worky. It just constantly resets. When I run it through the debugger, I get constant:
Cortex_M3_0: GEL Output: Memory Map Initialization Complete.
Cortex_M3_0: GEL Output: Board Reset Complete.
Cortex_M3_0: Error: (Error -1170 @ 0x0) Unable to access the DAP. Reset the device, and retry the operation. If error persists, confirm configuration, power-cycle the board, and/or try more reliable JTAG settings (e.g. lower TCLK). (Emulation package 20.0.0.3178)
Cortex_M3_0: Trouble Halting Target CPU: (Error -2064 @ 0x0) Unable to read device status. Reset the device, and retry the operation. If error persists, confirm configuration, power-cycle the board, and/or try more reliable JTAG settings (e.g. lower TCLK). (Emulation package 20.0.0.3178)
Cortex_M3_0: Error: (Error -1170 @ 0x0) Unable to access the DAP. Reset the device, and retry the operation. If error persists, confirm configuration, power-cycle the board, and/or try more reliable JTAG settings (e.g. lower TCLK). (Emulation package 20.0.0.3178)
Cortex_M3_0: Trouble Halting Target CPU: (Error -2064 @ 0x0) Unable to read device status. Reset the device, and retry the operation. If error persists, confirm configuration, power-cycle the board, and/or try more reliable JTAG settings (e.g. lower TCLK). (Emulation package 20.0.0.3178)
Am I doing something incorrectly? I saw a bunch of example code that pretty much did the same thing...
Thanks.
Hi Dave,
from a first look it seems like you're running in a buffer overflow. You can try to allocate memory for your variables first.
I'm working on debugging your solution but I think I'm missing some of your changes.
Can you please provide all of them so that I can reproduce the error?
Kind regards,
Theo
The only other change is in the Board_Lcd_writeString* functions in board_lcd.c:
/*! * Write a string on the LCD display. * * Public function defined in board_lcd.h */ void Board_Lcd_writeString(char *str, uint8_t line) { #if defined(BOARD_DISPLAY_USE_UART) #if defined(DEBUG_PRINT_TIMESTAMP) print_timestamp(); #endif System_printf(str); System_printf("\r\n"); #endif #if defined(BOARD_DISPLAY_USE_LCD) if(hDisp != NULL) { Display_control(hDisp, DISPLAY_CMD_TRANSPORT_OPEN, NULL); Display_print0(hDisp, line, 0, str); Display_control(hDisp, DISPLAY_CMD_TRANSPORT_CLOSE, NULL); } #endif /* BOARD_DISPLAY_USE_LCD */ } /*! * Write a string and value on the LCD display. * * Public function defined in board_lcd.h */ void Board_Lcd_writeStringValue(char *str, uint16_t value, uint8_t format, uint8_t line) { int len = strlen(str); memset(lcdBuf, 0, MAX_LCD_BUF); memcpy(lcdBuf, str, len); Util_itoa(value, &lcdBuf[len], format); #if defined(BOARD_DISPLAY_USE_UART) #if defined(DEBUG_PRINT_TIMESTAMP) print_timestamp(); #endif System_printf((xdc_CString)lcdBuf); System_printf("\r\n"); #endif #if defined(BOARD_DISPLAY_USE_LCD) if(hDisp != NULL) { Display_control(hDisp, DISPLAY_CMD_TRANSPORT_OPEN, NULL); Display_print0(hDisp, line, 0, (char *)lcdBuf); Display_control(hDisp, DISPLAY_CMD_TRANSPORT_CLOSE, NULL); } #endif /* BOARD_DISPLAY_USE_LCD */ }
But, you're right. Declaring the variables in the top of the function "fixed" everything. Note to self...
Thanks!
Well, crud. I spoke too soon. Still doing it with the changes below:
#if defined(DEBUG_PRINT_TIMESTAMP) #include <stdio.h> void print_timestamp(void) { uint32_t t; time_t t1; struct tm *ltm; char *curTime; char buf[81]; t = Seconds_get(); t1 = time(NULL); #if 1 ltm = localtime(&t1); curTime = asctime(ltm); strcpy(buf,curTime); #else Util_ltoa(t1, (uint8_t *)buf, 10); #endif t = strlen((char *)buf); buf[t-1] = ':'; buf[t] = ' '; buf[t+1] = 0; System_printf((xdc_CString)buf); } #endif
I had put the same changes into the Collector example, and it actually works fine.
I also pulled the "char buf[81]" out of there into a static array to see if the stack was getting hosed, but that didn't change behavior.
I wonder if this has something to do with the "struct tm" and/or the "char *" that gets allocated and used in that localtime and asctime calls?
Or, hopefully I'm just doing something stupid.
Hi Dave,
it still looks like memory issue to me. Did you look into using localtime_r() that is thread safe and uses a user provide buffer for the result that you can define statically?
I would recommend you to implement an alternative for asctime() as also here is internally memory allocated which might break the code.
Kind regards,
Theo
Hmmm....the *_r() time functions don't seem to be available in the ccs environment?
unresolved symbol localtime_r, first referenced in <whole-program>
Did you give that a shot in your environment?
Thanks
Hi Dave,
my bad, I didn't test the implementation first. It is indeed not included.
I was running now some tests using your latest implementation and I can reproduce the DAP access error.
I'm not sure yet what exactly causes it.
You could try instead going with your second option and format it using char array based operations.
Kind regards,
Theo
I think there is some funkiness going on with 32 vs 64 bit mode...I saw some posts about telling the compiler which clock version to use (i forget the macro). Lots of stuff regarding epoch differences between functions, etc. Seems overly complicated for something that a lot of folks use, but probably not normally in production product with these components.
And thanks for taking a look!
Hi Dave,
I'm not sure about that. But in general we have also another option to add timestamps to you debug output which you can activate in the project properties -> Debug: https://software-dl.ti.com/ccs/esd/documents/users_guide/ccs_debug-main.html#misc-other-options
Did you already check it out?
Kind regards,
Theo
I didn't check that out yet...thanks.
I'm actually not running these targets under the debugger 99% of the time. The timestamps are a crude "when did that happen" over days of time.
As an interesting aside, it seems that Seconds_get() (1970 epoch) and time(NULL) (1900 epoch) don't return the same values for me.
Hi Dave,
I checked our mac layer implementation again and there is by default timestamps that you can use to print out. Did you check the implementations suggested in the following threads:
You can search for the "timestamp" variables with the file search (ctrl+h).
Kind regards,
Theo
This is all great info...my big worry is really more the locking up at this stage of the game. Seconds_get() works fine for now, and I just won't use the pretty time functions.
Hi Dave,
I'm sorry if I missed something.
Can you please explain the remaining "locking up" issue again?
Kind regards,
Theo
That "Cortex_M3_0: Error: (Error -1170 @ 0x0) Unable to access the DAP. Reset the device, and retry the operation. If error persists, confirm configuration, power-cycle the board, and/or try more reliable JTAG settings (e.g. lower TCLK). (Emulation package 20.0.0.3178)" I detailed above. You said you even replicated it.
If I don't run the code in the debugger, my target just constantly resets.
Thanks.
Hi Dave,
could replicate it when using localtime() and asctime().
But when I use the function in this configuration:
void print_timestamp(void) { uint32_t t; time_t t1; char buf[81]; t = Seconds_get(); t1 = time(NULL); #if 0 ltm = localtime(&t1); curTime = asctime(ltm); strcpy(buf,curTime); #else Util_ltoa(t1, (uint8_t *)buf, 10); #endif t = strlen((char *)buf); buf[t-1] = ':'; buf[t] = ' '; buf[t+1] = 0; System_printf((xdc_CString)buf); }
It runs without error.
Did you make any additional modifications that I don't have in my example?
Kind regards,
Theo
No...like you said, it runs without error when NOT using localtime and asctime. I'd like to use them ;-) They are pretty standard operations.
Thanks.
Hi Dave,
I'm looking into if there is a way to use these functions in an embedded rtos environment but they are not the standard.
If you look at the recommended standard then you can find an example project for cc1310 implementing a real time clock with formatted output here: https://dev.ti.com/tirex/explore/node?node=A__ADyXJdDRtNfrNfBnPIYDxw__com.ti.SIMPLELINK_CC13X0_SDK__eCfARaV__LATEST I think the best would be to implement the clock following this project as it would provide you the formatted output that you want to have.
Kind regards,
Theo
Hi Theo,
I appreciate the link...I'm not using C++ in my application. But, we're getting a bit off track. I've used the standard time stuff (time(),asctime(),localtime(),ctime) for lots of years in lots of embedded rtos environments. Especially ones that support posix.
I'm actually fine right now with my solution to display time, so don't need an alternative. I just thought you'd be a bit more interested in the lockup/"Unable to access the DAP" created when I use the built-in functions of the sdk. Seems like you've recreated that issue yourself, so good luck with a fix! And I wouldn't think a "fix" would be "use something else", as those functions are very standard.
Regards,
-- Dave
Hi Dave,
I can only guarantee that our recommended implementations work. I will anyways follow up on this with R&D and update this thread in the future.
I'm happy that you have a solution for your case right know.
Kind regards,
Theo