This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

add uart peripheral into client example returns "app_error_weak.c, 105, Mesh assert at 0x0002C8B0 (:0)"

I am using sdk for mesh v.5 (s140.7.2.0) and nrf52840 DK and want to add uart peripheral into the client in the light switch mesh example and then trigger button 1 once a sting data is received.

I added drivers and libraries c.files of the art peripheral, paths, headers, and finally added these functions in the main.c file.

void uart_error_handle(app_uart_evt_t * p_event)
void uart_event_handle(app_uart_evt_t * p_event)
void uart_init(void)

And with an "if" I checked a string received from uart and then I trigger buttun1 by call the "button_event_handler(button_number)" function.

and I added the "uart_init()" function in the main () function .


When I press the button 1 it works fine, although when I write the "string" on the uart, it returns:


<t: 0>, main.c, 573, ----- BLE Mesh Light Switch Client Demo -----
<t: 12650>, main.c, 412, Initializing and adding models
<t: 12702>, main.c, 209, Node Address: 0x0004
<t: 12704>, mesh_app_utils.c, 66, Device UUID (raw): 137FF47B11294702B381A62F60654E45
<t: 12708>, mesh_app_utils.c, 67, Device UUID : 137FF47B-1129-4702-B381-A62F60654E45
<t: 12731>, main.c, 625,
------------------------------------------------------------------------------------
Button/RTT 1) Send a message to the odd group (address: 0xC003) to turn on LED 1.
Button/RTT 2) Send a message to the odd group (address: 0xC003) to turn off LED 1.
Button/RTT 3) Send a message to the even group (address: 0xC002) to turn on LED 1.
Button/RTT 4) Send a message to the even group (address: 0xC002) to turn off LED 1.
------------------------------------------------------------------------------------
<t: 483794>, main.c, 489, Data is Successfully Received
<t: 483797>, main.c, 312, Button 1 pressed
<t: 483799>, main.c, 335, Sending msg: ONOFF SET 1
<t: 483809>, app_error_weak.c, 105, Mesh assert at 0x0002C8B0 (:0)

I searched my problem and found this case.

So I tried to add app_scheduler in my codes based on this tutorial.

#include "app_scheduler.h"

static void button_event_handler_app_sched(void * p_event_data, uint16_t event_size)
{
uint8_t * button_number = (uint8_t *) p_event_data;
NRF_MESH_ASSERT(event_size == 1);
button_event_handler(*button_number);
}
static void button_event_handler_irq(uint32_t button_number)
{
static uint8_t bt_num;
bt_num = button_number;
app_sched_event_put((void *)&bt_num, sizeof(bt_num), button_event_handler_app_sched);
}

static void initialize(void)

{

.

.

#if BUTTON_BOARD
ERROR_CHECK(hal_buttons_init(button_event_handler_irq));
#endif

.

.

.

}

int main(void)
{

///////////////////////add by Sama
/*scheduler*/
APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, SCHED_QUEUE_SIZE);
app_sched_execute();

/*UART_Interface*/
uart_init();

///////////////////////end by Sama
initialize();
start();

for (;;)
{
/*scheduler*/
//(void)sd_app_evt_wait();
bool done = nrf_mesh_process();
if (done)
{
sd_app_evt_wait();
}

}
}

However, it does not work. Here is the log file:
t: 0>, main.c, 594, ----- BLE Mesh Light Switch Client Demo -----
<t: 12031>, app_error_weak.c, 115, Mesh error 8 at 0x0002846B (D:\Behine Niroo\Nordic\NRF Mesh\nrf5_SDK_for_Mesh_v5.0.0_src\examples\common\src\simple_hal.c:244)

Could you please advise me?

Thank you in advance.

Br,

Sama

