RIOT-OS / RIOT

RIOT - The friendly OS for IoT
https://riot-os.org
GNU Lesser General Public License v2.1
4.91k stars 1.98k forks source link

Getting UART error in ESp32-wroom #16249

Closed Eleftheria-99 closed 3 years ago

Eleftheria-99 commented 3 years ago

Description Task: I want to build a watering system with the use of esp32-wroom board, humidity sensors into the soil of a plant, water pump etc. The sensors are gonna detect the humidity, the board has to read the humidity values and then decide if the plant needs water or not The hardware is ready ! Software: I need to implement a client - server model . The client is the board. The logic is that the client reads some values from the board , it sends them to the sever and the server sends back an asnwer to the client, 1 if the plant needs water , otherwise 0, and the client has to write to the board, to release water into the plant or not ! I first connected the board to the computer and then I tried to flash it into the board. But I keep getting the uart error, although I do not use UART. The client code is as following :

#include "net/netopt.h" 
#include "net/gnrc/nettype.h" 
#include "net/gnrc/pkt.h"

#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <stdio.h>

#include "net/af.h"
#include "net/protnum.h"
#include "net/ipv6/addr.h"
#include "net/sock/udp.h"
#include "xtimer.h"
#include "net/protnum.h"
#include "net/ipv6/addr.h"
#include "net/sock/udp.h"

#include "saul_reg.h"

//#include "adc.h"

#include "shell.h"
#include "board.h"
#include "periph_conf.h"
#include "xtimer.h"  //for udp and tcp and processes
#include "thread.h" //for threads
#include "msg.h" //for threads
#include "net/gnrc/pktbuf.h" //for packets
#include <pthread.h>

#include "periph/gpio.h" //file periph.h: Parameter definitions for mapping peripherals directly to SAUL.
//CLIENT CODE 
//PINS:  13(insetad of 11 we had before) , 12 , VIN, 36 
#define Q_SZ 1000

#include "assert.h"
#include "log.h"
#include "saul_reg.h"

#include "arduino_board.h"
#include "arduino_pinmap.h"
#include "periph/adc.h"
#include "timex.h"
#include "led.h"

//hardware configuration 
#ifndef ARDUINO_LED
#define ARDUINO_LED     (0)
#endif

// Assign the default LED pin
int ledPin = ARDUINO_LED;

// input buffer for receiving chars on the serial port
int buf[64];
char line_buf[SHELL_DEFAULT_BUFSIZE];

// counter that counts the number of received chars
int count = 0;
int adcPortinit13 = 0 ;
int adcPortinit12 = 0 ;
int adcPortinit14 = 0 ; //input 

int val11=0;
int val12=0;
int val13=0;
//int val14=0;

sock_udp_ep_t local = SOCK_IPV6_EP_ANY; //  //We first create again a sock with a local end point bound to any IPv6 address and some port(  local.port = 0xabcd; ) . 
sock_udp_t sock;

void * data ;

static const shell_command_t commands[] = {
        { NULL, NULL, NULL }
};

int main(void){
    puts("Welcome to RIOT!\n");

    //step1 : init the pin and read data from the pin
    //adc port init
    adcPortinit13 = adc_init(13);  
    adcPortinit12 = adc_init(12);
    adcPortinit12 = adc_init(14);

    puts("adc_init for ports: DONE!\n");
    local.port = 0xabcd; //local port 

    if (sock_udp_create(&sock, &local, NULL, 0) < 0) { //udp sock
        puts("Error creating UDP sock");
        return 1;
    }

    printf("this is adcPort13 return value\n %d",adcPortinit13);
    if(adcPortinit13 == 0){
        puts("\nadc port13 initilised");
    }else{
        puts("\nadc failed to init 13");
    }

    printf("this is adcPort12 return value\n %d",adcPortinit12);

   if(adcPortinit12 == 0){
        puts("\nadc port12 initilised");
    }else{
        puts("\nadc failed to init 12");
    }

    printf("this is adcPort14 return value\n %d",adcPortinit14);
    if(adcPortinit14 == 0){
        puts("\nadc port14 initilised");
    }else{
        puts("\nadc failed to init 14");
    }

    while(1){   
        val11 = adc_sample(13, ADC_RES_10BIT);
        if(val11 < 0) {
            puts("[!] GPIO13 : sampling failure\n");
            return -1;
        }else{
            puts("GPIO13 : done sampling");
        }
       printf("val13 =  %d \n", val13 );

    val12 = adc_sample(12, ADC_RES_10BIT);
        if(val12 < 0) {
            puts("[!] GPIO12 : sampling failure\n");
            return -1;
        }else{
            puts("GPIO12 :done sampling");
        }
    printf("val12 =  %d \n", val12 );

    data = malloc ( sizeof ( val12)); //save humidity, data that we want to send to server
    sock_udp_ep_t remote = { .family = AF_INET6 };
        ssize_t res;

        //define port
    remote.port = 12345;
    ipv6_addr_set_all_nodes_multicast((ipv6_addr_t *)&remote.addr.ipv6,
                                          IPV6_ADDR_MCAST_SCP_LINK_LOCAL);
    if (sock_udp_send(&sock, data, sizeof(data), &remote) < 0) { //send data to server 
                puts("Error sending message");
                sock_udp_close(&sock);
                break;
    }
    if ((res = sock_udp_recv(&sock, buf, sizeof(buf), 1 * US_PER_SEC,NULL)) < 0) { //in case of error, when trying to send data to server
        if (res == -ETIMEDOUT) {
            puts("Timed out");
        }else {
            puts("Error receiving message");
        }
    }else {
        printf("Received message: \"");
        for (int i = 0; i < res; i++) {
            printf("%c", buf[i]);
        }
        printf("\"\n");
        //see what the server answered
        //send appropriate command to the hardware 
        if ( buf[0] == 1 ){
            printf("Plant does need any water\n");
            //saul_reg_write( saul_reg_find_name(), ); digitalWrite(14,HIGH);

        }else if( buf[0] ==0) {
            printf("Plant needs water\n");
            //saul_reg_write( saul_reg_find_name(),); 
        }
        }
        xtimer_sleep(5); //wait for 5 sec before we send an other message 
    }  
    puts("Client ending!\n");
    shell_run(commands, line_buf, SHELL_DEFAULT_BUFSIZE);
    return 0;
}

