espressif / esp-modbus

ESP-Modbus - the officially suppported library for Modbus protocol (serial RS485 + TCP over WiFi or Ethernet).
Apache License 2.0
85 stars 46 forks source link

multi UART conflict (IDFGH-12165) #53

Open ss1k opened 5 months ago

ss1k commented 5 months ago

The project I'm working on right now, uses UART0 for NB-IOT communication, and UART1 for modbus. The problem occurs when setting up modbus, when it enters critical, the modbus's log info will be received by UART0. Following are those wrongly received message.

'D (59601) MB_PORT_COMMON: vMBPortSetMode: Port enter critical.[0m  
D (59601) MB_PORT_COMMON: vMBPortSetMode: Port exit critical[0m
D (59601) MB_PORT_COMMON: eMBMasterRTUInit: Port enter critical.[0m
D (59611) intr_alloc: Connected src 22 to int 9 (cpu 0)[0m
D (59611) MB_PORT_COMMON: eMBMasterRTUInit: Port exit critical[0m
D (59621) MB_PORT_COMMON: eMBMasterRTUStart: Port enter critical.[0m
D (59631) MB_PORT_COD (59631) DBG: RTU timer, init FSM state.[0m
D (59631) MBM_TIMER: Timer mode: (0) triggered[0m
MMON: eMBMasterRTUStart: Port exit critical[0m
ERROR

ERROR

ERROR

ERROR

ERROR

ERROR

ERROR

ERROR

ERROR
D (59691) MB_PORT_COMMON: eMBMasterRTUSend: Port enter critical.[0m
D (59691) MB_PORT_COMMON: eMBMasterRTUSend: Port exit critical[0m
D (59701) MB_PORT_COMMON: eMBMasterRTUReceive: Port enter critical.[0m
D (59701) MB_PORT_COMMON: eMBMasterRTUReceive: Port exit critical[0m
D (59701) MB_PORT_COMMON: eMBMasterRTUStop: Port enter critical.[0m
D (59711) MB_PORT_COMMON: eMBMasterRTUStop: Port exit critical[0m
D (59711) MB_PORT_COMMON: vMBPortSetMode: Port enter critical.[0m
D (59721) MB_PORT_COMMON: vMBPortSetMode: Port exit critical[0m
ERROR

ERROR

ERROR

ERROR

ERROR

ERROR

ERROR

ERROR
'
static _lock_t s_port_lock;
inline void
vMBPortEnterCritical(void)
{
    _lock_acquire(&s_port_lock);
}

inline void
vMBPortExitCritical(void)
{
    _lock_release(&s_port_lock);
}

I tried to assign s_port_lock to 1, since _lock_t is an Interger essentially, but it doesn't work. So I just commented out enter/exit critical and changed ESP_EARLY_LOGD into ESP_LOGD, most of the wrong message can be handled properly, but still

'D (9799) intr_alloc: Connected src 22 to int 9 (cpu 0)[0m

ERROR'

this line of modbus information be received by NB-IOT.

Is there a way to change value of s_port_lock? or what are the other solutions to address my problem?

alisitsyn commented 5 months ago

Hi @ss1k,

What kind of board and chip are used in your project? I guess you configured your ports incorrectly, NB_IOT and console use the same port = UART0. The default settings for console is UART0 and this is the port where the modbus and other software send the log messages. idf.py menuconfig: image

ss1k commented 5 months ago

Hi @ss1k,

What kind of board and chip are used in your project? I guess you configured your ports incorrectly, NB_IOT and console use the same port = UART0. The default settings for console is UART0 and this is the port where the modbus and other software send the log messages. idf.py menuconfig: image

Hi @alisitsyn, I use a self-designed board and the chip is esp32c3, we solder the UART0 and NB_IOT module together, in this case, we can only use UART1 for modbus. The console port is UART0, and we can see the message from NB_IOT side, at the same time, the AT receiving message task of NB_IOT is running, that's why I don't wanna modbus's log message to be sent to UART0. Is there a way to change the UART of modbus? Thanks

alisitsyn commented 5 months ago

Is there a way to change the UART of modbus?

it is possible to change the working port of modbus but it is impossible to change the logging port for modbus. It is also possible to disable some messages of modbus but the component uses the unique tag for each module. I think the better way is to change the logging behavior of the component moving it to your_project/components folder and redefine the logging macros to some custom redefined versions. In this case you will be able to control the logging of Modbus as you need.

logging

Is there a way to change value of s_port_lock? or what are the other solutions to address my problem?

The s_port_lock is the log for critical section of modbus port functionality. I don't think you need to change this. You can just redefine the log output macro as you need, the lock functions itself should not output anything into port.

'D (9799) intr_alloc: Connected src 22 to int 9 (cpu 0)[0m

This comes from interrupt allocation module and can be disabled: esp_log_level_set("intr_alloc", ESP_LOG_NONE);

Please also consider to disable the standard logging output functionality in this case and use your UART0 for NB_IOT only:

ss1k commented 4 months ago

Is there a way to change the UART of modbus?

it is possible to change the working port of modbus but it is impossible to change the logging port for modbus. It is also possible to disable some messages of modbus but the component uses the unique tag for each module. I think the better way is to change the logging behavior of the component moving it to your_project/components folder and redefine the logging macros to some custom redefined versions. In this case you will be able to control the logging of Modbus as you need.

logging

Is there a way to change value of s_port_lock? or what are the other solutions to address my problem?

The s_port_lock is the log for critical section of modbus port functionality. I don't think you need to change this. You can just redefine the log output macro as you need, the lock functions itself should not output anything into port.

'D (9799) intr_alloc: Connected src 22 to int 9 (cpu 0)[0m

This comes from interrupt allocation module and can be disabled: esp_log_level_set("intr_alloc", ESP_LOG_NONE);

Please also consider to disable the standard logging output functionality in this case and use your UART0 for NB_IOT only: "idf.py menuconfig", go to "Bootloader config" and set "Bootloader log verbosity" to "No output" to disable bootloader output "idf.py menuconfig", go to "Component config", "Log output", set "Default log verbosity" to "No output" to disable application output; Would this work for your project or you need some custom logging behavior also? Please let me know if this helps. Thanks.

Thank you so much for your help, we will change the logging behavior and move the modbus component under our project directory, I will let you know how's the result soon!