Add error handling for UART and GPIO configurations in gps_sync_init
- Implemented error checks for uart_driver_install, uart_set_pin, gpio_config, gpio_install_isr_service, and gpio_isr_handler_add to ensure robust initialization of GPS synchronization components. - Enhanced logging to provide detailed error messages for easier debugging.
This commit is contained in:
parent
feb0d4d142
commit
d4cd861b80
|
|
@ -38,6 +38,7 @@
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
|
#include "esp_err.h"
|
||||||
#include "esp_timer.h"
|
#include "esp_timer.h"
|
||||||
#include "driver/uart.h"
|
#include "driver/uart.h"
|
||||||
#include "driver/gpio.h"
|
#include "driver/gpio.h"
|
||||||
|
|
@ -212,19 +213,41 @@ void gps_sync_init(const gps_sync_config_t *cfg, bool force_enable) {
|
||||||
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
|
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
|
||||||
.source_clk = UART_SCLK_DEFAULT,
|
.source_clk = UART_SCLK_DEFAULT,
|
||||||
};
|
};
|
||||||
uart_driver_install(s_cfg.uart_port, GPS_BUF_SIZE * 2, 0, 0, NULL, 0);
|
esp_err_t err = uart_driver_install(s_cfg.uart_port, GPS_BUF_SIZE * 2, 0, 0, NULL, 0);
|
||||||
|
if (err != ESP_OK && err != ESP_ERR_INVALID_STATE) {
|
||||||
|
ESP_LOGE(TAG, "Failed to install UART driver: %s", esp_err_to_name(err));
|
||||||
|
return;
|
||||||
|
}
|
||||||
uart_param_config(s_cfg.uart_port, &uart_config);
|
uart_param_config(s_cfg.uart_port, &uart_config);
|
||||||
uart_set_pin(s_cfg.uart_port, s_cfg.tx_pin, s_cfg.rx_pin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
|
err = uart_set_pin(s_cfg.uart_port, s_cfg.tx_pin, s_cfg.rx_pin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Failed to set UART pins: %s", esp_err_to_name(err));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
gpio_config_t io_conf = {};
|
gpio_config_t io_conf = {};
|
||||||
io_conf.intr_type = GPIO_INTR_POSEDGE;
|
io_conf.intr_type = GPIO_INTR_POSEDGE;
|
||||||
io_conf.pin_bit_mask = (1ULL << s_cfg.pps_pin);
|
io_conf.pin_bit_mask = (1ULL << s_cfg.pps_pin);
|
||||||
io_conf.mode = GPIO_MODE_INPUT;
|
io_conf.mode = GPIO_MODE_INPUT;
|
||||||
io_conf.pull_up_en = 1;
|
io_conf.pull_up_en = 1;
|
||||||
gpio_config(&io_conf);
|
err = gpio_config(&io_conf);
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Failed to configure PPS GPIO %d: %s", s_cfg.pps_pin, esp_err_to_name(err));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
gpio_install_isr_service(0);
|
// Install ISR service (ignore error if already installed)
|
||||||
gpio_isr_handler_add(s_cfg.pps_pin, pps_gpio_isr_handler, NULL);
|
err = gpio_install_isr_service(0);
|
||||||
|
if (err != ESP_OK && err != ESP_ERR_INVALID_STATE) {
|
||||||
|
ESP_LOGE(TAG, "Failed to install GPIO ISR service: %s", esp_err_to_name(err));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = gpio_isr_handler_add(s_cfg.pps_pin, pps_gpio_isr_handler, NULL);
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Failed to add PPS GPIO ISR handler: %s", esp_err_to_name(err));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
xTaskCreate(gps_task, "gps_task", 4096, NULL, 5, NULL);
|
xTaskCreate(gps_task, "gps_task", 4096, NULL, 5, NULL);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue