ESP8266 Developer Zone The Official ESP8266 Forum 2015-08-18T16:12:39+08:00 https://bbs.espressif.com:443/feed.php?f=7&t=944 2015-08-18T16:12:39+08:00 2015-08-18T16:12:39+08:00 https://bbs.espressif.com:443/viewtopic.php?t=944&p=3289#p3289 <![CDATA[Re: Math lib]]> But I don't mind.

Statistics: Posted by eriksl — Tue Aug 18, 2015 4:12 pm


]]>
2015-08-16T21:50:46+08:00 2015-08-16T21:50:46+08:00 https://bbs.espressif.com:443/viewtopic.php?t=944&p=3268#p3268 <![CDATA[Re: Math lib]]> Statistics: Posted by dkinzer — Sun Aug 16, 2015 9:50 pm


]]>
2015-08-16T15:55:25+08:00 2015-08-16T15:55:25+08:00 https://bbs.espressif.com:443/viewtopic.php?t=944&p=3266#p3266 <![CDATA[Re: Math lib]]> Statistics: Posted by eriksl — Sun Aug 16, 2015 3:55 pm


]]>
2015-08-15T22:53:04+08:00 2015-08-15T22:53:04+08:00 https://bbs.espressif.com:443/viewtopic.php?t=944&p=3263#p3263 <![CDATA[Re: Math lib]]>
eriksl wrote:
It does seem a bit cumbersome for arbitrary character strings, though, which take up the largest part of my dram.
As I mentioned, I use helper routines to retrieve read-only data from Flash. I have specialized routines for byte, word, and dword values as well as a routine to copy an arbitrary byte stream from an arbitrary address. An adaptation of the latter routine appears below and the others can be derived from it. The code below was not compiled so there may be some errors in it but the concept should be clear.

Code:

void ICACHE_FLASH_ATTR
flashReadData(const void *addr, void *bufp, uint16_t cnt)
{
    if ((bufp == NULL) || (cnt == 0))
        return;

    // reads from Flash must be done on 32-bit word boundaries
    uint16_t part;
    uint32_t ofst = (uint32_t)addr & 0x03;
    uint8_t *datap = bufp;
    union { uint32_t d; uint8_t b[4]; } data;
    const char *p = (const char *)addr;

    if (ofst)
    {
        // copy the bytes from the first partial word
        if ((part = 4 - ofst) > cnt)
            part = cnt;
        cnt -= part;
        data.d = *(uint32_t *)(p - ofst);
        p += part;
        while (part--)
            *datap++ = data.b[ofst++];
    }

    // copy the remainder of the data
    while (cnt)
    {
        if ((part = cnt) > 4)
            part = 4;
        data.d = *(uint32_t *)p;
        p += part;
        cnt -= part;
        ofst = 0;
        while (part--)
            *datap++ = data.b[ofst++];
    }
}

Statistics: Posted by dkinzer — Sat Aug 15, 2015 10:53 pm


]]>
2015-08-15T15:04:52+08:00 2015-08-15T15:04:52+08:00 https://bbs.espressif.com:443/viewtopic.php?t=944&p=3254#p3254 <![CDATA[Re: Math lib]]> Thanks!

So if I would define a struct that is a multiple of 32 bits in size and that elements that are also multiples of 32 bits and I'd make an array of it, it would work? Maybe that's something we can leave to the compiler by specifying alignment and padding requirements.

It does seem a bit cumbersome for arbitrary character strings, though, which take up the largest part of my dram.

Statistics: Posted by eriksl — Sat Aug 15, 2015 3:04 pm


]]>
2015-08-15T07:32:08+08:00 2015-08-15T07:32:08+08:00 https://bbs.espressif.com:443/viewtopic.php?t=944&p=3252#p3252 <![CDATA[Re: Math lib]]>
eriksl wrote:
[...] the esp8266 doesn't allow the flash to be used for read only data, and throws an execption.
I believe that this assertion is incorrect. I have several const data tables in Flash in my application. The only caveat is that you can't access such data directly unless every element happens to be 32-bit aligned and is a multiple of 32-bits in size. I handle this in my app by using some helper routines (similar to the __LPM_xxx() macros for the AVR) to access the elements of the data. Inside the routines, all reads are done on 32-bit boundaries and in multiples of 32-bits irrespective of the alignment and size of the data being requested.

Statistics: Posted by dkinzer — Sat Aug 15, 2015 7:32 am


]]>
2015-08-14T17:23:51+08:00 2015-08-14T17:23:51+08:00 https://bbs.espressif.com:443/viewtopic.php?t=944&p=3239#p3239 <![CDATA[Re: Math lib]]>
The moving of read only constants to irom sounds interesting. I believe nodemcu already does something like that. What I understand from it, is that you need to install an exception handler (in a very dirty way), because the esp8266 doesn't allow the flash to be used for read only data, and throws an execption. I can find the exception handler in the nodemcu code, but it doesn't seem to do anything but ignoring the exception. I'd expect a piece of emulation code, so I don't really understand, maybe somebody can explain this to me...?

By default all data (read write, read only, static or auto) ends up in dram, just like on Atmel.

Statistics: Posted by eriksl — Fri Aug 14, 2015 5:23 pm


]]>
2015-08-14T11:25:46+08:00 2015-08-14T11:25:46+08:00 https://bbs.espressif.com:443/viewtopic.php?t=944&p=3223#p3223 <![CDATA[Re: Math lib]]>
https://github.com/anakod/esp_microc
https://github.com/SuperHouse/esp-open-rtos (newlib with patch for threadsafe)

In the latest RTOS SDK, text are placed in IROM section by default. It's a nice thing :D

Statistics: Posted by datltq — Fri Aug 14, 2015 11:25 am


]]>
2015-08-14T02:04:47+08:00 2015-08-14T02:04:47+08:00 https://bbs.espressif.com:443/viewtopic.php?t=944&p=3215#p3215 <![CDATA[Re: Math lib]]> https://github.com/espressif/esp_iot_rt ... libmirom.a

Statistics: Posted by blubb — Fri Aug 14, 2015 2:04 am


]]>
2015-08-13T22:46:11+08:00 2015-08-13T22:46:11+08:00 https://bbs.espressif.com:443/viewtopic.php?t=944&p=3211#p3211 <![CDATA[Re: Math lib]]>
The math library IS available and it works, the problem is that everything ends up in iram which fills up before you know it.

So what needs to be done is a math library that has all/most symbols in irom. Do we have volunteers?

I ended up collecting source code replacements for the functions I needed and compiled them myself, including the irom region directive, problem solved...

Statistics: Posted by eriksl — Thu Aug 13, 2015 10:46 pm


]]>
2015-08-13T20:25:45+08:00 2015-08-13T20:25:45+08:00 https://bbs.espressif.com:443/viewtopic.php?t=944&p=3210#p3210 <![CDATA[Re: Math lib]]>
There are two problems. The first is, M_PI is not defined. It's not a real issue, of course. Some C compilers don't do this.

The second problem concerns fmod.

Please try to compile

Code:

double ICACHE_FLASH_ATTR test(void) {
        return fmod(-10, 3);
}


Error message:

Code:

/opt/Espressif/esp_iot_sdk_v1.3.0/lib/libmirom.a(lib_a-e_fmod.o):(.irom0.literal+0x0): undefined reference to `__ieee754_remainder'
/opt/Espressif/esp_iot_sdk_v1.3.0/lib/libmirom.a(lib_a-e_fmod.o): In function `__ieee754_fmod':
/home/wjg/Workspace/esp-open-sdk/crosstool-NG/.build/src/newlib-2.0.0/newlib/libm/math/e_fmod.c:38: undefined reference to `__ieee754_remainder'


I don't know if this is the result of mixing the libs or if the problem exists in the RTOS-SDK as well. Maybe someone can try that?

Until that I have to implement fmod myself, which luckily is not too hard.

So my request to Espressif would be: Please fix fmod and include libmirom.a in the standard SDK. :)

Statistics: Posted by blubb — Thu Aug 13, 2015 8:25 pm


]]>
2015-08-13T15:08:52+08:00 2015-08-13T15:08:52+08:00 https://bbs.espressif.com:443/viewtopic.php?t=944&p=3203#p3203 <![CDATA[Re: Math lib]]>
I did not use the non-RTOS SDK but recently updated of RTOS one include an irom version of libm. I think the non-RTOS SDK should be the same.


https://github.com/espressif/esp_iot_rtos_sdk/

NEW VERSION: 1.0.4

1. memory optimize;
2. add irom version libm.a: libmirom.a;


Dat.

Statistics: Posted by datltq — Thu Aug 13, 2015 3:08 pm


]]>
2015-08-13T07:40:15+08:00 2015-08-13T07:40:15+08:00 https://bbs.espressif.com:443/viewtopic.php?t=944&p=3187#p3187 <![CDATA[Math lib]]> Will we eventually get an official math lib from Espressif? Compiling with -lm currently does not work. The compiler tries to put everything into RAM...
ESP8266 is a powerful chip and I would expect to be able to do anything I did with the (rather slow and very limited) ATmega.

Statistics: Posted by blubb — Thu Aug 13, 2015 7:40 am


]]>