<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>nRF52840 debug info printed correctly in SES debug output, but can&amp;#39;t read from serial port</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/108605/nrf52840-debug-info-printed-correctly-in-ses-debug-output-but-can-t-read-from-serial-port</link><description>Hi, 
 I&amp;#39;m currently using the nRF52840 DK. 
 My IDE is SEGGER Embedded Studio 8.10b, my SDK is nRF5_SDK_17.1.0_ddde560, and I&amp;#39;m using Macbook Pro m1 with MacOs Sonoma 14.0. 
 I copy the template_project in peripheral to my own directory. 
 To make it</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 06 Mar 2024 19:14:31 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/108605/nrf52840-debug-info-printed-correctly-in-ses-debug-output-but-can-t-read-from-serial-port" /><item><title>RE: nRF52840 debug info printed correctly in SES debug output, but can't read from serial port</title><link>https://devzone.nordicsemi.com/thread/472573?ContentTypeID=1</link><pubDate>Wed, 06 Mar 2024 19:14:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bcb3178d-86e2-4ebc-bcc3-f332088a93ea</guid><dc:creator>GeoffAtMSU</dc:creator><description>&lt;p&gt;Hi Einar,&lt;/p&gt;
&lt;p&gt;Thank you for your reply. I finally decided to use only uart to output and it worked.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;

#include &amp;quot;app_uart.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;nrf.h&amp;quot;
#include &amp;quot;nordic_common.h&amp;quot;
#include &amp;quot;boards.h&amp;quot;
#include &amp;quot;nrf_uart.h&amp;quot;

//#include &amp;quot;nrf_log.h&amp;quot;
//#include &amp;quot;nrf_log_ctrl.h&amp;quot;
//#include &amp;quot;nrf_log_default_backends.h&amp;quot;

#include &amp;lt;hal/nrf_pdm.h&amp;gt;
#include &amp;quot;nrf_drv_pdm.h&amp;quot;
#include &amp;quot;nrfx_pdm.h&amp;quot;

#include &amp;quot;nrf_delay.h&amp;quot;

// config of PDM
// PDM buffer
#define CLK_PIN 28
#define DIN_PIN 29
#define PDM_BUFF_SIZE 128
static int16_t pdm_buffer[PDM_BUFF_SIZE];
static bool pdm_buffer_ready;
static uint16_t pdm_size;

void myPrint(char *message){
  uint8_t i = 0;
  while(message[i] != NULL){ 
   app_uart_put(message[i++]);
  }
  char *new_line = &amp;quot;\r\n&amp;quot;;
  app_uart_put(new_line[0]);
  app_uart_put(new_line[1]);
}

void audio_callback(int16_t  *buffer, uint16_t size){
    // Convert the buffer data to a string and send over UART
    //for (uint16_t i = 0; i &amp;lt; 1; i++) {
    //    char str[16]; // Buffer to hold the string representation of the data
    //    snprintf(str, sizeof(str), &amp;quot;%d&amp;quot;, buffer[i]); // Convert the sample to string
    //    myPrint(&amp;quot;1&amp;quot;);
    //}
    pdm_buffer_ready = true;
    pdm_size = size;
}

void nrfx_pdm_event_handler(nrfx_pdm_evt_t const *const p_evt)
{
  if (p_evt-&amp;gt;buffer_requested) {
    nrfx_pdm_buffer_set(pdm_buffer, PDM_BUFF_SIZE);						
  }
  if (p_evt-&amp;gt;buffer_released != 0) {	
    audio_callback(pdm_buffer, PDM_BUFF_SIZE);
  }
}

static void pdm_init(void)
{
  nrfx_pdm_config_t pdm_config = NRFX_PDM_DEFAULT_CONFIG(CLK_PIN, DIN_PIN);
  nrfx_pdm_init(&amp;amp;pdm_config, nrfx_pdm_event_handler);
}

// configs of UART
#define UART_TX_BUFF_SIZE 1024
#define UART_RX_BUFF_SIZE 1024

#define UART_HWFC APP_UART_FLOW_CONTROL_DISABLED

void uart_err_handle(app_uart_evt_t * p_event){
    if (p_event-&amp;gt;evt_type == APP_UART_COMMUNICATION_ERROR) {
        APP_ERROR_HANDLER(p_event-&amp;gt;data.error_communication);
    }
    else if (p_event-&amp;gt;evt_type == APP_UART_FIFO_ERROR) {
        APP_ERROR_HANDLER(p_event-&amp;gt;data.error_code);
    }
}

uint32_t uart_init(){
  uint32_t err_code;
  
  const app_uart_comm_params_t com_params = {
    RX_PIN_NUMBER,
    TX_PIN_NUMBER,
    RTS_PIN_NUMBER,
    CTS_PIN_NUMBER,
    UART_HWFC,
    false,
    //NRF_UART_BAUDRATE_115200
    NRF_UART_BAUDRATE_1000000
  };
  APP_UART_FIFO_INIT(&amp;amp;com_params, UART_RX_BUFF_SIZE, UART_TX_BUFF_SIZE, uart_err_handle, APP_IRQ_PRIORITY_LOWEST, err_code);
  return err_code;

}

/**
 * @brief Function for application main entry.
 */
int main(void)
{
    nrfx_err_t err_code;
    //err_code = NRF_LOG_INIT(NULL);
    //APP_ERROR_CHECK(err_code);
    //NRF_LOG_DEFAULT_BACKENDS_INIT();
    
    err_code = uart_init();
    APP_ERROR_CHECK(err_code);
    //NRF_LOG_INFO(&amp;quot;HELLO from DK.&amp;quot;);
    //myPrint(&amp;quot;HELLO from DK.&amp;quot;);

    // NRF_LOG_INFO(&amp;quot;Start PDM init.&amp;quot;);
    //myPrint(&amp;quot;Start PDM init&amp;quot;);
    pdm_init();
    pdm_buffer_ready = false;
    err_code = nrfx_pdm_start();
    
    APP_ERROR_CHECK(err_code);
    if (err_code == NRFX_SUCCESS){
      //myPrint(&amp;quot;PDM started!&amp;quot;);
    }
    char str[16];
    uint8_t cr;

    while (true)
    {
        // Do nothing.
        //if (){
        
        //}
        //myPrint(&amp;quot;MAIN LOOP&amp;quot;);
        //NRF_LOG_INFO(&amp;quot;MAIN LOOP&amp;quot;);
        //nrf_delay_ms(500);
        while (app_uart_get(&amp;amp;cr) != NRF_SUCCESS) {
        
        }
        if (cr == &amp;#39;t&amp;#39;){
          while (1){
            if (pdm_buffer_ready){
              for (uint16_t i = 0; i &amp;lt; pdm_size; i++) {
                  //char str[16]; // Buffer to hold the string representation of the data
                  //snprintf(str, sizeof(str), &amp;quot;%d&amp;quot;, pdm_buffer[i]); // Convert the sample to string
                  //myPrint(str);
                  char high;
                  char low;
                  high = (pdm_buffer[i] &amp;gt;&amp;gt; 8) &amp;amp; 0xFF;
                  low = pdm_buffer[i] &amp;amp; 0xFF;
                  app_uart_put(high);
                  app_uart_put(low);
              }
              //char str[16];
              //snprintf(str, sizeof(str), &amp;quot;%d&amp;quot;, pdm_size);
              //myPrint(str);
              pdm_buffer_ready = false;

            }
            if (app_uart_get(&amp;amp;cr) == NRF_SUCCESS){
              if (cr == &amp;#39;k&amp;#39;){
                break;
              }
            }
          }

        }
        

    }
}
/** @} */
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 debug info printed correctly in SES debug output, but can't read from serial port</title><link>https://devzone.nordicsemi.com/thread/472360?ContentTypeID=1</link><pubDate>Wed, 06 Mar 2024 08:11:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:695c6089-ca7f-42bb-8b4a-fccbbc7264e5</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi Gen,&lt;/p&gt;
&lt;p&gt;The example works out of the box if you use the SES version that was used for testing that you can find in the &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/index.html"&gt;release notes&lt;/a&gt; (5.42a for 17.1.0). There are a few known issus when using newer SES version, and the&amp;nbsp;workarounds are described in these posts:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/88123/build-environment-problem/369319"&gt;RE: Build Environment Problem&lt;/a&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/88123/build-environment-problem/370762"&gt;RE: Build Environment Problem&lt;/a&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/85405/nrf5-sdk-17-1-0-examples-is-not-compiling-in-latest-ses-6-20a/356977"&gt;RE: nRF5 SDK 17.1.0 examples is not compiling in latest SES (6.20a)&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 debug info printed correctly in SES debug output, but can't read from serial port</title><link>https://devzone.nordicsemi.com/thread/472288?ContentTypeID=1</link><pubDate>Tue, 05 Mar 2024 15:59:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f9ca709b-cf70-4dc2-a8a9-bca96dd0d07d</guid><dc:creator>GeoffAtMSU</dc:creator><description>&lt;p&gt;Hi Einar,&lt;/p&gt;
&lt;p&gt;I tried to build the example &amp;#39;ble_app_uart&amp;#39;, but I got the error &amp;#39;&lt;/p&gt;
&lt;pre&gt;nRF5_SDK_17.1.0_ddde560/components/libraries/uart/retarget.c:101:23: error: unknown type name &amp;#39;__printf_tag_ptr&amp;#39;&lt;/pre&gt;
&lt;p&gt;&amp;#39;,&lt;/p&gt;
&lt;p&gt;And when I set RETARGET_ENABLED to 0 in the sdk config, I got a different error &amp;#39;&lt;/p&gt;
&lt;pre&gt;nRF5_SDK_17.1.0_ddde560/examples/piezobuds/ble_app_uart/pca10056/s140/ses/SEGGER_RTT_Syscalls_SES.c:76:10: fatal error: __vfprintf.h: No such file or directory
&lt;br /&gt;&amp;#39;,&lt;br /&gt;&lt;br /&gt;Do you know what caused this and what I should do?&lt;br /&gt;&lt;br /&gt;Best,&lt;br /&gt;Gen&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 debug info printed correctly in SES debug output, but can't read from serial port</title><link>https://devzone.nordicsemi.com/thread/472228?ContentTypeID=1</link><pubDate>Tue, 05 Mar 2024 12:50:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8d1ff1be-8469-489b-af4f-01d073f0fb76</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi Gen,&lt;/p&gt;
&lt;p&gt;You don&amp;#39;t need to change the Library I/O settings in the project.&lt;/p&gt;
&lt;p&gt;I suggest you take a look at the &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/ble_sdk_app_nus_eval.html"&gt;UART/Serial Port Emulation over BLE&lt;/a&gt;&amp;nbsp;sample, which demonstrate exactly this. It use UART for data, and use RTT for logging. If you first make sure you get that unmodified example working on your computer you know you have the basic set up and knows how to use it. Then you can use that as a reference for your application (just ignore everything related to Bluetooth and SoftDevice, as that is not what you are interested in).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 debug info printed correctly in SES debug output, but can't read from serial port</title><link>https://devzone.nordicsemi.com/thread/472110?ContentTypeID=1</link><pubDate>Mon, 04 Mar 2024 17:42:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ccf52211-3a14-4371-b685-7da4bd57d3f0</guid><dc:creator>GeoffAtMSU</dc:creator><description>&lt;p&gt;Hi Einar,&lt;/p&gt;
&lt;p&gt;I did what you said based on my understanding. And I set &amp;#39;Library I/O&amp;#39; in the option to RTT. The project was built successfully. But I cannot see anything using &amp;#39;screen&amp;#39; in my mac terminal.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Could you please help me check it?&lt;/p&gt;
&lt;p&gt;Thank you so much for your help.&lt;/p&gt;
&lt;p&gt;Best,&lt;/p&gt;
&lt;p&gt;Gen&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;

#include &amp;quot;app_uart.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;nrf.h&amp;quot;
#include &amp;quot;nordic_common.h&amp;quot;
#include &amp;quot;boards.h&amp;quot;
#include &amp;quot;nrf_uart.h&amp;quot;

#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#include &amp;quot;nrf_log_default_backends.h&amp;quot;

#include &amp;lt;hal/nrf_pdm.h&amp;gt;
#include &amp;quot;nrf_drv_pdm.h&amp;quot;
#include &amp;quot;nrfx_pdm.h&amp;quot;

#include &amp;quot;nrf_delay.h&amp;quot;

// config of PDM
// PDM buffer
#define CLK_PIN 28
#define DIN_PIN 29
#define PDM_BUFF_SIZE 128
static int16_t pdm_buffer[PDM_BUFF_SIZE];

void myPrint(char *message){
  uint8_t i = 0;
  while(message[i] != NULL){ 
   app_uart_put(message[i++]);
  }
  char *new_line = &amp;quot;\r\n&amp;quot;;
  app_uart_put(new_line[0]);
  app_uart_put(new_line[1]);
}

void audio_callback(int16_t  *buffer, uint16_t size){
    // Convert the buffer data to a string and send over UART
    for (uint16_t i = 0; i &amp;lt; size; i++) {
        char str[16]; // Buffer to hold the string representation of the data
        snprintf(str, sizeof(str), &amp;quot;%d&amp;quot;, buffer[i]); // Convert the sample to string
        //myPrint(str);
    }
}

void nrfx_pdm_event_handler(nrfx_pdm_evt_t const *const p_evt)
{
  if (p_evt-&amp;gt;buffer_requested) {
    nrfx_pdm_buffer_set(pdm_buffer, PDM_BUFF_SIZE);						
  }
  if (p_evt-&amp;gt;buffer_released != 0) {	
    audio_callback(pdm_buffer, PDM_BUFF_SIZE);
  }
}

static void pdm_init(void)
{
  nrfx_pdm_config_t pdm_config = NRFX_PDM_DEFAULT_CONFIG(CLK_PIN, DIN_PIN);
  nrfx_pdm_init(&amp;amp;pdm_config, nrfx_pdm_event_handler);
}

// configs of UART
#define UART_TX_BUFF_SIZE 128
#define UART_RX_BUFF_SIZE 128

#define UART_HWFC APP_UART_FLOW_CONTROL_DISABLED

void uart_err_handle(app_uart_evt_t * p_event){
    if (p_event-&amp;gt;evt_type == APP_UART_COMMUNICATION_ERROR) {
        APP_ERROR_HANDLER(p_event-&amp;gt;data.error_communication);
    }
    else if (p_event-&amp;gt;evt_type == APP_UART_FIFO_ERROR) {
        APP_ERROR_HANDLER(p_event-&amp;gt;data.error_code);
    }
}

uint32_t uart_init(){
  uint32_t err_code;
  
  const app_uart_comm_params_t com_params = {
    RX_PIN_NUMBER,
    TX_PIN_NUMBER,
    RTS_PIN_NUMBER,
    CTS_PIN_NUMBER,
    UART_HWFC,
    false,
    NRF_UART_BAUDRATE_115200
  };
  APP_UART_FIFO_INIT(&amp;amp;com_params, UART_RX_BUFF_SIZE, UART_TX_BUFF_SIZE, uart_err_handle, APP_IRQ_PRIORITY_LOWEST, err_code);
  return err_code;

}

/**
 * @brief Function for application main entry.
 */
int main(void)
{
    APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
    NRF_LOG_DEFAULT_BACKENDS_INIT();
    
    nrfx_err_t err_code;
    err_code = uart_init();
    APP_ERROR_CHECK(err_code);
    NRF_LOG_INFO(&amp;quot;HELLO from DK.&amp;quot;);

    NRF_LOG_INFO(&amp;quot;Start PDM init.&amp;quot;);
    // myPrint(&amp;quot;Start PDM init&amp;quot;);
    pdm_init();
    err_code = nrfx_pdm_start();
    
    APP_ERROR_CHECK(err_code);
    if (err_code == NRFX_SUCCESS){
      NRF_LOG_INFO(&amp;quot;PDM started!&amp;quot;);
    }

    while (true)
    {
        // Do nothing.
        //if (){
        
        //}
        //myPrint(&amp;quot;MAIN LOOP&amp;quot;);
        NRF_LOG_INFO(&amp;quot;MAIN LOOP&amp;quot;);
        nrf_delay_ms(500);

    }
}
/** @} */
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;// &amp;lt;h&amp;gt; nRF_Log 

//==========================================================
// &amp;lt;e&amp;gt; NRF_LOG_BACKEND_RTT_ENABLED - nrf_log_backend_rtt - Log RTT backend
//==========================================================
#ifndef NRF_LOG_BACKEND_RTT_ENABLED
#define NRF_LOG_BACKEND_RTT_ENABLED 1
#endif
// &amp;lt;o&amp;gt; NRF_LOG_BACKEND_RTT_TEMP_BUFFER_SIZE - Size of buffer for partially processed strings. 
// &amp;lt;i&amp;gt; Size of the buffer is a trade-off between RAM usage and processing.
// &amp;lt;i&amp;gt; if buffer is smaller then strings will often be fragmented.
// &amp;lt;i&amp;gt; It is recommended to use size which will fit typical log and only the
// &amp;lt;i&amp;gt; longer one will be fragmented.

#ifndef NRF_LOG_BACKEND_RTT_TEMP_BUFFER_SIZE
#define NRF_LOG_BACKEND_RTT_TEMP_BUFFER_SIZE 64
#endif

// &amp;lt;o&amp;gt; NRF_LOG_BACKEND_RTT_TX_RETRY_DELAY_MS - Period before retrying writing to RTT 
#ifndef NRF_LOG_BACKEND_RTT_TX_RETRY_DELAY_MS
#define NRF_LOG_BACKEND_RTT_TX_RETRY_DELAY_MS 1
#endif

// &amp;lt;o&amp;gt; NRF_LOG_BACKEND_RTT_TX_RETRY_CNT - Writing to RTT retries. 
// &amp;lt;i&amp;gt; If RTT fails to accept any new data after retries
// &amp;lt;i&amp;gt; module assumes that host is not active and on next
// &amp;lt;i&amp;gt; request it will perform only one write attempt.
// &amp;lt;i&amp;gt; On successful writing, module assumes that host is active
// &amp;lt;i&amp;gt; and scheme with retry is applied again.

#ifndef NRF_LOG_BACKEND_RTT_TX_RETRY_CNT
#define NRF_LOG_BACKEND_RTT_TX_RETRY_CNT 3
#endif

// &amp;lt;/e&amp;gt;

// &amp;lt;e&amp;gt; NRF_LOG_BACKEND_UART_ENABLED - nrf_log_backend_uart - Log UART backend
//==========================================================
#ifndef NRF_LOG_BACKEND_UART_ENABLED
#define NRF_LOG_BACKEND_UART_ENABLED 0
#endif
// &amp;lt;o&amp;gt; NRF_LOG_BACKEND_UART_TX_PIN - UART TX pin 
#ifndef NRF_LOG_BACKEND_UART_TX_PIN
#define NRF_LOG_BACKEND_UART_TX_PIN 6
#endif

// &amp;lt;o&amp;gt; NRF_LOG_BACKEND_UART_BAUDRATE  - Default Baudrate
 
// &amp;lt;323584=&amp;gt; 1200 baud 
// &amp;lt;643072=&amp;gt; 2400 baud 
// &amp;lt;1290240=&amp;gt; 4800 baud 
// &amp;lt;2576384=&amp;gt; 9600 baud 
// &amp;lt;3862528=&amp;gt; 14400 baud 
// &amp;lt;5152768=&amp;gt; 19200 baud 
// &amp;lt;7716864=&amp;gt; 28800 baud 
// &amp;lt;10289152=&amp;gt; 38400 baud 
// &amp;lt;15400960=&amp;gt; 57600 baud 
// &amp;lt;20615168=&amp;gt; 76800 baud 
// &amp;lt;30801920=&amp;gt; 115200 baud 
// &amp;lt;61865984=&amp;gt; 230400 baud 
// &amp;lt;67108864=&amp;gt; 250000 baud 
// &amp;lt;121634816=&amp;gt; 460800 baud 
// &amp;lt;251658240=&amp;gt; 921600 baud 
// &amp;lt;268435456=&amp;gt; 1000000 baud 

#ifndef NRF_LOG_BACKEND_UART_BAUDRATE
#define NRF_LOG_BACKEND_UART_BAUDRATE 30801920
#endif

// &amp;lt;o&amp;gt; NRF_LOG_BACKEND_UART_TEMP_BUFFER_SIZE - Size of buffer for partially processed strings. 
// &amp;lt;i&amp;gt; Size of the buffer is a trade-off between RAM usage and processing.
// &amp;lt;i&amp;gt; if buffer is smaller then strings will often be fragmented.
// &amp;lt;i&amp;gt; It is recommended to use size which will fit typical log and only the
// &amp;lt;i&amp;gt; longer one will be fragmented.

#ifndef NRF_LOG_BACKEND_UART_TEMP_BUFFER_SIZE
#define NRF_LOG_BACKEND_UART_TEMP_BUFFER_SIZE 64
#endif

// &amp;lt;/e&amp;gt;



//==========================================================
// &amp;lt;e&amp;gt; NRF_LOG_ENABLED - nrf_log - Logger
//==========================================================
#ifndef NRF_LOG_ENABLED
#define NRF_LOG_ENABLED 0
#endif
// &amp;lt;h&amp;gt; Log message pool - Configuration of log message pool

//==========================================================
// &amp;lt;o&amp;gt; NRF_LOG_MSGPOOL_ELEMENT_SIZE - Size of a single element in the pool of memory objects. 
// &amp;lt;i&amp;gt; If a small value is set, then performance of logs processing
// &amp;lt;i&amp;gt; is degraded because data is fragmented. Bigger value impacts
// &amp;lt;i&amp;gt; RAM memory utilization. The size is set to fit a message with
// &amp;lt;i&amp;gt; a timestamp and up to 2 arguments in a single memory object.

#ifndef NRF_LOG_MSGPOOL_ELEMENT_SIZE
#define NRF_LOG_MSGPOOL_ELEMENT_SIZE 20
#endif

// &amp;lt;o&amp;gt; NRF_LOG_MSGPOOL_ELEMENT_COUNT - Number of elements in the pool of memory objects 
// &amp;lt;i&amp;gt; If a small value is set, then it may lead to a deadlock
// &amp;lt;i&amp;gt; in certain cases if backend has high latency and holds
// &amp;lt;i&amp;gt; multiple messages for long time. Bigger value impacts
// &amp;lt;i&amp;gt; RAM memory usage.

#ifndef NRF_LOG_MSGPOOL_ELEMENT_COUNT
#define NRF_LOG_MSGPOOL_ELEMENT_COUNT 8
#endif

// &amp;lt;/h&amp;gt; 
//==========================================================

// &amp;lt;q&amp;gt; NRF_LOG_ALLOW_OVERFLOW  - Configures behavior when circular buffer is full.
 

// &amp;lt;i&amp;gt; If set then oldest logs are overwritten. Otherwise a 
// &amp;lt;i&amp;gt; marker is injected informing about overflow.

#ifndef NRF_LOG_ALLOW_OVERFLOW
#define NRF_LOG_ALLOW_OVERFLOW 1
#endif

// &amp;lt;o&amp;gt; NRF_LOG_BUFSIZE  - Size of the buffer for storing logs (in bytes).
 

// &amp;lt;i&amp;gt; Must be power of 2 and multiple of 4.
// &amp;lt;i&amp;gt; If NRF_LOG_DEFERRED = 0 then buffer size can be reduced to minimum.
// &amp;lt;128=&amp;gt; 128 
// &amp;lt;256=&amp;gt; 256 
// &amp;lt;512=&amp;gt; 512 
// &amp;lt;1024=&amp;gt; 1024 
// &amp;lt;2048=&amp;gt; 2048 
// &amp;lt;4096=&amp;gt; 4096 
// &amp;lt;8192=&amp;gt; 8192 
// &amp;lt;16384=&amp;gt; 16384 

#ifndef NRF_LOG_BUFSIZE
#define NRF_LOG_BUFSIZE 1024
#endif

// &amp;lt;q&amp;gt; NRF_LOG_CLI_CMDS  - Enable CLI commands for the module.
 

#ifndef NRF_LOG_CLI_CMDS
#define NRF_LOG_CLI_CMDS 1
#endif

// &amp;lt;o&amp;gt; NRF_LOG_DEFAULT_LEVEL  - Default Severity level
 
// &amp;lt;0=&amp;gt; Off 
// &amp;lt;1=&amp;gt; Error 
// &amp;lt;2=&amp;gt; Warning 
// &amp;lt;3=&amp;gt; Info 
// &amp;lt;4=&amp;gt; Debug 

#ifndef NRF_LOG_DEFAULT_LEVEL
#define NRF_LOG_DEFAULT_LEVEL 3
#endif

// &amp;lt;q&amp;gt; NRF_LOG_DEFERRED  - Enable deffered logger.
 

// &amp;lt;i&amp;gt; Log data is buffered and can be processed in idle.

#ifndef NRF_LOG_DEFERRED
#define NRF_LOG_DEFERRED 0
#endif

// &amp;lt;q&amp;gt; NRF_LOG_FILTERS_ENABLED  - Enable dynamic filtering of logs.
 

#ifndef NRF_LOG_FILTERS_ENABLED
#define NRF_LOG_FILTERS_ENABLED 1
#endif

// &amp;lt;q&amp;gt; NRF_LOG_NON_DEFFERED_CRITICAL_REGION_ENABLED  - Enable use of critical region for non deffered mode when flushing logs.
 

// &amp;lt;i&amp;gt; When enabled NRF_LOG_FLUSH is called from critical section when non deffered mode is used.
// &amp;lt;i&amp;gt; Log output will never be corrupted as access to the log backend is exclusive
// &amp;lt;i&amp;gt; but system will spend significant amount of time in critical section

#ifndef NRF_LOG_NON_DEFFERED_CRITICAL_REGION_ENABLED
#define NRF_LOG_NON_DEFFERED_CRITICAL_REGION_ENABLED 0
#endif

// &amp;lt;o&amp;gt; NRF_LOG_STR_PUSH_BUFFER_SIZE  - Size of the buffer dedicated for strings stored using @ref NRF_LOG_PUSH.
 
// &amp;lt;16=&amp;gt; 16 
// &amp;lt;32=&amp;gt; 32 
// &amp;lt;64=&amp;gt; 64 
// &amp;lt;128=&amp;gt; 128 
// &amp;lt;256=&amp;gt; 256 
// &amp;lt;512=&amp;gt; 512 
// &amp;lt;1024=&amp;gt; 1024 

#ifndef NRF_LOG_STR_PUSH_BUFFER_SIZE
#define NRF_LOG_STR_PUSH_BUFFER_SIZE 128
#endif

// &amp;lt;o&amp;gt; NRF_LOG_STR_PUSH_BUFFER_SIZE  - Size of the buffer dedicated for strings stored using @ref NRF_LOG_PUSH.
 
// &amp;lt;16=&amp;gt; 16 
// &amp;lt;32=&amp;gt; 32 
// &amp;lt;64=&amp;gt; 64 
// &amp;lt;128=&amp;gt; 128 
// &amp;lt;256=&amp;gt; 256 
// &amp;lt;512=&amp;gt; 512 
// &amp;lt;1024=&amp;gt; 1024 

#ifndef NRF_LOG_STR_PUSH_BUFFER_SIZE
#define NRF_LOG_STR_PUSH_BUFFER_SIZE 128
#endif

// &amp;lt;e&amp;gt; NRF_LOG_USES_COLORS - If enabled then ANSI escape code for colors is prefixed to every string
//==========================================================
#ifndef NRF_LOG_USES_COLORS
#define NRF_LOG_USES_COLORS 0
#endif
// &amp;lt;o&amp;gt; NRF_LOG_COLOR_DEFAULT  - ANSI escape code prefix.
 
// &amp;lt;0=&amp;gt; Default 
// &amp;lt;1=&amp;gt; Black 
// &amp;lt;2=&amp;gt; Red 
// &amp;lt;3=&amp;gt; Green 
// &amp;lt;4=&amp;gt; Yellow 
// &amp;lt;5=&amp;gt; Blue 
// &amp;lt;6=&amp;gt; Magenta 
// &amp;lt;7=&amp;gt; Cyan 
// &amp;lt;8=&amp;gt; White 

#ifndef NRF_LOG_COLOR_DEFAULT
#define NRF_LOG_COLOR_DEFAULT 0
#endif

// &amp;lt;o&amp;gt; NRF_LOG_ERROR_COLOR  - ANSI escape code prefix.
 
// &amp;lt;0=&amp;gt; Default 
// &amp;lt;1=&amp;gt; Black 
// &amp;lt;2=&amp;gt; Red 
// &amp;lt;3=&amp;gt; Green 
// &amp;lt;4=&amp;gt; Yellow 
// &amp;lt;5=&amp;gt; Blue 
// &amp;lt;6=&amp;gt; Magenta 
// &amp;lt;7=&amp;gt; Cyan 
// &amp;lt;8=&amp;gt; White 

#ifndef NRF_LOG_ERROR_COLOR
#define NRF_LOG_ERROR_COLOR 2
#endif

// &amp;lt;o&amp;gt; NRF_LOG_WARNING_COLOR  - ANSI escape code prefix.
 
// &amp;lt;0=&amp;gt; Default 
// &amp;lt;1=&amp;gt; Black 
// &amp;lt;2=&amp;gt; Red 
// &amp;lt;3=&amp;gt; Green 
// &amp;lt;4=&amp;gt; Yellow 
// &amp;lt;5=&amp;gt; Blue 
// &amp;lt;6=&amp;gt; Magenta 
// &amp;lt;7=&amp;gt; Cyan 
// &amp;lt;8=&amp;gt; White 

#ifndef NRF_LOG_WARNING_COLOR
#define NRF_LOG_WARNING_COLOR 4
#endif

// &amp;lt;/e&amp;gt;

// &amp;lt;e&amp;gt; NRF_LOG_USES_TIMESTAMP - Enable timestamping

// &amp;lt;i&amp;gt; Function for getting the timestamp is provided by the user
//==========================================================
#ifndef NRF_LOG_USES_TIMESTAMP
#define NRF_LOG_USES_TIMESTAMP 0
#endif
// &amp;lt;o&amp;gt; NRF_LOG_TIMESTAMP_DEFAULT_FREQUENCY - Default frequency of the timestamp (in Hz) or 0 to use app_timer frequency. 
#ifndef NRF_LOG_TIMESTAMP_DEFAULT_FREQUENCY
#define NRF_LOG_TIMESTAMP_DEFAULT_FREQUENCY 0
#endif

// &amp;lt;/e&amp;gt;

// &amp;lt;h&amp;gt; nrf_log module configuration &lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 debug info printed correctly in SES debug output, but can't read from serial port</title><link>https://devzone.nordicsemi.com/thread/471772?ContentTypeID=1</link><pubDate>Fri, 01 Mar 2024 12:00:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c93c935a-8b96-4e3a-9c83-a04a87f04c0d</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi Geoff,&lt;/p&gt;
&lt;p&gt;I see. In your code you use your myPrint() both for logging and data out. Based on what you wrote earlier here I assume you want to split it. So, I suggest using UART for data out (like you do with&amp;nbsp;myPrint), and use the logger system for logging. Then, enable the RTT backend (NRF_LOG_BACKEND_RTT_ENABLED) and disable the UART backend (NRF_LOG_BACKEND_UART_ENABLED). If you project don&amp;#39;t have the dependencies for RTT logging you need to add that (most example projects include all dependencies even if RTT logging is not enabled, so you can pick one and refer to that).&lt;/p&gt;
&lt;p&gt;Einar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 debug info printed correctly in SES debug output, but can't read from serial port</title><link>https://devzone.nordicsemi.com/thread/471597?ContentTypeID=1</link><pubDate>Thu, 29 Feb 2024 15:04:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0fbcdb32-e5e7-48a9-9b2e-fb3b0476f5a5</guid><dc:creator>GeoffAtMSU</dc:creator><description>&lt;p&gt;Hi Einar,&lt;/p&gt;
&lt;p&gt;I&amp;#39;d like to send the pdm data to my computer, for example, read the samples using serial port and store it as a wav file.&lt;/p&gt;
&lt;p&gt;Best,&lt;/p&gt;
&lt;p&gt;Geoff&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 debug info printed correctly in SES debug output, but can't read from serial port</title><link>https://devzone.nordicsemi.com/thread/471543?ContentTypeID=1</link><pubDate>Thu, 29 Feb 2024 13:23:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f486a4fb-d934-43a5-b1af-31d0696b7737</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;Geoff,&lt;/p&gt;
&lt;p&gt;Can you first clarify what you want to achieve? What do you want to do with the PDM samples? Once we know that, we can make sure you use a logging method that does not conflict with it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 debug info printed correctly in SES debug output, but can't read from serial port</title><link>https://devzone.nordicsemi.com/thread/471382?ContentTypeID=1</link><pubDate>Wed, 28 Feb 2024 16:02:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bd3ba83f-9fbe-422e-ad2b-d7908492855b</guid><dc:creator>GeoffAtMSU</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;

#include &amp;quot;app_uart.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;nrf.h&amp;quot;
#include &amp;quot;nordic_common.h&amp;quot;
#include &amp;quot;boards.h&amp;quot;
#include &amp;quot;nrf_uart.h&amp;quot;

#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#include &amp;quot;nrf_log_default_backends.h&amp;quot;

#include &amp;lt;hal/nrf_pdm.h&amp;gt;
#include &amp;quot;nrf_drv_pdm.h&amp;quot;
#include &amp;quot;nrfx_pdm.h&amp;quot;

#include &amp;quot;nrf_delay.h&amp;quot;

// config of PDM
// PDM buffer
#define CLK_PIN 28
#define DIN_PIN 29
#define PDM_BUFF_SIZE 128
static int16_t pdm_buffer[PDM_BUFF_SIZE];

void myPrint(char *message){
  uint8_t i = 0;
  while(message[i] != NULL){ 
   app_uart_put(message[i++]);
  }
  char *new_line = &amp;quot;\r\n&amp;quot;;
  app_uart_put(new_line[0]);
  app_uart_put(new_line[1]);
}

void audio_callback(int16_t  *buffer, uint16_t size){
    // Convert the buffer data to a string and send over UART
    for (uint16_t i = 0; i &amp;lt; size; i++) {
        char str[16]; // Buffer to hold the string representation of the data
        snprintf(str, sizeof(str), &amp;quot;%d&amp;quot;, buffer[i]); // Convert the sample to string
        myPrint(str);
    }
}

void nrfx_pdm_event_handler(nrfx_pdm_evt_t const *const p_evt)
{
  if (p_evt-&amp;gt;buffer_requested) {
    nrfx_pdm_buffer_set(pdm_buffer, PDM_BUFF_SIZE);						
  }
  if (p_evt-&amp;gt;buffer_released != 0) {	
    audio_callback(pdm_buffer, PDM_BUFF_SIZE);
  }
}

static void pdm_init(void)
{
  nrfx_pdm_config_t pdm_config = NRFX_PDM_DEFAULT_CONFIG(CLK_PIN, DIN_PIN);
  nrfx_pdm_init(&amp;amp;pdm_config, nrfx_pdm_event_handler);
}

// configs of UART
#define UART_TX_BUFF_SIZE 128
#define UART_RX_BUFF_SIZE 128

#define UART_HWFC APP_UART_FLOW_CONTROL_DISABLED

void uart_err_handle(app_uart_evt_t * p_event){
    if (p_event-&amp;gt;evt_type == APP_UART_COMMUNICATION_ERROR) {
        APP_ERROR_HANDLER(p_event-&amp;gt;data.error_communication);
    }
    else if (p_event-&amp;gt;evt_type == APP_UART_FIFO_ERROR) {
        APP_ERROR_HANDLER(p_event-&amp;gt;data.error_code);
    }
}

uint32_t uart_init(){
  uint32_t err_code;
  
  const app_uart_comm_params_t com_params = {
    RX_PIN_NUMBER,
    TX_PIN_NUMBER,
    RTS_PIN_NUMBER,
    CTS_PIN_NUMBER,
    UART_HWFC,
    false,
    NRF_UART_BAUDRATE_115200
  };
  APP_UART_FIFO_INIT(&amp;amp;com_params, UART_RX_BUFF_SIZE, UART_TX_BUFF_SIZE, uart_err_handle, APP_IRQ_PRIORITY_LOWEST, err_code);
  return err_code;

}

/**
 * @brief Function for application main entry.
 */
int main(void)
{
    // APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
    // NRF_LOG_DEFAULT_BACKENDS_INIT();
    
    nrfx_err_t err_code;
    err_code = uart_init();
    APP_ERROR_CHECK(err_code);
    // NRF_LOG_INFO(&amp;quot;HELLO from DK.&amp;quot;);

    // NRF_LOG_INFO(&amp;quot;Start PDM init.&amp;quot;);
    myPrint(&amp;quot;Start PDM init&amp;quot;);
    pdm_init();
    err_code = nrfx_pdm_start();
    
    APP_ERROR_CHECK(err_code);
    if (err_code == NRFX_SUCCESS){
      myPrint(&amp;quot;PDM started!&amp;quot;);
    }

    while (true)
    {
        // Do nothing.
        //if (){
        
        //}
        myPrint(&amp;quot;MAIN LOOP&amp;quot;);
        nrf_delay_ms(500);

    }
}
/** @} */
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Hi Einar,&lt;/p&gt;
&lt;p&gt;I tried the log module, it worked well if I didn&amp;#39;t print anything in the pdm callback. But if I tried to log the pdm value in the pdm callback function, I cannot see any outputs. So I changed back to uart, but the problem remains.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Here is my code, could you please give me some advice?&lt;/p&gt;
&lt;p&gt;Best,&lt;/p&gt;
&lt;p&gt;Geoff&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 debug info printed correctly in SES debug output, but can't read from serial port</title><link>https://devzone.nordicsemi.com/thread/470956?ContentTypeID=1</link><pubDate>Tue, 27 Feb 2024 09:04:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7df1d813-c062-4332-8cf1-0ca7baac3ccd</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;That depends on the product you are making. How do you need to use or output the PDM samples? If you need a dedicated UART for that, then you can use RTT for logging. Or an other UART (though on the DK only a single UART is routed to the onboard debugger that acts as a USB-UART bridge).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 debug info printed correctly in SES debug output, but can't read from serial port</title><link>https://devzone.nordicsemi.com/thread/470803?ContentTypeID=1</link><pubDate>Mon, 26 Feb 2024 15:23:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:72584750-73ad-47c3-baa4-66b4762fc9e1</guid><dc:creator>GeoffAtMSU</dc:creator><description>&lt;p&gt;Thank you so much Einar!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;If I use the logger module for output the things like &amp;quot;PDM started&amp;quot;, what should I use to output the real PDM data?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 debug info printed correctly in SES debug output, but can't read from serial port</title><link>https://devzone.nordicsemi.com/thread/470699?ContentTypeID=1</link><pubDate>Mon, 26 Feb 2024 11:52:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f2d4d516-002a-4ba6-b6d1-77c2d09d4304</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;It seems like you are using RTT for logging, and for that you need a Segger debugger to read the log. The &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/lib_nrf_log.html"&gt;logger module&lt;/a&gt; also support UART though, but then you need to configure that in your sdk_config.h. But in the code you show here I don&amp;#39;t see you using the logger module, and only printf, so it must be that you have configured the Segger Embedded Studio project to use RTT as backend for printf. I would suggest that you use the logge rmodule in the SDK instead, which leats you easily switch between RTT and UART in sdk_config.h (and even let&amp;#39;s you use both at the same time).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>