GithubHelp home page GithubHelp logo

Comments (7)

zms16 avatar zms16 commented on June 5, 2024 1

Yes, I'm using PlatformIO, ESP-IDF 5.0.0 and ESP32-S3

from esp_dmx.

someweisguy avatar someweisguy commented on June 5, 2024 1

Is the esp_dmx library folder in your .pio/libdeps folder? If so, could you make a folder called components in your project directory, and move the esp_dmx folder to the components folder? The end result should be something like my_dmx_recorder_project/components/esp_dmx/ if your project is called my_dmx_recorder_project. Then clean and rebuild your project and flash it to your device.

What this should do is allow the ESP32 build system to find the Kconfig file in esp_dmx. This file interfaces with the ESP32's menuconfig. It will instruct the ESP32 to put the DMX driver and hardware timer driver into IRAM, which means that the DMX interrupts will continue to fire even when you are writing to flash.

That is my best guess of the issue at the moment. I think that you may be writing to flash in the middle of receiving a DMX packet. Because reading from or writing to flash stops the DMX interrupts (when the interrupts are not in IRAM), it is causing the DMX driver to miscount which byte corresponds to which DMX address. This could lead to the buffer shift that you are seeing.

If this fixes the issue, I will also add a function which can momentarily disable the DMX receive interrupts so that you can safely read or write to flash even if the DMX driver is not in IRAM.

from esp_dmx.

someweisguy avatar someweisguy commented on June 5, 2024 1

I'm working on #60 to fix this problem as well. With the added changes in this PR, you are able to call dmx_driver_disable() before reading or writing to flash. This disables the DMX driver gracefully, meaning that the driver will stop processing incoming DMX data and calls to dmx_send() and dmx_receive() are disabled. Any function that relies on these functions, such as any function which sends or receives RDM, will fail as well. When you are done with your work in flash, calling dmx_driver_enable() will reenable the DMX driver, allowing it to send and receive DMX data once again.

Disabling the driver is not needed when placing the DMX driver in IRAM. Placing the DMX driver in IRAM is the ideal solution, but I understand there are some situations where doing so isn't possible.

from esp_dmx.

zms16 avatar zms16 commented on June 5, 2024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "esp_log.h"
#include "esp_vfs.h"
#include "esp_vfs_fat.h"
#include "esp_system.h"
#include "esp_dmx.h"

#define RX_PIN 18
#define TX_PIN 17
#define RX_DMX DMX_NUM_2
#define TX_DMX DMX_NUM_1

uint8_t dmx_data[DMX_PACKET_SIZE] = {};
uint8_t j = 0;

static wl_handle_t s_wl_handle = WL_INVALID_HANDLE; // Handle of the wear levelling library instance
const char *base_path = "/spiflash"; // Mount path for the partition

void app_main() { 
	uint8_t* dmx_buff = (uint8_t*) malloc(100*513*sizeof(uint8_t));	
//------DMX INIT---------------------------------------------
	ESP_ERROR_CHECK(dmx_set_pin(RX_DMX, DMX_PIN_NO_CHANGE, RX_PIN, DMX_PIN_NO_CHANGE));
	ESP_ERROR_CHECK(dmx_driver_install(RX_DMX, DMX_DEFAULT_INTR_FLAGS));
	ESP_ERROR_CHECK(dmx_set_pin(TX_DMX, TX_PIN, DMX_PIN_NO_CHANGE, DMX_PIN_NO_CHANGE));
	ESP_ERROR_CHECK(dmx_driver_install(TX_DMX, DMX_DEFAULT_INTR_FLAGS));
	dmx_packet_t packet;
//------FAT INIT---------------------------------------------
	size_t f_bytes = 0; 
	const esp_vfs_fat_mount_config_t mount_config = {
		.max_files = 6,
		.format_if_mount_failed = true,
		.allocation_unit_size = CONFIG_WL_SECTOR_SIZE
    };
	ESP_LOGI("FAT", "Mounting FAT filesystem");
	esp_err_t  err = esp_vfs_fat_spiflash_mount_rw_wl(base_path, "fat_storage", &mount_config, &s_wl_handle);
	if (err != ESP_OK) {
        ESP_LOGE("FAT", "Failed to mount FATFS (%s)", esp_err_to_name(err));
    }

    while(true) {	
		if(dmx_receive(RX_DMX, &packet, 0)) {
			dmx_read(RX_DMX, dmx_data, DMX_PACKET_SIZE);
		}
		dmx_write(TX_DMX, dmx_data, DMX_PACKET_SIZE);
		dmx_send(TX_DMX, DMX_PACKET_SIZE);
		dmx_wait_sent(TX_DMX, DMX_TIMEOUT_TICK);

		memcpy((dmx_buff+j*513),dmx_data,513);
		++j;
		if(j==100) {
			FILE *f = fopen("/spiflash/file1.bin", "wb");
			if (f == NULL) {
				ESP_LOGE("FAT", "Failed to open file for writing");
			}
			f_bytes = fwrite(dmx_buff, sizeof(uint8_t), 513*100, f);
			fclose(f);
			ESP_LOGI("FAT", "%zu bytes written", f_bytes);
			j=0;
		}
		vTaskDelay(30 / portTICK_PERIOD_MS);
	}
}

from esp_dmx.

zms16 avatar zms16 commented on June 5, 2024

So I made a program that still causes recieve buffer to shift. It is not NVS, the shift is caused by FAT save.

from esp_dmx.

someweisguy avatar someweisguy commented on June 5, 2024

Thanks for the example code! Which version of ESP-IDF are you using?

Also, are you using PlatformIO?

from esp_dmx.

zms16 avatar zms16 commented on June 5, 2024

The library was in the /lib folder, but moving esp_dmx to /components still helped, thank you.

from esp_dmx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.