Steps to reproduce the issue I am trying to implement a client using riot os and I am keep getting this error, that comes from the file: periph_conf.h

Expected results : code running Actual results : warning: Configuration problem: Flash mode is qio or qout, \ GPIO9 and GPIO10 are not available for UART1 as configured-->

Versions Operating system: Linux Build environment: GCC, RIOT OS docker image

jeandudey commented 3 years ago

@Eleftheria-99 could you provide more information?

jeandudey commented 3 years ago

Closing since no information was provided, feel free to reopen this or open a new issue with more details about the problem.

Eleftheria-99 commented 3 years ago

@jeandudey I am so sorry, I just saw, I added all the necessary info , can we reopen the issue ??

Eleftheria-99 commented 3 years ago

@jeandudey also how did you add a label ?

jeandudey commented 3 years ago

@jeandudey also how did you add a label ?

Only members of the repository can add labels

jeandudey commented 3 years ago

@Eleftheria-99 what version of RIOT are you using? The version (e.g.: 2021.01) or the last commit (git log on RIOT directory).

gschorcht commented 3 years ago

The warning message is thrown if the flash mode is either qout or qio. In that case, the Quad SPI interface is used for SPI flash which in turn occupies GPIO 9 an GPIO 10 so that they can't be used as UART interface.

Could you check whether this is the case by using the the following command?

BOARD=esp32-wroom-32 make -C <your app directory> info-debug-variable-FLASH_MODE
Eleftheria-99 commented 3 years ago

@Eleftheria-99 what version of RIOT are you using? The version (e.g.: 2021.01) or the last commit (git log on RIOT directory).

I think 2021.01

Eleftheria-99 commented 3 years ago

The warning message is thrown if the flash mode is either qout or qio. In that case, the Quad SPI interface is used for SPI flash which in turn occupies GPIO 9 an GPIO 10 so that they can't be used as UART interface.

Could you check whether this is the case by using the the following command?

BOARD=esp32-wroom-32 make -C <your app directory> info-debug-variable-FLASH_MODE

I did not understand what the warning means why the warning is being thrown since I did not declare a flash mode when running the code !! The command we used to run the code was : cd into directory sudo BUILD_IN_DOCKER=1 BOARD=esp32-wroom-32 make
but we can try also the one you proposed

gschorcht commented 3 years ago

I did not understand what the warning means why the warning is being thrown since I did not declare a flash mode when running the code

It's only a warning and just means that UART1 can't be used as configured for the board by default because the flash mode is qout or qio. FLASH_MODE variable might be set automatically, for example if you use module esp_spi_ram. Therefore, please send the output of following commands:

BOARD=esp32-wroom-32 make info-debug-variable-USEMODULE
BOARD=esp32-wroom-32 make info-debug-variable-FLASH_MODE

This should also work in docker.

Eleftheria-99 commented 3 years ago

@gschorcht
results :

i just ran it again with the command you gave and it retunred: make: * info-debug-variable-FLASH_MODE: No such file or directory. Stop.

WhatsApp Image 2021-04-05 at 17 16 31

gschorcht commented 3 years ago

i just ran it again with the command you gave and it retunred: make: * info-debug-variable-FLASH_MODE: No such file or directory. Stop.

I'm really sorry, but you are wrong. I never gave you command

BOARD=esp32-wroom-32 make -C info-debug-variable-FLASH_MODE

Of course, this command doesn't work because option -C requires to specify a build directory. The first time I gave you the following command

BOARD=esp32-wroom-32 make -C <your app directory> info-debug-variable-FLASH_MODE

in which you would have to replace <your app directory> by your application directory. But since you have used command

sudo BUILD_IN_DOCKER=1 BOARD=esp32-wroom-32 make

according to your answer, I thought you are calling make inside your application directory and it is not necessary to specify application directory by option -C. So I gave you command

BOARD=esp32-wroom-32 make info-debug-variable-USEMODULE
BOARD=esp32-wroom-32 make info-debug-variable-FLASH_MODE

last time without option -C!

Please read more carefully next time.

gschorcht commented 3 years ago

Regarding the result. As supposed, the flash mode is qout because module `esp_spi_ram´ is used. You will find these information in the output of the last two commands.

Since the esp32-wroom-32 board doesn't have SPI RAM, module esp_spi_ram shouldn't be enabled. To be able to figure out what the problem might be in your case, I would need the Makefile of your application. Could you please provide it?

Eleftheria-99 commented 3 years ago

ok we will run it again

Eleftheria-99 commented 3 years ago

@gschorcht

A6FDC7D8-0A6E-4C07-A5C8-EC4CA4763198

gschorcht commented 3 years ago

screenshot_modified

Ok, this is the same as we had seen before, variable FLASH_MODE is set to qout because module esp_spi_ram is used.

According to your screenshot you are using examples/saul as application, right? I suspect that you have modified it, since examples/saul in the master repository neither uses the esp_spi_ram module nor has the FLASH_MODE variable set to qout.

Again, to find out what the problem in your case might be, I would need the Makefile of your application. Therefore, may I ask you again to provide your Makefile?

Eleftheria-99 commented 3 years ago

Makefile:


# name of your application
APPLICATION = saul_example

# If no BOARD is found in the environment, use this default:
BOARD ?= native

# This has to be the absolute path to the RIOT base directory:
RIOTBASE ?= $(CURDIR)/../..

# we want to use SAUL:
USEMODULE += saul_default
# include the shell:
USEMODULE += shell
USEMODULE += shell_commands
# additional modules for debugging:
USEMODULE += ps

# Include packages that pull up and auto-init the link layer.
# NOTE: 6LoWPAN will be included if IEEE802.15.4 devices are present
USEMODULE += gnrc_netdev_default
USEMODULE += auto_init_gnrc_netif
# Activate ICMPv6 error messages
USEMODULE += gnrc_icmpv6_error
# Specify the mandatory networking modules for IPv6 and UDP
USEMODULE += gnrc_ipv6_router_default
USEMODULE += gnrc_udp
# Add a routing protocol
USEMODULE += gnrc_rpl
USEMODULE += auto_init_gnrc_rpl
# This application dumps received packets to STDIO using the pktdump module
USEMODULE += gnrc_pktdump
# Additional networking modules that can be dropped if not needed
USEMODULE += gnrc_icmpv6_echo
# Add also the shell, some shell commands
USEMODULE += netstats_l2
USEMODULE += netstats_ipv6
USEMODULE += netstats_rpl

#USEMODULE += esp_spiffs
USEMODULE += esp_head
USEMODULE += esp_hw_counter
USEMODULE += esp_spi_ram
FEATURES_PROVIDED += periph_can

USEMODULE += saul_default
USEMODULE += printf_float
USEMODULE += xtimer

USEMODULE += newlib_nano
USEMODULE += gnrc_udp
USEMODULE += sock_udp  
USEMODULE += gnrc_ipv6_default  
# Comment this out to disable code in RIOT that does safety checking
# which is not needed in a production environment but helps in the
# development process:
DEVELHELP ?= 1

# Change this to 0 show compiler invocation lines by default:
QUIET ?= 1

#add current dir to the include path, 
#putting it in cflags will make it go to the beginning, before the stnadard includes. That way slip_params.h gets included and auto configuration can pick it up
CFLAGS += -I$(CURDIR)

# development process:
CFLAGS += -DDEVELHELP
CFLAGS=-DAUTO_INIT_LED0

#features
FEATURES_REQUIRED += periph_adc
FEATURES_REQUIRED += periph_gpio
FEATURES_REQUIRED += periph_gpio_irq
include $(RIOTBASE)/Makefile.include
gschorcht commented 3 years ago

USEMODULE += esp_spiffs

USEMODULE += esp_head USEMODULE += esp_hw_counter USEMODULE += esp_spi_ram

Here you have explicitly enabled module esp_spi_ram. Why, the ESP32-WROOM-32 module doesn't have SPI RAM? This is the reason that FLASH_MODE is set to qout and you get this warning message.

jeandudey commented 3 years ago

Closing as the issue as been already solved, if not, please re-open it.