Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not initialize mbed project #4360

Closed
Python380 opened this issue May 31, 2022 · 9 comments
Closed

Could not initialize mbed project #4360

Python380 opened this issue May 31, 2022 · 9 comments

Comments

@Python380
Copy link

Python380 commented May 31, 2022

I am unable to initialize project for the y5 nrf51822 mbug.

I am using a AMD Ryzen 5500U, with Windows and VSCode, Platform Mbed.
The error message I get:

PIO Core Call Error: "Resolving nrf51_mkit environment packages...\r\nAlready up-to-date.\r\nResolving nrf51822_y5_mbug environment packages...\r\nAlready up-to-date.\r\nUpdating metadata for the vscode IDE...\r\n\n\nError: Processing nrf51822_y5_mbug (platform: nordicnrf51; board: nrf51822_y5_mbug; framework: mbed)\r\n--------------------------------------------------------------------------------\r\nVerbose mode can be enabled via -v, --verbose option\r\nCONFIGURATION: https://docs.platformio.org/page/boards/nordicnrf51/nrf51822_y5_mbug.html\r\nPLATFORM: Nordic nRF51 (8.1.0) > y5 nRF51822 mbug\r\nHARDWARE: NRF51822 16MHz, 16KB RAM, 256KB Flash\r\nDEBUG: Current (cmsis-dap) On-board (cmsis-dap) External (blackmagic, jlink, stlink)\r\nPACKAGES: \r\n - framework-mbed @ 5.51105.190312 (5.11.5) \r\n - tool-sreccat @ 1.164.0 (1.64) \r\n - toolchain-gccarmnoneeabi @ 1.70201.0 (7.2.1)\r\nAttributeError: type object 'array.array' has no attribute 'tostring':\r\n File "C:\Users\henri\.platformio\penv\lib\site-packages\platformio\builder\main.py", line 184:\r\n env.SConscript("$BUILD_SCRIPT")\r\n File "C:\Users\henri\.platformio\packages\tool-scons\scons-local-4.3.0\SCons\Script\SConscript.py", line 597:\r\n return _SConscript(self.fs, *files, **subst_kw)\r\n File "C:\Users\henri\.platformio\packages\tool-scons\scons-local-4.3.0\SCons\Script\SConscript.py", line 285:\r\n exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)\r\n File "C:\Users\henri\.platformio\platforms\nordicnrf51\builder\main.py", line 116:\r\n target_elf = env.BuildProgram()\r\n File "C:\Users\henri\.platformio\packages\tool-scons\scons-local-4.3.0\SCons\Util.py", line 742:\r\n return self.method(*nargs, **kwargs)\r\n File "C:\Users\henri\.platformio\penv\lib\site-packages\platformio\builder\tools\platformio.py", line 63:\r\n env.ProcessProgramDeps()\r\n File "C:\Users\henri\.platformio\packages\tool-scons\scons-local-4.3.0\SCons\Util.py", line 742:\r\n return self.method(*nargs, **kwargs)\r\n File "C:\Users\henri\.platformio\penv\lib\site-packages\platformio\builder\tools\platformio.py", line 126:\r\n env.BuildFrameworks(env.get("PIOFRAMEWORK"))\r\n File "C:\Users\henri\.platformio\packages\tool-scons\scons-local-4.3.0\SCons\Util.py", line 742:\r\n return self.method(*nargs, **kwargs)\r\n File "C:\Users\henri\.platformio\penv\lib\site-packages\platformio\builder\tools\platformio.py", line 346:\r\n SConscript(env.GetFrameworkScript(f), exports="env")\r\n File "C:\Users\henri\.platformio\packages\tool-scons\scons-local-4.3.0\SCons\Script\SConscript.py", line 660:\r\n return method(*args, **kw)\r\n File "C:\Users\henri\.platformio\packages\tool-scons\scons-local-4.3.0\SCons\Script\SConscript.py", line 597:\r\n return _SConscript(self.fs, *files, **subst_kw)\r\n File "C:\Users\henri\.platformio\packages\tool-scons\scons-local-4.3.0\SCons\Script\SConscript.py", line 285:\r\n exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)\r\n File "C:\Users\henri\.platformio\platforms\nordicnrf51\builder\frameworks\mbed.py", line 35:\r\n SConscript(\r\n File "C:\Users\henri\.platformio\packages\tool-scons\scons-local-4.3.0\SCons\Script\SConscript.py", line 660:\r\n return method(*args, **kw)\r\n File "C:\Users\henri\.platformio\packages\tool-scons\scons-local-4.3.0\SCons\Script\SConscript.py", line 597:\r\n return _SConscript(self.fs, *files, **subst_kw)\r\n File "C:\Users\henri\.platformio\packages\tool-scons\scons-local-4.3.0\SCons\Script\SConscript.py", line 285:\r\n exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)\r\n File "C:\Users\henri\.platformio\packages\framework-mbed\platformio\platformio-build.py", line 40:\r\n from pio_mbed_adapter import PlatformioMbedAdapter\r\n File "C:\Users\henri\.platformio\packages\framework-mbed\platformio\pio_mbed_adapter.py", line 23:\r\n from tools.build_api import (prepare_toolchain, merge_region_list,\r\n File "C:\Users\henri\.platformio\packages\framework-mbed\tools\build_api.py", line 30:\r\n from intelhex import IntelHex\r\n File "C:\Users\henri\.platformio\packages\framework-mbed\platformio\package_deps\py3\intelhex\init.py", line 44:\r\n from intelhex.compat import (\r\n File "C:\Users\henri\.platformio\packages\framework-mbed\platformio\package_deps\py3\intelhex\compat.py", line 60:\r\n array_tobytes = getattr(array.array, "tobytes", array.array.tostring)\r\n========================== [FAILED] Took 0.60 seconds ==========================\r\n\r\nEnvironment Status Duration\r\n---------------- -------- ------------\r\nnrf51822_y5_mbug FAILED 00:00:00.600\r\n==================== 1 failed, 0 succeeded in 00:00:00.600 ===================="

