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

Mbed studio: Nuvoton M2354: build failed #15417

Open
lunchboxwu opened this issue May 5, 2023 · 11 comments
Open

Mbed studio: Nuvoton M2354: build failed #15417

lunchboxwu opened this issue May 5, 2023 · 11 comments

Comments

@lunchboxwu
Copy link

lunchboxwu commented May 5, 2023

Description of defect

On ARM Mbed Studio, targeting NUMAKER-M2354 v1.1 (NU_M2354), mbed-os-example-blinky (mbed-os 6.17.0) build failed with error log listed below. Tried other sample projects like mbed-os-empty with no avail either.

Target(s) affected by this defect ?

MCU: Nuvoton M2354
Board: NUMAKER-M2354 v1.1 (NU_M2354)

Toolchain(s) (name and version) displaying this defect ?

ARMC6

What version of Mbed-os are you using (tag or sha) ?

mbed-os 6.17.0
Commit: 17dc3dc

What version(s) of tools are you using. List all that apply (E.g. mbed-cli)

Mbed Studio: 1.4.5

How is this defect reproduced ?

  1. Log in Mbed Studio
  2. Click File > New Program > mbed-os-example-blinky > Add Program
  3. Update library to mbed-os-6.17.0 if not yet
  4. Specify NUMAKER-M2354 as target hardware
  5. Build failed with log:

Image: BUILD/NU_M2354/ARMC6\mbed-os-example-blinky.bin
0002874:CRITICAL:main:cannot read register r0 because core #0 is not halted
Traceback (most recent call last):
File "c:\Users\lunch\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd_main_.py", line 402, in run
self.COMMANDSself._args.cmd
File "c:\Users\lunch\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd_main
.py", line 579, in do_flash
file_format=self._args.format)
File "c:\Users\lunch\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\flash\file_programmer.py", line 157, in program
self._loader.commit()
File "c:\Users\lunch\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\flash\loader.py", line 168, in commit
keep_unwritten=self._keep_unwritten)
File "c:\Users\lunch\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\flash\builder.py", line 464, in program
flash_operation = self._chip_erase_program_double_buffer(progress_cb)
File "c:\Users\lunch\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\flash\builder.py", line 706, in _chip_erase_program_double_buffer
self.flash.erase_all()
File "c:\Users\lunch\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\flash\flash.py", line 345, in erase_all
result = self._call_function_and_wait(self.flash_algo['pc_eraseAll'])
File "c:\Users\lunch\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\flash\flash.py", line 604, in _call_function_and_wait
return self.wait_for_completion()
File "c:\Users\lunch\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\flash\flash.py", line 600, in wait_for_completion
return self.target.read_core_register('r0')
File "c:\Users\lunch\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\core\soc_target.py", line 173, in read_core_register
return self.selected_core.read_core_register(id)
File "c:\Users\lunch\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\coresight\cortex_m.py", line 911, in read_core_register
regValue = self.read_core_register_raw(reg_info.index)
File "c:\Users\lunch\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\coresight\cortex_m.py", line 928, in read_core_register_raw
vals = self.read_core_registers_raw([reg])
File "c:\Users\lunch\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\coresight\cortex_m.py", line 949, in read_core_registers_raw
return self._base_read_core_registers_raw(reg_list)
File "c:\Users\lunch\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\coresight\cortex_m.py", line 967, in _base_read_core_registers_raw
self.core_number))
pyocd.core.exceptions.CoreRegisterAccessError: cannot read register r0 because core #0 is not halted

@mbedmain
Copy link

mbedmain commented May 5, 2023

@lunchboxwu thank you for raising this issue.Please take a look at the following comments:

Could you add some more detail to the description? A good description should be at least 25 words.

NOTE: If there are fields which are not applicable then please just add 'n/a' or 'None'. This indicates to us that at least all the fields have been considered.
Please update the issue header with the missing information.

@lunchboxwu lunchboxwu changed the title mbed studio: m2354: build failed Mbed studio: Nuvoton M2354: build failed May 5, 2023
@0xc0170
Copy link
Contributor

0xc0170 commented May 8, 2023

cc @ARMmbed/team-nuvoton

@ccli8
Copy link
Contributor

ccli8 commented May 8, 2023

The error log is related to pyocd. Currently, M2354 board's NuLink2 doesn't support flash or debug on Mbed Studio. Just build code only, that is, on Mbed Sutdio, click Build program, neither Run program nor Debug program. To flash code, go USB drag-and-drop programming.

@cyliangtw
Copy link
Contributor

@ccli8
In fact, M2354 support pyocd in Jun 2021 at:
https://github.com/pyocd/pyOCD/blob/main/pyocd/target/builtin/target_M2354.py

please esnure Nu-Link2 with correct F/W and mbed-studio with up-to-date pyOCD pack.

@cyliangtw
Copy link
Contributor

cyliangtw commented May 9, 2023

After checking, Nu-Link2 default F/W is for normal drag-drop & mbed green-tea test support.
For M2354 mbed-studio debug support, you must update as NuLink2_DAPLink_for_numaker_m2354.bin.
How to update Nu-Link2 F/W, please refer to the steps of sub topic DAP Link Interface Firmware Update at: https://os.mbed.com/platforms/NUMAKER-M2354/

@ccli8
Copy link
Contributor

ccli8 commented May 9, 2023

For M2354 mbed-studio debug support, you must update as NuLink2_DAPLink_for_numaker_m2354.bin.

This is necessary. However, Mbed Studio's inbuilt pyOCD version 0.30.2 hasn't supported M2354. Upgrade this inbuilt pyOCD to latest version manually may break Mbed Studio. So Flash & Debug for M2354 are still not supported on Mbed Studio.

@cyliangtw
Copy link
Contributor

Manual upgrade pyocd is relative to python site package, for ex "Python38\Lib\site-packages\pyocd". My environment is pyocd v0.34.0 and get:

[cygwin~zephyr]$ pyocd list --targets | grep Nuvoton
  m2354kjfae                Nuvoton                 M2354KJFAE                              builtin 
  m252kg6ae                 Nuvoton                 M252KG6AE                               builtin 
  m263kiaae                 Nuvoton                 M263KIAAE                               builtin 
  m467hjhae                 Nuvoton                 M467HJHAE                               builtin 
  m487jidae                 Nuvoton                 M487JIDAE                               builtin 

In mbed studio environment console, it should reach python path and could manual update by "pip install pyocd" ?

@ccli8
Copy link
Contributor

ccli8 commented May 10, 2023

In mbed studio environment console, it should reach python path and could manual update by "pip install pyocd" ?

Yes. In Mbed Studio, open builtin console through Terminal > New Terminal and run like pip install -U pyocd to upgrade pyocd. But I don’t suggest doing it because as reported it will break Mbed Studio on pyocd relative files.

ccli8 added a commit to ccli8/mbed-os that referenced this issue May 22, 2023
Mbed Studio Debug, based on pyOCD, requires Mbed OS application code starting on the sector boundary.

Modification list:
1.  Update TF-M import assets with MCUboot header padding to sector aligned
2.  Following above, change header size argument (-H) in wrapper.py command line

Related issue:
ARMmbed#15417
ccli8 added a commit to ccli8/mbed-os that referenced this issue May 23, 2023
In Mbed Studio, debugging, based on pyOCD, requires Mbed OS application code starting on the sector boundary.

Modification list:
1.  Update TF-M import assets with MCUboot header padding to sector aligned
2.  Following above, change header size argument (-H) in wrapper.py command line
3.  Following below, fix min-write-size (--align) to 4 (per flash_area_align()) in wrapper.py command line
    https://docs.mcuboot.com/design.html#image-trailer

Related issue:
ARMmbed#15417
ccli8 added a commit to OpenNuvoton/mbed that referenced this issue May 30, 2023
In Mbed Studio, debugging, based on pyOCD, requires Mbed OS application code starting on the sector boundary.

Modification list:
1.  Update TF-M import assets with MCUboot header padding to sector aligned
2.  Following above, change header size argument (-H) in wrapper.py command line
3.  Following below, fix min-write-size (--align) to 4 (per flash_area_align()) in wrapper.py command line
    https://docs.mcuboot.com/design.html#image-trailer

Related issue:
ARMmbed#15417
@ccli8
Copy link
Contributor

ccli8 commented May 31, 2023

To enable flashing and debugging M2354 on Mbed Studio, please follow the flow:

  1. Apply M2354: Fix debug failure in Mbed Studio #15427 to fix Mbed OS application program doesn't start on the sector boundary. This is required by pyOCD Debug.

  2. Follow the procedure to upgrade NuLink2 F/W to v7509 or later. After upgrade is finished and USB is reconnected, open NU_CFG.TXT in the USB drive and check its content:

    • Version >= 7509 (Version=7509)
    • CMSIS DAP enabled (CMSIS-DAP=1).

    If either doesn't meet, apply one clean upgrade through ICP Tool instead of drag-and-drop upgrade as mentioned in As While DAP Button Not Work section in above procedure.

    NOTE: As of this writing, v7509 is not released yet.

  3. Mbed Studio 1.4.5 + pyOCD 0.30.2 doesn't support M2354 natively. Go extended support way through CMSIS Pack (detailed below).

@ccli8
Copy link
Contributor

ccli8 commented May 31, 2023

To extend pyOCD support for M2354 via CMSIS Pack, follow the procedure (verified on Windows 10):

  1. Download Nuvoton.NuMicro_DFP.1.3.20.pack. Assume it is saved in C:\Users\MY_ACCOUNT\Downloads.

  2. Connect M2354. Launch Mbed Studio.

  3. Follow Manage Custom Targets. In DebugFlags field, override its content with --target M2354KJFAE. Click Save All. This is to generate draft custom_targets.json which needs further editing.

  4. Find custom_targets.json through Help > Report an issue. Click Access Log to open the directory containing custom_targets.json.

  5. Exit Mbed Studio.

  6. Open custom_targets.json. All content may place in single line. Try google "pretty json" to find one tool to pretty print it.

  7. Based on existent content, edit like below. Save it.

    {
        "13120000002B005104448580000009FA": {
            "debugFlags": "--target M2354KJFAE --pack \"C:\\Users\\MY_ACCOUNT\\Downloads\\Nuvoton.NuMicro_DFP.1.3.20.pack\"",
            "productCode": "1312",
            "debugTarget": "M2354KJFAE",
            "cmsisPack": "C:\\Users\\MY_ACCOUNT\\Downloads\\Nuvoton.NuMicro_DFP.1.3.20.pack"
        }
    }
  8. Re-launch Mbed Studio. If everything goes smooth, flashing and debugging M2354 should be OK.

