if (it->handle == handle) {
// must erase the partition before writing to it
assert(it->erased_size > 0 && "must erase the partition before writing to it");
-
- if(it->wrote_size == 0 && size > 0 && data_bytes[0] != 0xE9) {
+ if (it->wrote_size == 0 && it->partial_bytes == 0 && size > 0 && data_bytes[0] != ESP_IMAGE_HEADER_MAGIC) {
ESP_LOGE(TAG, "OTA image has invalid magic byte (expected 0xE9, saw 0x%02x", data_bytes[0]);
return ESP_ERR_OTA_VALIDATE_FAILED;
}
config BTDM_MODEM_SLEEP_MODE_ORIG
bool "ORIG Mode(sleep with low power clock)"
help
- ORIG mode is a deep sleep mode that can be used for dual mode controller. In this mode, bluetooth controller sleeps between BR/EDR frames and BLE events. A low power clock is used to maintain bluetooth reference clock.
+ ORIG mode is a bluetooth sleep mode that can be used for dual mode controller. In this mode, bluetooth controller
+ sleeps between BR/EDR frames and BLE events. A low power clock is used to maintain bluetooth reference clock.
config BTDM_MODEM_SLEEP_MODE_EVED
- bool "EVED Mode "
+ bool "EVED Mode(For internal test only)"
help
- This mode is for BLE only.
+ EVED mode is for BLE only and is only for internal test. Do not use it for production. this mode is not compatible
+ with DFS nor light sleep
endchoice
choice BTDM_LOW_POWER_CLOCK
help
Main crystal can be used as low power clock for bluetooth modem sleep. If this option is selected, bluetooth
modem sleep can work under Dynamic Frequency Scaling(DFS) enabled, but cannot work when light sleep is enabled.
+ Main crystal has a relatively better performance than other bluetooth low power clock sources.
config BTDM_LPCLK_SEL_EXT_32K_XTAL
bool "External 32kHz crystal"
depends on ESP32_RTC_CLOCK_SOURCE_EXTERNAL_CRYSTAL
/* Sleep mode */
#define BTDM_MODEM_SLEEP_MODE_NONE (0)
#define BTDM_MODEM_SLEEP_MODE_ORIG (1)
-#define BTDM_MODEM_SLEEP_MODE_EVED (2)
+#define BTDM_MODEM_SLEEP_MODE_EVED (2) // sleep mode for BLE controller, used only for internal test.
/* Low Power Clock Selection */
#define BTDM_LPCLK_SEL_XTAL (0)
i2s_mode_t mode; /*!< I2S Working mode*/
uint32_t sample_rate; /*!< I2S sample rate */
bool use_apll; /*!< I2S use APLL clock */
+ bool tx_desc_auto_clear; /*!< I2S auto clear tx descriptor on underflow */
int fixed_mclk; /*!< I2S fixed MLCK clock */
} i2s_obj_t;
// All buffers are empty. This means we have an underflow on our hands.
if (xQueueIsQueueFullFromISR(p_i2s->tx->queue)) {
xQueueReceiveFromISR(p_i2s->tx->queue, &dummy, &high_priority_task_awoken);
+ // See if tx descriptor needs to be auto cleared:
+ // This will avoid any kind of noise that may get introduced due to transmission
+ // of previous data from tx descriptor on I2S line.
+ if (p_i2s->tx_desc_auto_clear == true) {
+ memset((void *) dummy, 0, p_i2s->tx->buf_size);
+ }
}
xQueueSendFromISR(p_i2s->tx->queue, (void*)(&finish_desc->buf), &high_priority_task_awoken);
if (p_i2s->i2s_queue) {
}
p_i2s_obj[i2s_num]->use_apll = i2s_config->use_apll;
+ p_i2s_obj[i2s_num]->tx_desc_auto_clear = i2s_config->tx_desc_auto_clear;
p_i2s_obj[i2s_num]->fixed_mclk = i2s_config->fixed_mclk;
return ESP_OK;
}
int dma_buf_count; /*!< I2S DMA Buffer Count */
int dma_buf_len; /*!< I2S DMA Buffer Length */
bool use_apll; /*!< I2S using APLL as main I2S clock, enable it to get accurate clock */
+ bool tx_desc_auto_clear; /*!< I2S auto clear tx descriptor if there is underflow condition (helps in avoiding noise in case of data unavailability) */
int fixed_mclk; /*!< I2S using fixed MCLK output. If use_apll = true and fixed_mclk > 0, then the clock output for i2s is fixed and equal to the fixed_mclk value.*/
} i2s_config_t;
-Subproject commit acc7e050c8ab15b04d2ac97085ba49823b8cd911
+Subproject commit 9db42853fe76e5d7cae9c72e823febf757b38a2e
menu "Modbus configuration"
-config MB_UART_RXD
- int "UART RXD pin number"
- range 0 34
- default 22
- help
- GPIO number for UART RX pin. See UART documentation for more information
- about available pin numbers for UART.
-
-config MB_UART_TXD
- int "UART TXD pin number"
- range 0 34
- default 23
- help
- GPIO number for UART TX pin. See UART documentation for more information
- about available pin numbers for UART.
-
-config MB_UART_RTS
- int "UART RTS pin number"
- range 0 34
- default 18
- help
- GPIO number for UART RTS pin. This pin is connected to
- ~RE/DE pin of RS485 transceiver to switch direction.
-
config MB_QUEUE_LENGTH
int "Modbus serial task queue length"
range 0 200
xErr = uart_param_config(ucUartNumber, &xUartConfig);
MB_PORT_CHECK((xErr == ESP_OK),
FALSE, "mb config failure, uart_param_config() returned (0x%x).", (uint32_t)xErr);
- // Set UART pin numbers
- xErr = uart_set_pin(ucUartNumber, MB_UART_TXD, MB_UART_RXD, MB_UART_RTS, UART_PIN_NO_CHANGE);
- MB_PORT_CHECK((xErr == ESP_OK), FALSE,
- "mb set pin failure, uart_set_pin() returned (0x%x).", (uint32_t)xErr);
// Install UART driver, and get the queue.
xErr = uart_driver_install(ucUartNumber, MB_SERIAL_BUF_SIZE, MB_SERIAL_BUF_SIZE,
MB_QUEUE_LENGTH, &xMbUartQueue, ESP_INTR_FLAG_LOWMED);
MB_PORT_CHECK((xErr == ESP_OK), FALSE,
"mb serial driver failure, uart_driver_install() returned (0x%x).", (uint32_t)xErr);
- // Set driver mode to Half Duplex
- xErr = uart_set_mode(ucUartNumber, UART_MODE_RS485_HALF_DUPLEX);
- MB_PORT_CHECK((xErr == ESP_OK), FALSE,
- "mb serial set mode failure, uart_set_mode() returned (0x%x).", (uint32_t)xErr);
#ifndef MB_TIMER_PORT_ENABLED
// Set timeout for TOUT interrupt (T3.5 modbus time)
xErr = uart_set_rx_timeout(ucUartNumber, MB_SERIAL_TOUT);
-Subproject commit 046fadde072b5fca94bea84c16cce5ecbfd6948e
+Subproject commit 0865edf80ad0a96e0eaf2bbedbad350cab248115
#include "mdns.h"
#include "mdns_private.h"
#include "mdns_networking.h"
+#include "esp_log.h"
#include <string.h>
#ifdef MDNS_ENABLE_DEBUG
mdns_server_t * _mdns_server = NULL;
+static const char *TAG = "MDNS";
+
static volatile TaskHandle_t _mdns_service_task_handle = NULL;
static SemaphoreHandle_t _mdns_service_semaphore = NULL;
//need to add -2 to string
ret = malloc(strlen(in) + 3);
if (ret == NULL) {
+ HOOK_MALLOC_FAILED;
return NULL;
}
sprintf(ret, "%s-2", in);
} else {
ret = malloc(strlen(in) + 2); //one extra byte in case 9-10 or 99-100 etc
+ if (ret == NULL) {
+ HOOK_MALLOC_FAILED;
+ return NULL;
+ }
strcpy(ret, in);
int baseLen = p - in; //length of 'bla' in 'bla-123'
//overwrite suffix with new suffix
action = (mdns_action_t *)malloc(sizeof(mdns_action_t));
if (!action) {
+ HOOK_MALLOC_FAILED;
return ESP_ERR_NO_MEM;
}
return 0;
}
data_len += l;
+ } else {
+ HOOK_MALLOC_FAILED;
+ // continue
}
txt = txt->next;
}
mdns_out_answer_t * a = (mdns_out_answer_t *)malloc(sizeof(mdns_out_answer_t));
if (!a) {
+ HOOK_MALLOC_FAILED;
return false;
}
a->type = type;
{
mdns_tx_packet_t * packet = (mdns_tx_packet_t*)malloc(sizeof(mdns_tx_packet_t));
if (!packet) {
+ HOOK_MALLOC_FAILED;
return NULL;
}
memset((uint8_t*)packet, 0, sizeof(mdns_tx_packet_t));
for (i=0; i<len; i++) {
mdns_out_question_t * q = (mdns_out_question_t *)malloc(sizeof(mdns_out_question_t));
if (!q) {
+ HOOK_MALLOC_FAILED;
_mdns_free_tx_packet(packet);
return NULL;
}
if (include_ip && !_str_null_or_empty(_mdns_server->hostname)) {
mdns_out_question_t * q = (mdns_out_question_t *)malloc(sizeof(mdns_out_question_t));
if (!q) {
+ HOOK_MALLOC_FAILED;
_mdns_free_tx_packet(packet);
return NULL;
}
if (services_final_len) {
_services = (mdns_srv_item_t **)malloc(sizeof(mdns_srv_item_t *) * services_final_len);
if (!_services) {
+ HOOK_MALLOC_FAILED;
return;
}
for (i=0; i<num_items; i++) {
mdns_txt_linked_item_t * new_item = (mdns_txt_linked_item_t *)malloc(sizeof(mdns_txt_linked_item_t));
if (!new_item) {
+ HOOK_MALLOC_FAILED;
break;
}
new_item->key = strdup(txt[i].key);
{
mdns_service_t * s = (mdns_service_t *)malloc(sizeof(mdns_service_t));
if (!s) {
+ HOOK_MALLOC_FAILED;
return NULL;
}
sprintf(tmp, "%s=%s", txt->key, txt->value);
_mdns_append_string(ours, &index, tmp);
free(tmp);
+ } else {
+ HOOK_MALLOC_FAILED;
+ // continue
}
txt = txt->next;
}
}
mdns_txt_item_t * txt = (mdns_txt_item_t *)malloc(sizeof(mdns_txt_item_t) * num_items);
+ if (!txt) {
+ HOOK_MALLOC_FAILED;
+ return;
+ }
memset(txt, 0, sizeof(mdns_txt_item_t) * num_items);
size_t txt_num = 0;
}
char * key = (char *)malloc(name_len + 1);
if (!key) {
+ HOOK_MALLOC_FAILED;
goto handle_error;//error
}
int value_len = partLen - name_len - 1;
if (value_len > 0) {
char * value = (char *)malloc(value_len + 1);
+ if (!value) {
+ HOOK_MALLOC_FAILED;
+ goto handle_error;//error
+ }
memcpy(value, data + i, value_len);
value[value_len] = 0;
i += value_len;
mdns_parsed_packet_t * parsed_packet = (mdns_parsed_packet_t *)malloc(sizeof(mdns_parsed_packet_t));
if (!parsed_packet) {
+ HOOK_MALLOC_FAILED;
return;
}
memset(parsed_packet, 0, sizeof(mdns_parsed_packet_t));
while (a) {
mdns_parsed_question_t * question = (mdns_parsed_question_t *)malloc(sizeof(mdns_parsed_question_t));
if (!question) {
+ HOOK_MALLOC_FAILED;
goto clear_rx_packet;
}
question->next = parsed_packet->questions;
mdns_parsed_question_t * question = (mdns_parsed_question_t *)malloc(sizeof(mdns_parsed_question_t));
if (!question) {
+ HOOK_MALLOC_FAILED;
goto clear_rx_packet;
}
question->next = parsed_packet->questions;
if (search_result) {
mdns_txt_item_t * txt = NULL;
size_t txt_count = 0;
- _mdns_result_txt_create(data_ptr, data_len, &txt, &txt_count);
- if (!txt_count) {
- continue;
- }
mdns_result_t * result = NULL;
if (search_result->type == MDNS_TYPE_PTR) {
}
}
if (!result->txt) {
- result->txt = txt;
- result->txt_count = txt_count;
+ _mdns_result_txt_create(data_ptr, data_len, &txt, &txt_count);
+ if (txt_count) {
+ result->txt = txt;
+ result->txt_count = txt_count;
+ }
}
} else {
_mdns_search_result_add_txt(search_result, txt, txt_count, packet->tcpip_if, packet->ip_protocol);
{
mdns_search_once_t * search = (mdns_search_once_t *)malloc(sizeof(mdns_search_once_t));
if (!search) {
+ HOOK_MALLOC_FAILED;
return NULL;
}
memset(search, 0, sizeof(mdns_search_once_t));
{
mdns_ip_addr_t * a = (mdns_ip_addr_t *)malloc(sizeof(mdns_ip_addr_t));
if (!a) {
+ HOOK_MALLOC_FAILED;
return NULL;
}
memset(a, 0 , sizeof(mdns_ip_addr_t));
if (!search->max_results || search->num_results < search->max_results) {
r = (mdns_result_t *)malloc(sizeof(mdns_result_t));
if (!r) {
+ HOOK_MALLOC_FAILED;
return;
}
if (!search->max_results || search->num_results < search->max_results) {
r = (mdns_result_t *)malloc(sizeof(mdns_result_t));
if (!r) {
+ HOOK_MALLOC_FAILED;
return NULL;
}
if (!search->max_results || search->num_results < search->max_results) {
r = (mdns_result_t *)malloc(sizeof(mdns_result_t));
if (!r) {
+ HOOK_MALLOC_FAILED;
return;
}
while (r) {
if (r->tcpip_if == tcpip_if && r->ip_protocol == ip_protocol) {
if (r->txt) {
- return;
+ goto free_txt;
}
r->txt = txt;
r->txt_count = txt_count;
if (!search->max_results || search->num_results < search->max_results) {
r = (mdns_result_t *)malloc(sizeof(mdns_result_t));
if (!r) {
- for (i=0; i<txt_count; i++) {
- free((char *)(txt[i].key));
- free((char *)(txt[i].value));
- }
- free(txt);
- return;
+ HOOK_MALLOC_FAILED;
+ goto free_txt;
}
memset(r, 0 , sizeof(mdns_result_t));
search->result = r;
search->num_results++;
}
+ return;
+
+free_txt:
+ for (i=0; i<txt_count; i++) {
+ free((char *)(txt[i].key));
+ free((char *)(txt[i].value));
+ }
+ free(txt);
}
/**
mdns_out_question_t * q = (mdns_out_question_t *)malloc(sizeof(mdns_out_question_t));
if (!q) {
+ HOOK_MALLOC_FAILED;
_mdns_free_tx_packet(packet);
return NULL;
}
}
mdns_out_answer_t * a = (mdns_out_answer_t *)malloc(sizeof(mdns_out_answer_t));
if (!a) {
+ HOOK_MALLOC_FAILED;
_mdns_free_tx_packet(packet);
return NULL;
}
*/
static void _mdns_search_send(mdns_search_once_t * search)
{
+ mdns_search_once_t* queue = _mdns_server->search_once;
+ bool found = false;
+ // looking for this search in active searches
+ while (queue) {
+ if (queue == search) {
+ found = true;
+ break;
+ }
+ queue = queue->next;
+ }
+
+ if (!found) {
+ // no longer active -> skip sending this search
+ return;
+ }
+
uint8_t i, j;
for (i=0; i<TCPIP_ADAPTER_IF_MAX; i++) {
for (j=0; j<MDNS_IP_PROTOCOL_MAX; j++) {
if (!txt) {
txt = (mdns_txt_linked_item_t *)malloc(sizeof(mdns_txt_linked_item_t));
if (!txt) {
+ HOOK_MALLOC_FAILED;
_mdns_free_action(action);
return;
}
action = (mdns_action_t *)malloc(sizeof(mdns_action_t));
if (!action) {
+ HOOK_MALLOC_FAILED;
return ESP_ERR_NO_MEM;
}
free(action);
_mdns_server->tx_queue_head = p;
}
+ } else {
+ HOOK_MALLOC_FAILED;
+ // continue
}
}
MDNS_SERVICE_UNLOCK();
*/
static void _mdns_search_run()
{
+ MDNS_SERVICE_LOCK();
mdns_search_once_t * s = _mdns_server->search_once;
uint32_t now = xTaskGetTickCount() * portTICK_PERIOD_MS;
if (!s) {
+ MDNS_SERVICE_UNLOCK();
return;
}
- MDNS_SERVICE_LOCK();
while (s) {
if (s->state != SEARCH_OFF) {
if (now > (s->started_at + s->timeout)) {
{
MDNS_SERVICE_LOCK();
_mdns_stop_timer();
+ MDNS_SERVICE_UNLOCK();
if (_mdns_service_task_handle) {
mdns_action_t action;
mdns_action_t * a = &action;
vTaskDelay(10 / portTICK_PERIOD_MS);
}
}
- MDNS_SERVICE_UNLOCK();
return ESP_OK;
}
mdns_action_t * action = (mdns_action_t *)malloc(sizeof(mdns_action_t));
if (!action) {
+ HOOK_MALLOC_FAILED;
return ESP_OK;
}
action->type = ACTION_SYSTEM_EVENT;
_mdns_server = (mdns_server_t *)malloc(sizeof(mdns_server_t));
if (!_mdns_server) {
+ HOOK_MALLOC_FAILED;
return ESP_ERR_NO_MEM;
}
memset((uint8_t*)_mdns_server, 0, sizeof(mdns_server_t));
if (!_mdns_server) {
return;
}
- _mdns_service_task_stop();
mdns_service_remove_all(_mdns_server);
+ _mdns_service_task_stop();
for (i=0; i<TCPIP_ADAPTER_IF_MAX; i++) {
for (j=0; j<MDNS_IP_PROTOCOL_MAX; j++) {
_mdns_pcb_deinit(i, j);
mdns_action_t * action = (mdns_action_t *)malloc(sizeof(mdns_action_t));
if (!action) {
+ HOOK_MALLOC_FAILED;
free(new_hostname);
return ESP_ERR_NO_MEM;
}
mdns_action_t * action = (mdns_action_t *)malloc(sizeof(mdns_action_t));
if (!action) {
+ HOOK_MALLOC_FAILED;
free(new_instance);
return ESP_ERR_NO_MEM;
}
item = (mdns_srv_item_t *)malloc(sizeof(mdns_srv_item_t));
if (!item) {
+ HOOK_MALLOC_FAILED;
_mdns_free_service(s);
return ESP_ERR_NO_MEM;
}
mdns_action_t * action = (mdns_action_t *)malloc(sizeof(mdns_action_t));
if (!action) {
+ HOOK_MALLOC_FAILED;
_mdns_free_service(s);
free(item);
return ESP_ERR_NO_MEM;
mdns_action_t * action = (mdns_action_t *)malloc(sizeof(mdns_action_t));
if (!action) {
+ HOOK_MALLOC_FAILED;
return ESP_ERR_NO_MEM;
}
action->type = ACTION_SERVICE_PORT_SET;
mdns_action_t * action = (mdns_action_t *)malloc(sizeof(mdns_action_t));
if (!action) {
+ HOOK_MALLOC_FAILED;
_mdns_free_linked_txt(new_txt);
return ESP_ERR_NO_MEM;
}
}
mdns_action_t * action = (mdns_action_t *)malloc(sizeof(mdns_action_t));
if (!action) {
+ HOOK_MALLOC_FAILED;
return ESP_ERR_NO_MEM;
}
}
mdns_action_t * action = (mdns_action_t *)malloc(sizeof(mdns_action_t));
if (!action) {
+ HOOK_MALLOC_FAILED;
return ESP_ERR_NO_MEM;
}
mdns_action_t * action = (mdns_action_t *)malloc(sizeof(mdns_action_t));
if (!action) {
+ HOOK_MALLOC_FAILED;
free(new_instance);
return ESP_ERR_NO_MEM;
}
mdns_action_t * action = (mdns_action_t *)malloc(sizeof(mdns_action_t));
if (!action) {
+ HOOK_MALLOC_FAILED;
return ESP_ERR_NO_MEM;
}
action->type = ACTION_SERVICE_DEL;
mdns_action_t * action = (mdns_action_t *)malloc(sizeof(mdns_action_t));
if (!action) {
+ HOOK_MALLOC_FAILED;
return ESP_ERR_NO_MEM;
}
action->type = ACTION_SERVICES_CLEAR;
*/
#include <string.h>
#include "mdns_networking.h"
+#include "esp_log.h"
extern mdns_server_t * _mdns_server;
* MDNS Server Networking
*
*/
+static const char *TAG = "MDNS_Networking";
static struct udp_pcb * _pcb_main = NULL;
mdns_rx_packet_t * packet = (mdns_rx_packet_t *)malloc(sizeof(mdns_rx_packet_t));
if (!packet) {
+ HOOK_MALLOC_FAILED;
//missed packet - no memory
pbuf_free(this_pb);
continue;
#define MDNS_SEARCH_LOCK() xSemaphoreTake(_mdns_server->search.lock, portMAX_DELAY)
#define MDNS_SEARCH_UNLOCK() xSemaphoreGive(_mdns_server->search.lock)
+#ifndef HOOK_MALLOC_FAILED
+#define HOOK_MALLOC_FAILED ESP_LOGE(TAG, "Cannot allocate memory (line: %d, free heap: %d bytes)", __LINE__, esp_get_free_heap_size());
+#endif
typedef enum {
PCB_OFF, PCB_DUP, PCB_INIT,
#define RTC_SLOW_CLK_FREQ_8MD256 (RTC_FAST_CLK_FREQ_8M / 256)
#define RTC_SLOW_CLK_FREQ_32K 32768
+/* BBPLL configuration values */
#define BBPLL_ENDIV5_VAL_320M 0x43
#define BBPLL_BBADC_DSMP_VAL_320M 0x84
#define BBPLL_ENDIV5_VAL_480M 0xc3
#define BBPLL_BBADC_DSMP_VAL_480M 0x74
+#define BBPLL_IR_CAL_DELAY_VAL 0x18
+#define BBPLL_IR_CAL_EXT_CAP_VAL 0x20
+#define BBPLL_OC_ENB_FCAL_VAL 0x9a
+#define BBPLL_OC_ENB_VCON_VAL 0x00
+#define BBPLL_BBADC_CAL_7_0_VAL 0x00
#define APLL_SDM_STOP_VAL_1 0x09
#define APLL_SDM_STOP_VAL_2_REV0 0x69
CLEAR_PERI_REG_MASK(RTC_CNTL_OPTIONS0_REG,
RTC_CNTL_BIAS_I2C_FORCE_PD | RTC_CNTL_BB_I2C_FORCE_PD |
RTC_CNTL_BBPLL_FORCE_PD | RTC_CNTL_BBPLL_I2C_FORCE_PD);
+
+ /* reset BBPLL configuration */
+ I2C_WRITEREG_RTC(I2C_BBPLL, I2C_BBPLL_IR_CAL_DELAY, BBPLL_IR_CAL_DELAY_VAL);
+ I2C_WRITEREG_RTC(I2C_BBPLL, I2C_BBPLL_IR_CAL_EXT_CAP, BBPLL_IR_CAL_EXT_CAP_VAL);
+ I2C_WRITEREG_RTC(I2C_BBPLL, I2C_BBPLL_OC_ENB_FCAL, BBPLL_OC_ENB_FCAL_VAL);
+ I2C_WRITEREG_RTC(I2C_BBPLL, I2C_BBPLL_OC_ENB_VCON, BBPLL_OC_ENB_VCON_VAL);
+ I2C_WRITEREG_RTC(I2C_BBPLL, I2C_BBPLL_BBADC_CAL_7_0, BBPLL_BBADC_CAL_7_0_VAL);
}
/**
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, //2-channels
.communication_format = I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB,
.dma_buf_count = 6,
- .dma_buf_len = 60, //
- .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1 //Interrupt level 1
+ .dma_buf_len = 60,
+ .intr_alloc_flags = 0, //Default interrupt priority
+ .tx_desc_auto_clear = true //Auto clear tx descriptor on underflow
};
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, //2-channels
.communication_format = I2S_COMM_FORMAT_I2S_MSB,
.dma_buf_count = 6,
- .dma_buf_len = 60, //
- .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1 //Interrupt level 1
+ .dma_buf_len = 60,
+ .intr_alloc_flags = 0, //Default interrupt priority
+ .tx_desc_auto_clear = true //Auto clear tx descriptor on underflow
};
--- /dev/null
+menu "Modbus Slave Example Configuration"
+
+config MB_UART_RXD
+ int "UART RXD pin number"
+ range 0 34
+ default 22
+ help
+ GPIO number for UART RX pin. See UART documentation for more information
+ about available pin numbers for UART.
+
+config MB_UART_TXD
+ int "UART TXD pin number"
+ range 0 34
+ default 23
+ help
+ GPIO number for UART TX pin. See UART documentation for more information
+ about available pin numbers for UART.
+
+config MB_UART_RTS
+ int "UART RTS pin number"
+ range 0 34
+ default 18
+ help
+ GPIO number for UART RTS pin. This pin is connected to
+ ~RE/DE pin of RS485 transceiver to switch direction.
+
+endmenu
comm_info.baudrate = MB_DEV_SPEED;
comm_info.parity = MB_PARITY_NONE;
ESP_ERROR_CHECK(mbcontroller_setup(comm_info));
-
+
// The code below initializes Modbus register area descriptors
// for Modbus Holding Registers, Input Registers, Coils and Discrete Inputs
// Initialization should be done for each supported Modbus register area according to register map.
// Starts of modbus controller and stack
ESP_ERROR_CHECK(mbcontroller_start());
+
+ // Set UART driver mode to Half Duplex
+ ESP_ERROR_CHECK(uart_set_mode(MB_PORT_NUM, UART_MODE_RS485_HALF_DUPLEX));
+
+ // Set UART pin numbers
+ ESP_ERROR_CHECK(uart_set_pin(MB_PORT_NUM, CONFIG_MB_UART_TXD,
+ CONFIG_MB_UART_RXD, CONFIG_MB_UART_RTS,
+ UART_PIN_NO_CHANGE));
// The cycle below will be terminated when parameter holdingRegParams.dataChan0
// incremented each access cycle reaches the CHAN_DATA_MAX_VAL value.