The error itself:
AttributeError: type object 'array.array' has no attribute 'tostring'

Other notes:
I am using the latest Platform IO version.

What should I try to do to fix this?

(This issue has appeared 4 times already, but no one else included extra information about their system and configuration.)
EDIT was just looking through the issues page, it appears more than 4 times...

@Python380
Copy link
Author

Python380 commented May 31, 2022

A little bit cleaned up:

.platformio/packages/framework-mbed/platformio/package_deps/py3/intelhex/compat.py, line 60

AttributeError:
object array.array has no attribute tostring

Could be python version?
Using python 3.9.6

@Python380
Copy link
Author

Opening the project that I initialized and then attempting to build returns a clean version of the error messages above.

AttributeError: type object 'array.array' has no attribute 'tostring':
  File "C:\Users\henri\.platformio\penv\lib\site-packages\platformio\builder\main.py", line 184:
    env.SConscript("$BUILD_SCRIPT")
  File "C:\Users\henri\.platformio\packages\tool-scons\scons-local-4.3.0\SCons\Script\SConscript.py", line 597:
    return _SConscript(self.fs, *files, **subst_kw)
  File "C:\Users\henri\.platformio\packages\tool-scons\scons-local-4.3.0\SCons\Script\SConscript.py", line 285:
    exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)
  File "C:\Users\henri\.platformio\platforms\nordicnrf51\builder\main.py", line 116:
    target_elf = env.BuildProgram()
  File "C:\Users\henri\.platformio\packages\tool-scons\scons-local-4.3.0\SCons\Util.py", line 742:
    return self.method(*nargs, **kwargs)
  File "C:\Users\henri\.platformio\penv\lib\site-packages\platformio\builder\tools\platformio.py", line 63:
    env.ProcessProgramDeps()
  File "C:\Users\henri\.platformio\packages\tool-scons\scons-local-4.3.0\SCons\Util.py", line 742:
    return self.method(*nargs, **kwargs)
  File "C:\Users\henri\.platformio\penv\lib\site-packages\platformio\builder\tools\platformio.py", line 126:
    env.BuildFrameworks(env.get("PIOFRAMEWORK"))
  File "C:\Users\henri\.platformio\packages\tool-scons\scons-local-4.3.0\SCons\Util.py", line 742:
    return self.method(*nargs, **kwargs)
  File "C:\Users\henri\.platformio\penv\lib\site-packages\platformio\builder\tools\platformio.py", line 346:
    SConscript(env.GetFrameworkScript(f), exports="env")
  File "C:\Users\henri\.platformio\packages\tool-scons\scons-local-4.3.0\SCons\Script\SConscript.py", line 660:
    return method(*args, **kw)
  File "C:\Users\henri\.platformio\packages\tool-scons\scons-local-4.3.0\SCons\Script\SConscript.py", line 597:
    return _SConscript(self.fs, *files, **subst_kw)
  File "C:\Users\henri\.platformio\packages\tool-scons\scons-local-4.3.0\SCons\Script\SConscript.py", line 285:
    exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)
  File "C:\Users\henri\.platformio\platforms\nordicnrf51\builder\frameworks\mbed.py", line 35:
    SConscript(
  File "C:\Users\henri\.platformio\packages\tool-scons\scons-local-4.3.0\SCons\Script\SConscript.py", line 660:
    return method(*args, **kw)
  File "C:\Users\henri\.platformio\packages\tool-scons\scons-local-4.3.0\SCons\Script\SConscript.py", line 597:
    return _SConscript(self.fs, *files, **subst_kw)
  File "C:\Users\henri\.platformio\packages\tool-scons\scons-local-4.3.0\SCons\Script\SConscript.py", line 285:
    exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)
  File "C:\Users\henri\.platformio\packages\framework-mbed\platformio\platformio-build.py", line 40:
    from pio_mbed_adapter import PlatformioMbedAdapter
  File "C:\Users\henri\.platformio\packages\framework-mbed\platformio\pio_mbed_adapter.py", line 23:
    from tools.build_api import (prepare_toolchain, merge_region_list,
  File "C:\Users\henri\.platformio\packages\framework-mbed\tools\build_api.py", line 30:
    from intelhex import IntelHex
  File "C:\Users\henri\.platformio\packages\framework-mbed\platformio\package_deps\py3\intelhex\__init__.py", line 44:
    from intelhex.compat import (
  File "C:\Users\henri\.platformio\packages\framework-mbed\platformio\package_deps\py3\intelhex\compat.py", line 60:
    array_tobytes = getattr(array.array, "tobytes", array.array.tostring)

@Python380
Copy link
Author

Python380 commented May 31, 2022

changing compat.py in intelhex to

# Copyright (c) 2011, Bernhard Leiner
# Copyright (c) 2013-2018 Alexander Belchenko
# All rights reserved.
#
# Redistribution and use in source and binary forms,
# with or without modification, are permitted provided
# that the following conditions are met:
#
# * Redistributions of source code must retain
#   the above copyright notice, this list of conditions
#   and the following disclaimer.
# * Redistributions in binary form must reproduce
#   the above copyright notice, this list of conditions
#   and the following disclaimer in the documentation
#   and/or other materials provided with the distribution.
# * Neither the name of the author nor the names
#   of its contributors may be used to endorse
#   or promote products derived from this software
#   without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
# OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

'''Compatibility functions for python 2 and 3.

@author     Bernhard Leiner (bleiner AT gmail com)
@author     Alexander Belchenko (alexander belchenko AT gmail com)
'''

__docformat__ = "javadoc"


import sys, array


# if sys.version_info[0] >= 3:
# Python 3
Python = 3

def asbytes(s):
    if isinstance(s, bytes):
        return s
    return s.encode('latin1')
def asstr(s):
    if isinstance(s, str):
        return s
    return s.decode('latin1')

array_tobytes = getattr(array.array, "tobytes", array.array.tostring)

IntTypes = (int,)
StrType = str
UnicodeType = str

range_g = range     # range generator
def range_l(*args): # range list
    return list(range(*args))

def dict_keys(dikt):        # dict keys list
    return list(dikt.keys())
def dict_keys_g(dikt):      # dict keys generator
    return dikt.keys()
def dict_items_g(dikt):     # dict items generator
    return dikt.items()

from io import StringIO, BytesIO

def get_binary_stdout():
    return sys.stdout.buffer

def get_binary_stdin():
    return sys.stdin.buffer

##else:
##    # Python 2
##    Python = 2
##
##    asbytes = str
##    asstr = str
##
##    array_tobytes = array.array.tostring
##
##    IntTypes = (int, long)
##    StrType = basestring
##    UnicodeType = unicode
##
##    #range_g = xrange    # range generator
##    def range_g(*args):
##        # we want to use xrange here but on python 2 it does not work with long ints
##        try:
##            return xrange(*args)
##        except OverflowError:
##            start = 0
##            stop = 0
##            step = 1
##            n = len(args)
##            if n == 1:
##                stop = args[0]
##            elif n == 2:
##                start, stop = args
##            elif n == 3:
##                start, stop, step = args
##            else:
##                raise TypeError('wrong number of arguments in range_g call!')
##            if step == 0:
##                raise ValueError('step cannot be zero')
##            if step > 0:
##                def up(start, stop, step):
##                    while start < stop:
##                        yield start
##                        start += step
##                return up(start, stop, step)
##            else:
##                def down(start, stop, step):
##                    while start > stop:
##                        yield start
##                        start += step
##                return down(start, stop, step)
##
##    range_l = range     # range list
##
##    def dict_keys(dikt):        # dict keys list
##        return dikt.keys()
##    def dict_keys_g(dikt):      # dict keys generator
##        return dikt.keys()
##    def dict_items_g(dikt):     # dict items generator
##        return dikt.items()
##
##    from cStringIO import StringIO
##    BytesIO = StringIO
##
##    import os
##    def _force_stream_binary(stream):
##        """Force binary mode for stream on Windows."""
##        if os.name == 'nt':
##            f_fileno = getattr(stream, 'fileno', None)
##            if f_fileno:
##                fileno = f_fileno()
##                if fileno >= 0:
##                    import msvcrt
##                    msvcrt.setmode(fileno, os.O_BINARY)
##        return stream
##
##    def get_binary_stdout():
##        return _force_stream_binary(sys.stdout)
##
##    def get_binary_stdin():
##        return _force_stream_binary(sys.stdin)
##

was not a success.
Could have guessed, the problem is with the array.array.tostring. I also know the fastest fix would be to hard-code it to be array.array.tobytes instead of getattr(...), but thought I'd better try other things first, just in case it was an issue with how things were set up.
reverting.

@Python380
Copy link
Author

Python380 commented May 31, 2022

adding a () to the end of array.array.tostring did not work.

Reverting.

@Python380
Copy link
Author

Python380 commented May 31, 2022

Checking python documentation for the array package tells me there is no array.array.tostring.
Changing line to read array_tobytes = array.array.tobytes worked. Note later on about a better fix.

@Python380
Copy link
Author

Python380 commented May 31, 2022

Found a fix for AttributeError: type object 'array.array' has no attribute 'tostring'. @ivankravets

@Python380
Copy link
Author

Note: wrapping array_tobytes = getattr(array.array, "tobytes", array.array.tostring) in a try/except may be a better fix.

@Python380
Copy link
Author

Final compat.py file is attached in zip file.
compat.zip

@Python380 Python380 reopened this May 31, 2022
@Python380
Copy link
Author

Intel hex is outdated on framework-mbed. Opening pull request and issue there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant