tralamazza / micropython

MicroPython - a lean and efficient Python implementation for microcontrollers and constrained systems
MIT License
29 stars 9 forks source link

compilation error for new version #194

Closed linycm closed 6 years ago

linycm commented 6 years ago

Hi,

I encounter many error for the recent version compilation as below. What's the reason?

GEN build-pca10040/genhdr/qstr.i.last In file included from ../../py/mphal.h:34:0, from ../../py/mpprint.c:33: ./mphalport.h:31:10: fatal error: nrfx.h: No such file or directory

include

      ^~~~~~~~

compilation terminate

Rdgs, Martin

linycm commented 6 years ago

The environment is: complie gcc-arm-none-eabi-7-2017-q4-major, virtual machine is Vmware workstation 64 bit Ubuntu.

glennrub commented 6 years ago

Hi @linycm !

Based on the error, not finding nrfx.h, it looks like you have not fetched the nrfx through the git submodule. To fetch the submodules you can run the following command inside you local clone of the repository:

git submodule update --init

linycm commented 6 years ago

I had run the command git submodule update --init at the first, but got error. So I run the command git init and then run "git submodule update --init". But don't fetch more submodules. How to do?

glennrub commented 6 years ago

Can you see the nrfx.h under \<clone-root>/lib/nrfx/ ? Or is it missing?

glennrub commented 6 years ago

one important note on the "git submodule update" is that it has to be done inside the folder you have cloned it to. Else it would not have any effect.

aykevl commented 6 years ago

So I run the command git init [...]

Don't do that in an existing repository, although it probably won't do any harm. git init is for creating a new repository. From the docs:

Running git init in an existing repository is safe. It will not overwrite things that are already there. The primary reason for rerunning git init is to pick up newly added templates (or to move the repository to another place if --separate-git-dir is given).

I don't know why git submodule update --init doesn't work for you, it has never failed for me.

linycm commented 6 years ago

When I download a source.zip file as micropython folder, "git submodule update --init" cannot work. /lib/nrfx/ is empty. When I use git clone... method, "git submodule update --init" works.

I complie with parameter "FROZEN_MPY_DIR=freeze", the result have error as below:

build-pca10040/frozen_mpy.c:39:26: error: size of 'mp_qstr_const_pool' differ from the size of original declaration [-Werror=lto-type-mismatch] extern const qstr_pool_t mp_qstr_const_pool; ^ ../../py/qstr.c:98:19: note: 'mp_qstr_const_pool' was previously declared here const qstr_pool_t mp_qstr_const_pool = { ^ ../../py/qstr.c:113:26: error: size of 'mp_qstr_frozen_const_pool' differ from the size of original declaration [-Werror=lto-type-mismatch] extern const qstr_pool_t MICROPY_QSTR_EXTRA_POOL; ^ build-pca10040/frozen_mpy.c:40:19: note: 'mp_qstr_frozen_const_pool' was previously declared here const qstr_pool_t mp_qstr_frozen_const_pool = { ^ lto1: all warnings being treated as errors lto-wrapper: fatal error: /home/martin/Ctools/gcc-arm-none-eabi-7-2017-q4-major/bin/arm-none-eabi-gcc returned 1 exit status compilation terminated.

linycm commented 6 years ago

Since I want to add filesystem support, if don't use the method of compile with FROZEN_MPY_DIR=yourdirectory, then add AMPY support, in mpconfigboard.h added "#define MICROPY_HW_HAS_BUILTIN_FLASH (1)". Got the error as below:

CC modules/uos/microbitfs.c modules/uos/microbitfs.c: In function 'advance': modules/uos/microbitfs.c:407:24: error: 'ENOSPC' undeclared (first use in this function); did you mean 'MP_ENOSPC'? return ENOSPC; ^~ MP_ENOSPC modules/uos/microbitfs.c:407:24: note: each undeclared identifier is reported only once for each function it appears in modules/uos/microbitfs.c: In function 'microbit_file_read': modules/uos/microbitfs.c:423:20: error: 'EBADF' undeclared (first use in this function); did you mean 'MP_EBADF'? errcode = EBADF; ^~~~~ MP_EBADF modules/uos/microbitfs.c: In function 'microbit_file_write': modules/uos/microbitfs.c:453:20: error: 'EBADF' undeclared (first use in this function); did you mean 'MP_EBADF'? errcode = EBADF; ^~~~~ MP_EBADF In file included from modules/uos/microbitfs.h:30:0, from modules/uos/microbitfs.c:32: At top level: modules/uos/microbitfs.c:564:34: error: 'uos_mbfs_mount_obj' defined but not used [-Werror=unused-const-variable=] STATIC MP_DEFINE_CONST_FUN_OBJ_3(uos_mbfs_mount_obj, uos_mbfs_mount); ^ ../../py/obj.h:283:38: note: in definition of macro 'MP_DEFINE_CONST_FUN_OBJ_3' const mp_obj_fun_builtin_fixed_t obj_name = \


How can it be resovled?

aykevl commented 6 years ago

When I download a source.zip file as micropython folder, "git submodule update --init" cannot work.

That's right, when you download the source as a .zip file from GitHub you're only getting the source files, not the git repository. So then all git commands will fail. In most cases, cloning with git is the best option.

lto-wrapper: fatal error: /home/martin/Ctools/gcc-arm-none-eabi-7-2017-q4-major/bin/arm-none-eabi-gcc returned 1 exit status

It looks like you're using a very new compiler which may give more compile errors. Can you run this command and paste the output?

arm-none-eabi-gcc --version

And this error:

CC modules/uos/microbitfs.c
modules/uos/microbitfs.c: In function 'advance':
modules/uos/microbitfs.c:407:24: error: 'ENOSPC' undeclared (first use in this function); did you mean 'MP_ENOSPC'?

It probably shows an error for you as you're using a different toolchain but the fix is as gcc suggests. I'll send a patch soon. EDIT: my bad: I broke it recently but didn't test properly.

modules/uos/microbitfs.c:564:34: error: 'uos_mbfs_mount_obj' defined but not used [-Werror=unused-const-variable=]
STATIC MP_DEFINE_CONST_FUN_OBJ_3(uos_mbfs_mount_obj, uos_mbfs_mount);

Interesting. The error is correct but the issue is harmless. Removing this line should silence the error.

aykevl commented 6 years ago

Oh and so you know: if you add three backticks (```) before and after a code or output block, the code will be much more readable. See this page for more information.

linycm commented 6 years ago

Current compiler is '''arm-none-eabi-gcc (GNU Tools for Arm Embedded Processors 7-2017-q4-major) 7.2.1 20170904 (release) [ARM/embedded-7-branch revision 255204]'''.

But I change to arm-none-eabi-gcc 6.3.1 20170620 (release), I got similar error result when compile with '''make FROZEN_MPY_DIR=yourdirectory'''.

glennrub commented 6 years ago

Thanks @aykevl for doing the patches in #195 and #196. I have merged them both to master. @linycm could you test the latest git master, to see if this resolves the issues you are seeing?

aykevl commented 6 years ago

The link errors haven't been fixed yet. A temporary workaround is not specifying FROZEN_MPY_DIR or removing -Werror from the Makefile. I think it's an issue with how frozen MPY files are generated and should be fixed in MicroPython (not this port).

linycm commented 6 years ago

@aykevl , @glennrub Thank you! I try lastest git master, it pass the complie when added "'#define MICROPY_HW_HAS_BUILTIN_FLASH (1)"' in mpconfigboard.h.

After I flash firmware inot PCA10040, I put command in Unbutu '''sudo ampy --port /dev/ttyUSB0 ls''', I cannot got correct AMPY result: ''' Traceback (most recent call last): File "/usr/local/bin/ampy", line 11, in sys.exit(cli()) File "/home/martin/.local/lib/python3.5/site-packages/click/core.py", line 722, in call return self.main(args, kwargs) File "/home/martin/.local/lib/python3.5/site-packages/click/core.py", line 697, in main rv = self.invoke(ctx) File "/home/martin/.local/lib/python3.5/site-packages/click/core.py", line 1066, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/home/martin/.local/lib/python3.5/site-packages/click/core.py", line 895, in invoke return ctx.invoke(self.callback, ctx.params) File "/home/martin/.local/lib/python3.5/site-packages/click/core.py", line 535, in invoke return callback(args, **kwargs) File "/home/martin/.local/lib/python3.5/site-packages/ampy/cli.py", line 147, in ls for f in board_files.ls(directory): File "/home/martin/.local/lib/python3.5/site-packages/ampy/files.py", line 103, in ls raise ex File "/home/martin/.local/lib/python3.5/site-packages/ampy/files.py", line 96, in ls out = self.pyboard.exec(textwrap.dedent(command)) File "/home/martin/.local/lib/python3.5/site-packages/ampy/pyboard.py", line 265, in exec_ raise PyboardError('exception', ret, ret_err) ampy.pyboard.PyboardError: ('exception', b'', b'Traceback (most recent call last):\r\n File "", in \r\nTypeError: function takes 0 positional arguments but 1 were given\r\n') ''' Is it something wrong in my operation for AMPY?

linycm commented 6 years ago

If I put main.py in freeze folder, compile '''FROZEN_MPY_DIR=freeze''' and removing -Werror from the Makefile, then after I flash firmware, The main.py function can work when ‘’‘import main''' in REPL. But I want main.py function can work when the board reboot. I cannot figure it out.

aykevl commented 6 years ago

At the moment it appears to be impossible to execute main.py as a frozen script. The way I work around it is by using a module with a different name and creating a file in the flash filesystem that imports it:

>>> f = open('boot.py', 'w')
>>> f.write('from main import *')
>>> f.close()

It should be fixed, though...

aykevl commented 6 years ago

Oh and I see the problem with ampy: the ls command doesn't work. Probably because ampy gives it a parameter and this filesystem doesn't support it. I think other commands will work. I have used it for put before.

linycm commented 6 years ago

@aykevl Thank you! The below works. I realize some function when reboot.

f = open('boot.py', 'w') f.write('from main import *') f.close()

The command '''put''' file into board works in AMPY.

glennrub commented 6 years ago

In order to clean up a bit i'm closing this issue in this repo as the continuation of the nrf-port development should happen in mainline micropython repository after the merge. If the issue is still applicable it could be raised towards mainline repo.