Parents
  • Hi Sama, 
    I have made an example here. It could be useful for you. 

  • Hi Hung,

    Thank you very much for your reply.


    I can read from and write on the UART by enabling the peripheral resource sharing for UART and UARTE. This was done by setting #define NRFX_PRS_ENABLED 1' and '#define NRFX_PRS_BOX_2_ENABLED 1' in your sdk_config.h file.

    My trouble is that I want to call "button_event_handler(button_number)" function from the "uart_event_handle(app_uart_evt_t * p_event)" function, exactly same as this case .

     initialized the Mesh stack with NRF_MESH_IRQ_PRIORITY_LOWEST but that did not work and returned "Mesh assert at 0x0002C8B0 (:0)". 

    I thought this needs to have a scheduler to order the interrupts.
    Isn't it?

    Br,
    Sama

  • Hi Hung,

    I did not use the "app scheduler".

    The "timer scheduler" was added in the client example by default in the Core folder.

    I have just added the drivers and libraries of UART into the client example as you can see in the image.

    As I said when I change the priority of the UART it works fine.

    I have another question that may be not related to this topic.

    Is it possible to use the UART peripheral beside the DFU mesh example?

    Actually, I want to have a serial connection to send and receive string data, and also do DFU mesh through the serial port. 

    Please let me know if I should create a new case for my question.

    Br,

    Sama

  • No I'm talking about the app_scheduler you used: 

    ///////////////////////add by Sama
    /*scheduler*/
    APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, SCHED_QUEUE_SIZE);
    app_sched_execute();

    I'm not sure which priority you used when init mesh inside mesh_init() but please follow the correct interrupt priority. 

    Regarding your question, if you want to add your own command to the serial example you would need to have a look inside the serial.h, there you can find the list of command. For example DFU command is from 0xD0 to 0xDF. 
    You can define your own command from 0x30 to 0x3F for example. 
    You then can handle your own command by adding your handler inside m_cmd_handlers[] inside serial.c 

  • Hi Hung,

    I am sorry if my explanations were confusing.


    Using "app_scheduler" was my first test that did not work.
    After that, I create a new file in which I added UART into the client example. Then I changed "APP_IRQ_PRIORITY_LOWEST" to "APP_IRQ_PRIORITY_LOW" in the "APP_UART_FIFO_INIT" function, solving the problem. Please have a look at this case.

    I will send you my codes to have a look.
    I appreciate it if you can help me to add a serial communication to send data and also to do DFU.

    Br,

    Sama

  • Hi Sama, 

    Have you followed what I suggest ? There should be very minor change in the serial.h file and then you describe your own uart handler that handles the UART opcode 0x30 to 0x3F that you define yourself. 

  • Hi Hung,

    Sorry for my late reply. I was involved in the other parts of the project.

    I found this ticket in which two UARTs are used for mesh and SDK. 

    Is it possible for my case?

    Br,

    Sama

Reply Children
  • Could you send the ticket ? 
    Have you looked into my suggestion ? You need to get to understand how the serial layer works and then you will know what you need to define to add your own opcode. 

  • Hi Hung,

    Thank you for your quick reply.

    Sorry, the link was missed.

    I had a look at the serial and the serial_cmd.h where all opcodes are defined. I found that more difficult than using two UARTs. isn't it?

    I am looking for the most simple method.

    Br,

    Sama 

  • Hi Sama, 
    I don't think using 2 UART would help much here. You would need to have 2 cables connected to PC. One for UART0 and one for UART1. 
    If that OK for you you can follow what I suggested in the case to implement. But I do think that you can just edit the serial library in mesh to add your own opcode it's much more simpler. 

  • Hi,

    There is no problem with the two cables. So there are two ways:

    1. using two UARTs

    What is the pin map of UARTE1? Can I use the nRF USB MicroUSB connector on the board? 

    2. using usbd_cdc_acm

    I have added the usbd_cdc_acm to the client codes. I am facing the problem with app_timer2 and app_timer_mesh. There are many definitions common in both files. I exclusive the app_timer2 and drv_rtc leading to mesh error 8.

    After that, I added two files and I tried to comment out the common definitions and change the name of app_timer_init in the app_timer2 and main. the codes were built without any compiler error. However, this returned "app_error_weak.c,  115, Mesh error 133 at 0x00000000"

    any solution?

    Br,

    Sama

  • Hi Sama, 
    1. Please tell how you plan to use UARTE1 ? Are you using the nrf_drv_uart or you are using the serial_uart from mesh SDK ? 
    The nrf_drv_uart use the configuration when you call APP_UART_FIFO_INIT() you can choose the pin their. You would need to select the APP_UART_DRIVER_INSTANCE to 1. See here.

    2. You may want to debug the mesh application and tell where the error is. 

    I really think that you are complicated thing up. It can be much easier if you follow what I suggested. Just add you own opcode in the serial.h file and you can do your own communication with the same UART as for DFU or serial mesh. Let me know if there is anything you don't understand on that. 

Related