ccli8 added a commit to OpenNuvoton/mbed that referenced this issue Jun 2, 2023
In Mbed Studio, debugging, based on pyOCD, requires Mbed OS application code starting on the sector boundary.

Modification list:
1.  Update TF-M import assets with MCUboot header padding to sector aligned
2.  Following above, change header size argument (-H) in wrapper.py command line
3.  Following below, fix min-write-size (--align) to 4 (per flash_area_align()) in wrapper.py command line
    https://docs.mcuboot.com/design.html#image-trailer

Related issue:
ARMmbed#15417
@cyliangtw
Copy link
Contributor

This issue was fixed and could be closed.

multiplemonomials pushed a commit to mbed-ce/mbed-os that referenced this issue Sep 24, 2023
In Mbed Studio, debugging, based on pyOCD, requires Mbed OS application code starting on the sector boundary.

Modification list:
1.  Update TF-M import assets with MCUboot header padding to sector aligned
2.  Following above, change header size argument (-H) in wrapper.py command line
3.  Following below, fix min-write-size (--align) to 4 (per flash_area_align()) in wrapper.py command line
    https://docs.mcuboot.com/design.html#image-trailer

Related issue:
ARMmbed#15417
multiplemonomials added a commit to mbed-ce/mbed-os that referenced this issue Sep 25, 2023
* Fix null pointer dereferencing

Add null check for return values of functions that are mostly (but not
always) checked for null.
E.g., since 98% of calls to protocol_stack_interface_info_get_by_id
check for null, it is likely that the function can return null values in
some cases, and omitting the check could crash the program.

* Update MAX32660 peripheral drivers with final ones that use by SDK

* Apply MAX32660 delta
Update mbed hal function as per of SDK update

Signed-off-by: Sadik.Ozer <[email protected]>

* M2354: Fix debug failure in Mbed Studio

In Mbed Studio, debugging, based on pyOCD, requires Mbed OS application code starting on the sector boundary.

Modification list:
1.  Update TF-M import assets with MCUboot header padding to sector aligned
2.  Following above, change header size argument (-H) in wrapper.py command line
3.  Following below, fix min-write-size (--align) to 4 (per flash_area_align()) in wrapper.py command line
    https://docs.mcuboot.com/design.html#image-trailer

Related issue:
ARMmbed#15417

* Do not clear interrupt flag during initialization
This causes issue for repeaded initialization while using BufferedSerial mode

Signed-off-by: Sadik.Ozer <[email protected]>

* MAX32660, MAX32670 UART performance improvement

Signed-off-by: Sadik.Ozer <[email protected]>

* Handle negative values passed to close()

Calling close() with negative numbers causes out-of-bounds indexing of the filehandles array. For example, this can happen if open() returns an error and the value is later passed to close().

* Moved a { to the same line as if

Moved a { to the same line as if

* add nullpointer check in LWIP::socket_close

* Fix crash when using FDCAN3 RX IRQ on STM32G473 (and others)

* connectivity: drivers: Update Nuvoton M467 EMAC DMA_IE ctl

In IRQ Handler, to disable some interrupt type of DMA error.
It could avoid unexpected repeated interrupt.The masked bit of
DMA_IE could be recovered in next EMAC IRQ event.

Signed-off-by: cyliang tw <[email protected]>

* Add workaround for G474 hardfault

* update drivers STM32WL CUBE V1.3.0

* Changed static to weak

* Fix: Do not disable SPI for manual drive mode during transaction setup
It has been reported that disabling SPI module causes glitch for manual SS drive mode

Signed-off-by: Sadik.Ozer <[email protected]>

* make cellular event queue size configurable

update unit tests

---------

Signed-off-by: Sadik.Ozer <[email protected]>
Signed-off-by: cyliang tw <[email protected]>
Co-authored-by: Mingjie Shen <[email protected]>
Co-authored-by: Ahmet Polat <[email protected]>
Co-authored-by: Sadik.Ozer <[email protected]>
Co-authored-by: Chun-Chieh Li <[email protected]>
Co-authored-by: alrvid <[email protected]>
Co-authored-by: Jost, Chris <[email protected]>
Co-authored-by: Joseph Duchesne <[email protected]>
Co-authored-by: cyliang tw <[email protected]>
Co-authored-by: Maxim Markin <[email protected]>
Co-authored-by: Charles <[email protected]>
Co-authored-by: Lukas Karel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants