Hi everyone,
I'm using ses IDE to debug via J-link on nRF52840 DK.
I'm debbuging CDC ACM example (I haven't changed it) but when I debug: ret = app_usbd_cdc_acm_write(&m_app_cdc_acm, m_tx_buffer, size) I have that ret is not NRF_SUCCESS,
Why?
BR
Hi everyone,
I'm using ses IDE to debug via J-link on nRF52840 DK.
I'm debbuging CDC ACM example (I haven't changed it) but when I debug: ret = app_usbd_cdc_acm_write(&m_app_cdc_acm, m_tx_buffer, size) I have that ret is not NRF_SUCCESS,
Why?
BR
There is not an error messagge.
int main(void)
{
ret_code_t ret;
static const app_usbd_config_t usbd_config = {
.ev_state_proc = usbd_user_ev_handler
};
ret = NRF_LOG_INIT(NULL);
APP_ERROR_CHECK(ret);
ret = nrf_drv_clock_init();
APP_ERROR_CHECK(ret);
nrf_drv_clock_lfclk_request(NULL);
while(!nrf_drv_clock_lfclk_is_running())
{
/* Just waiting */
}
ret = app_timer_init();
APP_ERROR_CHECK(ret);
init_bsp();
#if NRF_CLI_ENABLED
init_cli();
#endif
app_usbd_serial_num_generate();
ret = app_usbd_init(&usbd_config);
APP_ERROR_CHECK(ret);
NRF_LOG_INFO("USBD CDC ACM example started.");
app_usbd_class_inst_t const * class_cdc_acm = app_usbd_cdc_acm_class_inst_get(&m_app_cdc_acm);
ret = app_usbd_class_append(class_cdc_acm);
APP_ERROR_CHECK(ret);
if (USBD_POWER_DETECTION)
{
ret = app_usbd_power_events_enable();
APP_ERROR_CHECK(ret);
}
else
{
NRF_LOG_INFO("No USB power detection enabled\r\nStarting USB now");
app_usbd_enable();
app_usbd_start();
}
while (true)
{
while (app_usbd_event_queue_process())
{
/* Nothing to do */
}
if(m_send_flag)
{
static int frame_counter;
size_t size = sprintf(m_tx_buffer, "Hello USB CDC FA demo: %u\r\n", frame_counter);
ret = app_usbd_cdc_acm_write(&m_app_cdc_acm, m_tx_buffer, size);
if (ret == NRF_SUCCESS)
{
++frame_counter;
}
}
#if NRF_CLI_ENABLED
nrf_cli_process(&m_cli_uart);
#endif
UNUSED_RETURN_VALUE(NRF_LOG_PROCESS());
/* Sleep CPU only if there was no interrupt since last loop processing */
__WFE();
}
}
/** @} */
At line 67 there is a conditional statement. In the debug phase the condition is not verified and therefore in the debug it would seem that frame_counter is not incremented. However trying the program it results that frame_counter is incremented.
Sorry if I can't explain myself well but I'm not very familiar with English as I am Swedish.
alexlöddeköpinge said:At line 67 there is a conditional statement. In the debug phase the condition is not verified and therefore in the debug it would seem that frame_counter is not incremented. However trying the program it results that frame_counter is incremented.
Ah, so it is. I understand. Could you go ahead and add a APP_ERROR_CHECK(ret) right after the line?
This should always be done when an error code is returned, in order to find out whether it was successful or not.
I am not certain why it was not added in the first place in the example, and will create an internal ticket to inquire about this, and ask that it is added in future versions.
If the error is != NRF_SUCCESS then the APP_ERROR_CHECK will print a more detailed error message to the log, before resetting the device ( default error handling ).
Please let me know what the outputted error message says.
alexlöddeköpinge said:Sorry if I can't explain myself well but I'm not very familiar with English as I am Swedish.
No worries, your English is fine for now and I will do my best to understand what you mean.
Best regards,
Karl
Please let me know what the outputted error message says.
The output is:
<error> app: Fatal error
<warning> app: System reset
Also adding the line as you advised me, when I press the button, frame_counter increases by a few units and then the system resets itself automatically. In other words, the program no longer works as it should. I thank you infinitely for your availability and for your precious collaboration. Have a nice day.
BR
alexlöddeköpinge said:The output is:
<error> app: Fatal error
<warning> app: System reset
Could you confirm for me which logger backend you are using, and that you have DEBUG defined in your preprocessor defines - like shown in the image I included in my first comment?
alexlöddeköpinge said:Also adding the line as you advised me, when I press the button, frame_counter increases by a few units and then the system resets itself automatically. In other words, the program no longer works as it should.
Yes, as I mentioned in my previous comment the default error handling done by APP_ERROR_CHECK when it receives an error code != NRF_CONNECT is to reset the device.
Defining DEBUG in the preprocessor defines will make a detailed error message be written to the log, which we may then use to identify the issue the application is encountering.
alexlöddeköpinge said:I thank you infinitely for your availability and for your precious collaboration. Have a nice day.
No problem at all, I am happy to help!
Looking forward to resolving this issue together.
Best regards,
Karl
Defining DEBUG in the preprocessor defines will make a detailed error message be written to the log, which we may then use to identify the issue the application is encountering.
<error> app: ERROR 17 [NRF_ERROR_BUSY] at C:\Users\blackp\Desktop\DeviceDownlo ad\nRF5SDK1702d674dde\nRF5_SDK_17.0.2_d674dde\examples\peripheral\usbd_cdc_acm\main.c:357
Maybe you are referring to this error code?
Thanks