SDK version: nRF5_SDK_15.3.0
Platform: nRF52840 DK
---
Add FreeRTOS into serial example(nRF5_SDK_15.3.0_59ac345\examples\peripheral\serial)
and I copy task of blinky_freertos example into this project, it work.
int main(void)
{
ret_code_t ret;
ret = nrf_drv_clock_init();
APP_ERROR_CHECK(ret);
ret = nrf_drv_power_init(NULL);
APP_ERROR_CHECK(ret);
nrf_drv_clock_lfclk_request(NULL);
ret = app_timer_init();
APP_ERROR_CHECK(ret);
// Initialize LEDs and buttons.
bsp_board_init(BSP_INIT_LEDS | BSP_INIT_BUTTONS);
#if 1
/* Create task for LED0 blinking with priority set to 2 */
UNUSED_VARIABLE(xTaskCreate(led_toggle_task_function, "LED0", configMINIMAL_STACK_SIZE + 200, NULL, 2, &led_toggle_task_handle));
led_toggle_timer_handle = xTimerCreate( "LED1", TIMER_PERIOD, pdTRUE, NULL, led_toggle_timer_callback);
UNUSED_VARIABLE(xTimerStart(led_toggle_timer_handle, 0));
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
vTaskStartScheduler();
while (true)
{
/* FreeRTOS should not be here... FreeRTOS goes back to the start of stack
* in vTaskStartScheduler function. */
}
#endif
}
Then, add uarte into main(): it's don't work.
int main(void)
{
ret_code_t ret;
ret = nrf_drv_clock_init();
APP_ERROR_CHECK(ret);
ret = nrf_drv_power_init(NULL);
APP_ERROR_CHECK(ret);
nrf_drv_clock_lfclk_request(NULL);
ret = app_timer_init();
APP_ERROR_CHECK(ret);
// Initialize LEDs and buttons.
bsp_board_init(BSP_INIT_LEDS | BSP_INIT_BUTTONS);
ret = nrf_serial_init(&serial_uart, &m_uart0_drv_config, &serial_config);
APP_ERROR_CHECK(ret);
static char tx_message[] = "Hello Tim!\n\r";
ret = nrf_serial_write(&serial_uart,
tx_message,
strlen(tx_message),
NULL,
NRF_SERIAL_MAX_TIMEOUT);
APP_ERROR_CHECK(ret);
while (true)
{
char c;
ret = nrf_serial_read(&serial_uart, &c, sizeof(c), NULL, 1000);
if (ret != NRF_SUCCESS)
{
continue;
}
(void)nrf_serial_write(&serial_uart, &c, sizeof(c), NULL, 0);
(void)nrf_serial_flush(&serial_uart, 0);
}
#if 1
/* Create task for LED0 blinking with priority set to 2 */
UNUSED_VARIABLE(xTaskCreate(led_toggle_task_function, "LED0", configMINIMAL_STACK_SIZE + 200, NULL, 2, &led_toggle_task_handle));
led_toggle_timer_handle = xTimerCreate( "LED1", TIMER_PERIOD, pdTRUE, NULL, led_toggle_timer_callback);
UNUSED_VARIABLE(xTimerStart(led_toggle_timer_handle, 0));
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
vTaskStartScheduler();
while (true)
{
/* FreeRTOS should not be here... FreeRTOS goes back to the start of stack
* in vTaskStartScheduler function. */
}
#endif
}
I find that
In nrf_serial_read() call timeout_setup() to create timer (call app_timer_create())
but the app_timer_create() return errorcode = 8 (Invalid state, operation disallowed in this state)
I not sure why errorcode=8, and how to fix?

and timer create fail

BTW, I include app_timer_freertos.c instead of app_timer.c, and use RTC1.
https://drive.google.com/file/d/1LnsNW1LME_fONC2Wyhs8Pjsr-679NLJJ/view
Thanks,
Tim