These are chat archives for esp8266/Arduino

16th
May 2015
ficeto
@ficeto
May 16 2015 14:40
size_t Print::print(const char *format, ...) {
  va_list arg;
  va_start(arg, format);
  char temp[1024];
  ets_vsnprintf(temp, 1024, format, arg);
  size_t len = write((const char *)temp);
  delete[] temp;
  va_end(arg);
  return len;
}
ny clues why this causes wdt_reset?
would love to get this working
Markus
@Links2004
May 16 2015 14:41
may serial buffer full see Links2004/Arduino@2cf1772
had a simular problem with os_printf
ficeto
@ficeto
May 16 2015 14:41
I think i have that already in
Markus
@Links2004
May 16 2015 14:42
it is not in igrr branch yet
ficeto
@ficeto
May 16 2015 14:43
i pulled your changes earlier
you it's in
no luck whatever I try to make it work
tried os_sprintf to same result
Markus
@Links2004
May 16 2015 14:46
may the \0 is not applied correctly?
size_t Print::print(const char *format, ...) {
  va_list arg;
  va_start(arg, format);
  char temp[1024] = {0};
  ets_vsnprintf(temp, 1024, format, arg);
 hexdump(&temp[0],1024);
  size_t len = write((const char *)temp);
  delete[] temp;
  va_end(arg);
  return len;
}
is delete[] temp; really nessesary? its a normal variable
ficeto
@ficeto
May 16 2015 14:47
would that lead to wdt reset thouygh?
with/without delete... same
Markus
@Links2004
May 16 2015 14:48
\0 may yes ist trys to send until it find a 0x00
ficeto
@ficeto
May 16 2015 14:56
size_t Print::print(const char *format, ...) {
  va_list arg;
  va_start(arg, format);
  char temp[128];
  size_t len = ets_vsnprintf(temp, 128, format, arg);
  temp[len-1] = '\0';
  len = write((const char *)temp);
  va_end(arg);
  return len;
}
same
Markus
@Links2004
May 16 2015 14:58
strange, then only help debug output + delay (for serial out) before each function call to see where its hangs
ficeto
@ficeto
May 16 2015 15:01
OMG.... now i feel stupid
it was me blocking for too long without yield
strange though did not run into it before i started replacing the print function
i imagine this has to do with your addition
you are waiting when buffer is full correct?
Markus
@Links2004
May 16 2015 15:02
no no waiting anymore if buffer is full
ficeto
@ficeto
May 16 2015 15:03
hm...
Markus
@Links2004
May 16 2015 15:03
the wait was crashing if the os try to send something
ficeto
@ficeto
May 16 2015 16:41
@Links2004 so your UART fix is great for os_printf
byt the Serial library is really easy to do the same thing
that check should be in the HardwareSerial::write method
Markus
@Links2004
May 16 2015 16:42
no
ficeto
@ficeto
May 16 2015 16:42
then how?
that is what caused my resets
is I go through os_printf it's all good
Markus
@Links2004
May 16 2015 16:42
the serial.print stuff always run on the "arduino" thread
ficeto
@ficeto
May 16 2015 16:42
if I go through Serial.print it goes to hell
Markus
@Links2004
May 16 2015 16:43
so there we can wait may the wait is not goot implementet need to check this
the write do this:
   while(_tx_buffer->room() == 0) {
        yield();
    }
so for the arduino os task all is ok
this was only crashing/hang if os_print was called in non arduino task
ficeto
@ficeto
May 16 2015 16:46
my case is as follows
I dump lots on init
I can dump through the serial library or through the os_
through os_ all goes through
Markus
@Links2004
May 16 2015 16:47
we have the 256 Byte arduino buffer + 128 FIFO of the esp8266
ficeto
@ficeto
May 16 2015 16:47
both run in the arduino context
Markus
@Links2004
May 16 2015 16:48
os_ loss some chars if both buffer are full (may they also mixed up)
ficeto
@ficeto
May 16 2015 16:48
did not lose anything
outputed the same exact thing
Markus
@Links2004
May 16 2015 16:49
serial. stuff shut wait until we have free buffer with an yield
ok then you not reach the buffer max
ficeto
@ficeto
May 16 2015 16:49
i think i do not
i even have yield here and there to help
Markus
@Links2004
May 16 2015 16:50
are we sure yield call wtd feed?
extern "C" void __yield() {
    esp_schedule();
    esp_yield();
}
then comes ESP8266 magic
ficeto
@ficeto
May 16 2015 16:52
i did catch an exception 0 at the beginning of uart-interrupt_handler
Markus
@Links2004
May 16 2015 16:53
wOo Illegal Instruction
ficeto
@ficeto
May 16 2015 17:11
good old delay helped
but does not explain why this happens
Markus
@Links2004
May 16 2015 17:12
yes Illegal Instruction is very strange
ficeto
@ficeto
May 16 2015 17:12
wdt comes after the last line has been outputed and before some wait and other stuff
hete is the function
void initSD(){
  if (SD.begin(SS, 8000000)){
    hasSD = true;
    DBG_OUTPUT_PORT.print("\n==== SD Card Info ====\n");
    DBG_OUTPUT_PORT.printf("SD Type: %s FAT%d, Size: %s\n", getSdTypeString(), SD.fatType(), getSizeString(SD.size()));
    DBG_OUTPUT_PORT.printf("SD Blocks: total: %d, size: %s\n", SD.totalBlocks(), getSizeString(SD.blockSize()));
    DBG_OUTPUT_PORT.printf("SD Clusters: total: %d, blocks: %d, size: %s\n", SD.totalClusters(), SD.blocksPerCluster(), getSizeString(SD.clusterSize()));
    File entry;
    File dir = SD.open("/");
    dir.rewindDirectory();
    while(true){
      entry = dir.openNextFile();
      if (!entry) break;
      DBG_OUTPUT_PORT.printf("SD File: %s, type: %s, size: %s\n", entry.name(), (entry.isDirectory())?"dir":"file", getSizeString(entry.size()));
      entry.close();
      delay(1);
    }
    dir.close();
    DBG_OUTPUT_PORT.println();

    if(!FS.exists("edit.htm") && SD.exists((char *)("/test.htm"))){
      sdToSpi("/test.htm", "edit.htm");
    }
  } else 
    DBG_OUTPUT_PORT.println("SD Card Not Found!");
}
wdt comes after the last FD File has been printed
and before the next method is executed
edit.htm exists on FD so that is quick andswer
Markus
@Links2004
May 16 2015 17:15
DBG_OUTPUT_PORT.println(); is not reached?
ficeto
@ficeto
May 16 2015 17:16
it is
well spometimes it breaks earlier...
but most of the time it breaks after the last println
Markus
@Links2004
May 16 2015 17:16
can you try to send more then 384 byte in one call
ficeto
@ficeto
May 16 2015 17:19
it's fine
i tried 1024 char string
Markus
@Links2004
May 16 2015 17:20
ok so no problem with the buffers of the serial.
ficeto
@ficeto
May 16 2015 17:21
only one thing comes to mind
somewhere inside FS.exists("edit.htm")
uart interrupt is disabled then enabled
a few times probably
Markus
@Links2004
May 16 2015 17:22
but exists shut be read only?
ficeto
@ficeto
May 16 2015 17:23
let me remove the int disable enable from the read method and see
Markus
@Links2004
May 16 2015 17:25
may better use noInterrupts then the irq from serial shut be there and handled later by interrupts (nerver tested but so shut it work ^^)
ficeto
@ficeto
May 16 2015 17:26
actully there is no INT enable/disable there
it's WDT_RESET() << macro I have named so because first I saw it in the UART code
Markus
@Links2004
May 16 2015 17:27
why you use spi_flash_read? shut the flash not be mapped to normal range for read?
ficeto
@ficeto
May 16 2015 17:28
this is wharever is in the spiffs library
ficeto
@ficeto
May 16 2015 17:28
wel...
that can work if chips is smaller than 1MB
above that the memory loops
so have to access it directly
ok... removed that FS.exists() call and no issue now
Markus
@Links2004
May 16 2015 17:30
k (mean the memory loop)
ficeto
@ficeto
May 16 2015 17:30
not really :D
Markus
@Links2004
May 16 2015 17:30
hope get my 4MB flash ships soon the test this out
ficeto
@ficeto
May 16 2015 17:31
anything above 1M will work
Markus
@Links2004
May 16 2015 17:32
my modules all have only 512k. but the question is if the 4mb will mapped full in memory or only the first 1Mb.
but back to the current problem :)
ficeto
@ficeto
May 16 2015 17:34
ok... I added ETS_UART_INTR_DISABLE/ENABLE before and after the memory read and it;s all good with exists as well
WDT_RESET();
  ETS_UART_INTR_DISABLE();
  r = spi_flash_read(fromaddr, (uint32 *)to, size);
  ETS_UART_INTR_ENABLE();
