Compare commits
14 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1aaa7184dd | |||
| 26b482f57c | |||
| 7a9d6c82fa | |||
| 943a418cb0 | |||
| 6fe97707f2 | |||
| 8f1dae7094 | |||
| ff8d0a68cf | |||
| 1ed69b107c | |||
|
|
7cf9731056 | ||
|
|
f4e5f6bd10 | ||
|
|
b78d983c1f | ||
|
|
3aae26a437 | ||
|
|
aa8ff79313 | ||
|
|
ec377c95d6 |
5 changed files with 162 additions and 25 deletions
101
README.md
101
README.md
|
|
@ -1,9 +1,104 @@
|
|||
**Warning: in esp-idf v5.2 there's a bug that prevent's app from booting when using `CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y`. Use esp-idf v5.1.2 for now.**
|
||||
|
||||
TODO:
|
||||
# CAN Wizard
|
||||
|
||||
CAN Wizard is a project designed for communication using the CAN (Controller Area Network) protocol, primarily targeted at embedded systems utilizing the ESP32 microcontroller family. This project is developed using ESP-IDF and supports ESP32-C3, allowing flexible development for different use cases.
|
||||
|
||||
Here are more information:
|
||||
- [Xa6p Article](https://habr.com/ru/articles/793326/). (in Russian)
|
||||
- [Traduccion in English](https://okhsunrog.ru/articles/2024/02/15/can_bus_sniffer/).
|
||||
|
||||
## Features
|
||||
|
||||
- **CAN Communication**: Implements CAN communication protocols, enabling data exchange between devices over a CAN bus.
|
||||
- **File System Integration**: Includes file system operations for handling configuration or logging.
|
||||
- **Custom serial Console**: A custom serial console implementation for interacting with the system and issuing commands.
|
||||
- **Modular Design**: Organized in components for easier maintenance and scalability, including linked lists and command utilities.
|
||||
|
||||
## Requirements
|
||||
|
||||
- **Hardware**:
|
||||
- ESP32-C3 microcontroller
|
||||
- SN65HVD230 CAN transceiver
|
||||
|
||||
- **Software**:
|
||||
- ESP-IDF (version x.x.x or newer)
|
||||
- CMake (for project build system)
|
||||
- Python (for ESP-IDF and related tools)
|
||||
|
||||
## Setup and Installation
|
||||
|
||||
1. **Clone the Repository**:
|
||||
Clone this repository using:
|
||||
```bash
|
||||
git clone --recursive git@github.com:okhsunrog/can_wizard.git
|
||||
```
|
||||
|
||||
2. **Install ESP-IDF**:
|
||||
Follow the official ESP-IDF installation guide for your operating system: [ESP-IDF Setup Guide](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/)
|
||||
|
||||
3. **Configure ESP-IDF**:
|
||||
Set up your environment by running the following commands:
|
||||
```bash
|
||||
cd <project-directory>
|
||||
idf.py set-target esp32c3
|
||||
idf.py menuconfig
|
||||
```
|
||||
|
||||
4. **Build and Flash**:
|
||||
Build the project and flash it to your microcontroller:
|
||||
```bash
|
||||
idf.py build
|
||||
idf.py flash
|
||||
idf.py monitor
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Console Commands
|
||||
|
||||
The CAN Wizard project provides several commands that can be executed through a console interface:
|
||||
|
||||
- `can_send <data>`: Send CAN data over the bus.
|
||||
- `can_receive`: Receive CAN data from the bus.
|
||||
- `can_status`: Display the current CAN status.
|
||||
|
||||
Additional commands can be explored through the console by typing `help`.
|
||||
|
||||
### File System Operations
|
||||
|
||||
The project includes basic file system operations to read and write configuration or log files. These operations can be accessed through the `fs_*` commands in the console.
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
can_wizard-main/
|
||||
├── components/
|
||||
│ └── C-Linked-List/ # Linked list implementation used in the project
|
||||
├── main/
|
||||
│ ├── can.c # CAN communication implementation
|
||||
│ ├── console.c # Custom console implementation
|
||||
│ ├── cmd_can.c # CAN command handlers
|
||||
│ ├── fs.c # File system operations
|
||||
│ └── main.c # Main entry point
|
||||
└── CMakeLists.txt # Project build system configuration
|
||||
```
|
||||
|
||||
## TODO:
|
||||
- code refactoring
|
||||
- test dumb mode
|
||||
- fix prompt flickering with some commands
|
||||
- add standard ID filtering to cansmartfilter
|
||||
|
||||
Description in [Russian](https://habr.com/ru/articles/793326/).
|
||||
## License
|
||||
|
||||
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions are welcome! Please submit a pull request or open an issue to discuss your ideas.
|
||||
|
||||
## Author
|
||||
|
||||
Danila Gornushko
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 2782b9db6a22df017e3fd74092f93bd624a21e6e
|
||||
Subproject commit ebbbc22f8907766208823737ba3fda655ddac5ca
|
||||
|
|
@ -1 +1 @@
|
|||
Subproject commit 41873c20fb5cdbcf28d7d6cc04e4bcb4a1305317
|
||||
Subproject commit 3e5e7a11b7f06515a1f93873b6fe5a9efe88338b
|
||||
|
|
@ -185,6 +185,7 @@ static int canup(int argc, char **argv) {
|
|||
break;
|
||||
}
|
||||
switch (canup_args.speed->ival[0]) {
|
||||
#if CONFIG_IDF_TARGET_ESP32C3
|
||||
case 1000:
|
||||
t_config = (twai_timing_config_t) TWAI_TIMING_CONFIG_1KBITS();
|
||||
break;
|
||||
|
|
@ -203,6 +204,7 @@ static int canup(int argc, char **argv) {
|
|||
case 20000:
|
||||
t_config = (twai_timing_config_t) TWAI_TIMING_CONFIG_20KBITS();
|
||||
break;
|
||||
#endif
|
||||
case 25000:
|
||||
t_config = (twai_timing_config_t) TWAI_TIMING_CONFIG_25KBITS();
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -15,8 +15,6 @@
|
|||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "esp_vfs_usb_serial_jtag.h"
|
||||
#include "driver/usb_serial_jtag.h"
|
||||
#include "cmd_system.h"
|
||||
#include "cmd_can.h"
|
||||
#include "cmd_utils.h"
|
||||
|
|
@ -24,6 +22,14 @@
|
|||
#include "fs.h"
|
||||
#include "xvprintf.h"
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32C3
|
||||
#include <driver/usb_serial_jtag_vfs.h>
|
||||
#include "driver/usb_serial_jtag.h"
|
||||
#else
|
||||
#include <driver/uart_vfs.h>
|
||||
#include "driver/uart.h"
|
||||
#endif
|
||||
|
||||
#if CONFIG_LOG_COLORS
|
||||
static const bool use_colors = true;
|
||||
#else
|
||||
|
|
@ -90,7 +96,8 @@ void console_task_tx(void* arg) {
|
|||
static const TickType_t prompt_timeout = pdMS_TO_TICKS(200);
|
||||
const int fd = fileno(stdout);
|
||||
size_t msg_to_print_size;
|
||||
while(1) {
|
||||
// ReSharper disable once CppDFAEndlessLoop
|
||||
while (1) {
|
||||
char* msg_to_print = xRingbufferReceive(uart_tx_ringbuf, &msg_to_print_size, prompt_timeout);
|
||||
update_prompt();
|
||||
xSemaphoreTake(console_taken_sem, portMAX_DELAY);
|
||||
|
|
@ -98,22 +105,22 @@ void console_task_tx(void* arg) {
|
|||
linenoiseHide(&ls);
|
||||
if (msg_to_print != NULL) {
|
||||
// if zero-length string - just refresh prompt. used for updating prompt
|
||||
if(msg_to_print[0] != '\0') {
|
||||
if (msg_to_print[0] != '\0') {
|
||||
write(fd, msg_to_print, msg_to_print_size);
|
||||
flushWrite();
|
||||
}
|
||||
vRingbufferReturnItem(uart_tx_ringbuf, (void *) msg_to_print);
|
||||
vRingbufferReturnItem(uart_tx_ringbuf, (void*) msg_to_print);
|
||||
}
|
||||
linenoiseShow(&ls);
|
||||
xSemaphoreGive(stdout_taken_sem);
|
||||
xSemaphoreGive(console_taken_sem);
|
||||
xSemaphoreGive(console_taken_sem);
|
||||
}
|
||||
}
|
||||
|
||||
void console_task_interactive(void* arg) {
|
||||
console_taken_sem = xSemaphoreCreateMutex();
|
||||
stdout_taken_sem = xSemaphoreCreateMutex();
|
||||
char *buf = calloc(1, console_config.max_cmdline_length);
|
||||
char* buf = calloc(1, console_config.max_cmdline_length);
|
||||
/* Figure out if the terminal supports escape sequences */
|
||||
printf("Testing your console...\n");
|
||||
const int probe_status = linenoiseProbe();
|
||||
|
|
@ -127,10 +134,10 @@ void console_task_interactive(void* arg) {
|
|||
linenoiseSetDumbMode(1);
|
||||
}
|
||||
printf("\n"
|
||||
"Type 'help' to get the list of commands.\n"
|
||||
"Use UP/DOWN arrows to navigate through command history.\n"
|
||||
"Press TAB when typing command name to auto-complete.\n"
|
||||
"Ctrl+C will terminate the console environment.\n");
|
||||
"Type 'help' to get the list of commands.\n"
|
||||
"Use UP/DOWN arrows to navigate through command history.\n"
|
||||
"Press TAB when typing command name to auto-complete.\n"
|
||||
"Ctrl+C will terminate the console environment.\n");
|
||||
ls.buflen = console_config.max_cmdline_length;
|
||||
ls.buf = buf;
|
||||
update_prompt();
|
||||
|
|
@ -182,29 +189,62 @@ void console_task_interactive(void* arg) {
|
|||
void initialize_console(void) {
|
||||
/* Disable buffering on stdin */
|
||||
setvbuf(stdin, NULL, _IONBF, 0);
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32C3
|
||||
/* Minicom, screen, idf_monitor send CR when ENTER key is pressed */
|
||||
esp_vfs_dev_usb_serial_jtag_set_rx_line_endings(ESP_LINE_ENDINGS_CR);
|
||||
usb_serial_jtag_vfs_set_rx_line_endings(ESP_LINE_ENDINGS_CR);
|
||||
|
||||
/* Move the caret to the beginning of the next line on '\n' */
|
||||
esp_vfs_dev_usb_serial_jtag_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF);
|
||||
usb_serial_jtag_vfs_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF);
|
||||
|
||||
usb_serial_jtag_driver_config_t usb_serial_jtag_config = USB_SERIAL_JTAG_DRIVER_CONFIG_DEFAULT();
|
||||
|
||||
/* Install USB-SERIAL-JTAG driver for interrupt-driven reads and writes */
|
||||
ESP_ERROR_CHECK(usb_serial_jtag_driver_install(&usb_serial_jtag_config));
|
||||
|
||||
/* Asign vfs to JTAG */
|
||||
usb_serial_jtag_vfs_use_driver();
|
||||
#else
|
||||
/* Set up UART for the console */
|
||||
const uart_config_t uart_config = {
|
||||
.baud_rate = 115200,
|
||||
.data_bits = UART_DATA_8_BITS,
|
||||
.parity = UART_PARITY_DISABLE,
|
||||
.stop_bits = UART_STOP_BITS_1,
|
||||
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
|
||||
};
|
||||
|
||||
/* Install the UART driver */
|
||||
uart_driver_install(UART_NUM_0, 256, 0, 0, NULL, 0);
|
||||
uart_param_config(UART_NUM_0, &uart_config);
|
||||
|
||||
/* Asign VFS to UART */
|
||||
// uart_vfs_dev_use_driver(UART_NUM_0);
|
||||
uart_vfs_dev_use_driver(UART_NUM_0);
|
||||
|
||||
#endif
|
||||
|
||||
/* Enable non-blocking mode on stdin and stdout */
|
||||
fcntl(fileno(stdout), F_SETFL, 0);
|
||||
fcntl(fileno(stdin), F_SETFL, 0);
|
||||
usb_serial_jtag_driver_config_t usb_serial_jtag_config = USB_SERIAL_JTAG_DRIVER_CONFIG_DEFAULT();
|
||||
/* Install USB-SERIAL-JTAG driver for interrupt-driven reads and writes */
|
||||
ESP_ERROR_CHECK(usb_serial_jtag_driver_install(&usb_serial_jtag_config));
|
||||
/* Tell vfs to use usb-serial-jtag driver */
|
||||
esp_vfs_usb_serial_jtag_use_driver();
|
||||
|
||||
/* Configure the console */
|
||||
console_config.max_cmdline_args = CONFIG_CONSOLE_MAX_CMDLINE_ARGS;
|
||||
console_config.max_cmdline_length = CONFIG_CONSOLE_MAX_CMDLINE_LENGTH;
|
||||
if (use_colors) console_config.hint_color = atoi(LOG_COLOR_CYAN);
|
||||
|
||||
/* Initializing */
|
||||
ESP_ERROR_CHECK(esp_console_init(&console_config));
|
||||
// linenoiseSetMultiLine(1);
|
||||
|
||||
/* Config library linenoise */
|
||||
linenoiseSetMultiLine(1);
|
||||
linenoiseSetCompletionCallback(&esp_console_get_completion);
|
||||
linenoiseSetHintsCallback((linenoiseHintsCallback*) &esp_console_get_hint);
|
||||
linenoiseHistorySetMaxLen(30);
|
||||
linenoiseSetMaxLineLen(console_config.max_cmdline_length);
|
||||
linenoiseHistoryLoad(HISTORY_PATH);
|
||||
/* Register commands */
|
||||
|
||||
/* Record commands */
|
||||
esp_console_register_help_command();
|
||||
register_system();
|
||||
register_can_commands();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue