Discuss here different C compiler set ups, and compiling executables for the ESP8266

User avatar
By OssO
#13663 So, another try.
I changed the header files in nodemcu project, from 8 bit to 32 bit. And the 256-repetition dissappears. Looks like it is compiling more correctly now.
But, another strange behavior appears.
I can not read odd ( not multiple by 4 ) addresses - system hangs up or restarts - as it was doing before.
OK, so the address must be divisible by 4.
But then, I can not also use any address higher then 188.
For 188 it reads a value, for 189,190,191 it hangs, and for 192 it returns false as indication of no success - as for any other higher value.
So it looks like the function is not multiplying the address by 4, but it is limiting the value of address to 191 maximum ( as it should if it will multiply the adress by 4 ).
Nice :?
User avatar
By jcmvbkbc
#13708
OssO wrote:But, another strange behavior appears.
I can not read odd ( not multiple by 4 ) addresses - system hangs up or restarts - as it was doing before.

Ok, you're right. The math is wrong:
Code: Select all000000f4 <system_rtc_mem_read>:
  f4:   bfa052          movi    a5, 191
  f7:   123527          bltu    a5, a2, 10d <system_rtc_mem_read+0x19>   <<<  check if src_addr < 192, OK
                        f7: R_XTENSA_SLOT0_OP   .text+0x10d
  fa:   370c            movi.n  a7, 3
  fc:   146030          extui   a6, a3, 0, 2
  ff:   a6cc            bnez.n  a6, 10d <system_rtc_mem_read+0x19>
                        ff: R_XTENSA_SLOT0_OP   .text+0x10d
 101:   1192e0          slli    a9, a2, 2                                <<< Multiply src_addr by 4 for size calculation, OK
 104:   00a382          movi    a8, 0x300
 107:   c08890          sub     a8, a8, a9
 10a:   03a847          bge     a8, a4, 111 <system_rtc_mem_read+0x1d>
                        10a: R_XTENSA_SLOT0_OP  .text+0x111
 10d:   020c            movi.n  a2, 0
 10f:   f00d            ret.n
 111:   0a0747          bnone   a7, a4, 11f <system_rtc_mem_read+0x2b>
                        111: R_XTENSA_SLOT0_OP  .text+0x11f
 114:   450c            movi.n  a5, 4
 116:   414240          srli    a4, a4, 2
 119:   a04450          addx4   a4, a4, a5
 11c:   f44040          extui   a4, a4, 0, 16
 11f:   418240          srli    a8, a4, 2
 122:   e89c            beqz.n  a8, 144 <system_rtc_mem_read+0x50>
                        122: R_XTENSA_SLOT0_OP  .text+0x144
 124:   fff371          l32r    a7, f0 <system_rtc_mem_write+0x54>
                        124: R_XTENSA_SLOT0_OP  .text+0xf0
 127:   040c            movi.n  a4, 0                                    <<< i = 0
 129:   a05420          addx4   a5, a4, a2                               <<< a5 = i * 4 + src_addr. Wrong.
 12c:   a06430          addx4   a6, a4, a3
 12f:   557a            add.n   a5, a5, a7                               <<< addr = a5 + RTC mem base
 131:   0020c0          memw
 134:   c02552          l32i    a5, a5, 0x300
 137:   0020c0          memw
 13a:   0659            s32i.n  a5, a6, 0
 13c:   441b            addi.n  a4, a4, 1
 13e:   744040          extui   a4, a4, 0, 8
 141:   e43487          bltu    a4, a8, 129 <system_rtc_mem_read+0x35>
                        141: R_XTENSA_SLOT0_OP  .text+0x129
 144:   120c            movi.n  a2, 1
 146:   f00d            ret.n


a5 should have been i + src_addr, and addr should have been a5 * 4 + RTC mem base.
User avatar
By OssO
#13738 Thanks a lot for your help.
So wrong function ( api bug ) looks found.
I downloaded 1.0.0 sdk, and there is a remark about some rtc memory bug fix in version 1.0.0 from 20.03.2015.
What version are you dissassembling ?
I used 0.9.5 for compile, since nodemcu is based on it at this time, but maybe if I will be able to switch to newer, it can be already fixed.