Markus
@Links2004
May 16 2015 17:38
k may the spi_flash_read disable / blocks the mapped memory and then any interrupt that needs functions from flash will wait
but the interrupt blocks the spi flash read --> dead lock
this may also happens with the timers
ficeto
@ficeto
May 16 2015 17:41
it can happen with anything that reads the flash i guess
Markus
@Links2004
May 16 2015 17:42
yes using the mapped flash or noInterrupts() for read are the best options i think
ficeto
@ficeto
May 16 2015 17:43
as I said.. flash maps only to 1MB
so not an option on any board above 1M
Markus
@Links2004
May 16 2015 17:43
even if you have a real 4Mb chip + config in there
ficeto
@ficeto
May 16 2015 17:43
I'll try the noInterrupt
after all I have a ready case that crashes :)
yup
Markus
@Links2004
May 16 2015 17:44
:)
ficeto
@ficeto
May 16 2015 17:44
i have a real 4M chip
config is at the end
but map above 1M loops
==== SPIFFS Info ====
FS Size: 2.98MB
FS Blocks: total: 381, free: 276, size: 8.00KB
FS Pages: allocated: 414, deleted: 2835, size: 256B
FS File: edit.htm, type: file, size: 10.16KB
FS File: esp-201.png, type: file, size: 89.91KB
Markus
@Links2004
May 16 2015 17:45
k bad to know this was hoping i can use all flash for code to do simple bootloading
ficeto
@ficeto
May 16 2015 17:48
/hardware/esp8266com/esp8266/cores/esp8266/Arduino.h:132:77: error: expected ':' or ')' before '__STRINGIFY'
 #define xt_disable_interrupts(state, level) __asm__ __volatile__("rsil %0," __STRINGIFY(level) "; esync; isync; dsync" : "=a" (state))
Markus
@Links2004
May 16 2015 17:49
are you in a "c" file ?
ficeto
@ficeto
May 16 2015 17:49
yup
sspiffs_flashmem.c
Markus
@Links2004
May 16 2015 17:50
k the problem is a missing feature from cpp regarding string handling in precompiler
ficeto
@ficeto
May 16 2015 17:51
workaround?
Markus
@Links2004
May 16 2015 17:51
 __asm__ __volatile__("rsil %0,15; esync; isync; dsync" : "=a" (state))
ficeto
@ficeto
May 16 2015 17:51
should I define this separately or replace the Arduino.h definition?
Markus
@Links2004
May 16 2015 17:52
// level (0-15), 
// level 15 will disable ALL interrupts, 
// level 0 will disable most software interrupts
//
#ifdef __cplusplus
#define xt_disable_interrupts(state, level) __asm__ __volatile__("rsil %0," __STRINGIFY(level) "; esync; isync; dsync" : "=a" (state))
#else
#define xt_disable_interrupts(state, level) __asm__ __volatile__("rsil %0,15; esync; isync; dsync" : "=a" (state))
#endif
#define xt_enable_interrupts(state)  __asm__ __volatile__("wsr %0,ps; esync" :: "a" (state) : "memory")

extern uint32_t interruptsState;

#define interrupts() xt_enable_interrupts(interruptsState)
#define noInterrupts() xt_disable_interrupts(interruptsState, 15)
ficeto
@ficeto
May 16 2015 17:52
aah
ok
should read those comments...
it's working
i replaced the noInterrupts() macro