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.

CCS/CC2640R2F: Printing to console disrupts program flow

Part Number: CC2640R2F

Tool/software: Code Composer Studio

Hello,

I'm reading print statements from simplePeripheral to the console. As can be seen from the console output, the device tries to connect several times. On the iPhone the app (LightBlue) finally issues a connection error. When I click dismiss, I get the last entry in the console "conn 255". I don't see a counter increment. It jumps from 1 connection to 0 connections to 255 connections. Can anyone explain this behavior? Also, when I disconnect the device from the debugger, the device connects just fine. There are references in the documentation suggesting that this behavior can occur, but this makes printing to the console limitedly useful.

Cortex_M3_0] *
Simple Peripheral
====================
Initialized
Dev Addr: 0x0081F9838081
Adv Set 1 Enabled
Adv Set 0 Enabled
Adv Set 0 Disabled
Adv Set 0 disabled after conn 0
Num Conns: 1
Connected to 0x68FC0C286197
*
Simple Peripheral
+Work with >
Adv Set 1 Disabled
Device Disconnected!
Num Conns: 0
*
Simple Peripheral
Adv Set 0 Enabled
Adv Set 1 Enabled
Adv Set 0 Disabled
Adv Set 0 disabled after conn 0
Num Conns: 1
Connected to 0x68FC0C286197
*
Simple Peripheral
+Work with >
Adv Set 1 Disabled
Device Disconnected!
Num Conns: 0
*
Simple Peripheral
Adv Set 0 Enabled
Adv Set 1 Enabled
Adv Set 0 Disabled
Adv Set 0 disabled after conn 0
Num Conns: 1
Connected to 0x68FC0C286197
*
Simple Peripheral
+Work with >
Adv Set 1 Disabled
Device Disconnected!
Num Conns: 0
*
Simple Peripheral
Adv Set 0 Enabled
Adv Set 1 Enabled
Adv Set 0 Disabled
Adv Set 0 disabled after conn 255

  • Hi Patrick,
    Could you please elaborate a bit more on the setup? (i.e. SDK version, Smartphone modes, HW etc.)
  • Patrick,

    You should not print to the console like that. At least if I understand this correctly and you mean the CIO Console in CCS which emulates console output by writing to a buffer and inserting breakpoints in the code. I am basing this on the ""Cortex_M3_0] *"" at the top.

    Consider using UART, which is the default in the example. CCS has support for opening terminals to serial ports, or you can use eg. PuTTY/TeraTerm, etc.

    Best regards,
    Aslak
  • Hello Aslak,

    Thank you for your suggestion. You are correct, writing to the console in this way creates timing issues. I'm now trying to implement System_printf(). Following the example in SimpleLink Academy, it suggests that I add UARTUtils.c & UARTUtils.h to my project (SimplePeripheral SDK 30.00.28). I can't seem to find these utility files. In another E2E post, it is suggested that these files are not implemented for CC26XX, but it doesn't provide and alternative.

    From post found here: "You can use System_printf and route the characters out the UART, but the UARTUtils files that we had for other devices will not work because UART_writePolling is not implemented for CC26xx devices."

    Can you provide a System_printf() implementation that works with CC2640r2 to output via UART thus avoiding problem with Display_printf()?

    Thank you,

    Patrick

  • Hi Patrick,

    Well, you could just use UART_write(uartHandle, "Hello\r\n", 7); for example. It should be mentioned that uart writes are only supported from Task context, and only from one at a time. It's quite easy to get into a situation (if you want to log for example) where you print from interrupts and two tasks at a time.

    This is mainly because the cc13/26xx platform does not have a writePolling implementation, which again is because it's not a good idea to wait in a spinlock for uart to finish when the RF operations are sometimes timing critical.

    I would perhaps suggest looking at project_zero where the Log_xx API is overridden to log to a buffer and print to UART in the idle loop, meaning that it has very little timing impact and can be used in any context.

    dev.ti.com/.../

    It can be added to any project by adding Idle.addFunc('&uartLog_flush'); to the projects RTOS cfg file, adding UartLog.c/h, and by following the instructions in UartLog.h. You should perhaps also add uartlog_FILE="\"${InputFileName}\"" as a project level precompiler define as well, to get nice filename printout. Refer to project_zero.

    Best regards,
    Aslak