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

Error: Failed to access data for an ELF segment??? #77

Closed
Rockwell1799 opened this issue Nov 14, 2024 · 10 comments
Closed

Error: Failed to access data for an ELF segment??? #77

Rockwell1799 opened this issue Nov 14, 2024 · 10 comments

Comments

@Rockwell1799
Copy link

Rockwell1799 commented Nov 14, 2024

Hello
I have an issue with the following code:

#include <config.h>                               // user configurations
#include <system.h>                               // system functions
#include <gpio.h>                                 // GPIO functions
#include <debug_serial.h>                          // serial debug functions
volatile uint32_t count;
// ===================================================================================
// Main Function
// ===================================================================================
int main(void) {
  // Setup
  PIN_output(PIN_LED);                            // set LED pin to output

  // Loop
  while(1) {
    PIN_toggle(PIN_LED);                            // toggle LED
    DLY_ms(1000);                                  // wait a bit
    DEBUG_newline();
    DEBUG_printD(count++);                         // send string
  }
}

The code does compile, but I get the error: Failed to access data for an ELF segment.
When I remove the last 2 lines, the code uploads without any issue.
Does someone have an idea why I'm getting this error?
TIA
Code_aFmWRBOoyT

@maxgerhardt
Copy link
Member

maxgerhardt commented Nov 14, 2024

Can you flash with upload_protocol = wch-link fine? What about upload_protocol = minichlink?

@Rockwell1799
Copy link
Author

I can't use minichlink,because I'm not using the winusb driver.

@maxgerhardt
Copy link
Member

Okay, then upload_protocol = wch-link should work if you use the WCH driver.

Can you upload the exact project files? It seems to be https://github.com/wagiminator/Development-Boards/blob/main/CH32X033F8P6_DevBoard/software/debug_serial but with some modifications.

@Rockwell1799
Copy link
Author

Rockwell1799 commented Nov 14, 2024

With wch-link, it uploads the code, but the LED is not blinking anymore!
Code_65tUdmfQ8W

blink.zip
I've attached the project files as zip below.

@maxgerhardt
Copy link
Member

maxgerhardt commented Nov 14, 2024

Look in the debugger. You're hanging up in the DEBUG_write() function which waits for the character to be written (Transmit Empty), but that can never happen because your main() function never initializes the UART by calling into DEBUG_init().

grafik

A main function of

int main(void) {
  // Setup
  PIN_output(PIN_LED);                            // set LED pin to output
  DEBUG_init();
  
  // Loop
  while(1) {
    PIN_toggle(PIN_LED);                            // toggle LED
    DLY_ms(1000);                                  // wait a bit
    DEBUG_newline();
    DEBUG_printD(count++);                         // send string
  }
}

gets the LED blinking again.

@maxgerhardt
Copy link
Member

Thanks to your project, I can reproduce the error

22:30:04 [INFO] Connected to WCH-Link v2.14(v34) (WCH-LinkE-CH32V305)
22:30:04 [INFO] Attached chip: CH32X035 [CH32X035F8U6] (ChipID: 0x035e0601)
22:30:04 [INFO] Chip ESIG: FlashSize(62KB) UID(cd-ab-28-c5-49-bc-3e-2d)
22:30:04 Error: Failed to access data for an ELF segment.
[INFO] Flash protected: false
22:30:04 [INFO] Read .pio\build\CH32X035\firmware.elf as ELF format
*** [upload] Error 1

and will look into it. Maybe we need a wlink.exe update, or a bug should be opened there.

@maxgerhardt
Copy link
Member

maxgerhardt commented Nov 14, 2024

This error is reproducable in the latest version of wlink and now tracked in ch32-rs/wlink#77.

Please use upload_protocol = wch-link since it works fine.

You can also debug with it. Just open the debug sidepanel and click on the green Play button next to "PIO Debug". You can even view all perpiheral registers.

grafik

@maxgerhardt
Copy link
Member

Will update the PlatformIO binaries for wlink once ch32-rs/wlink#79 is released.

@maxgerhardt
Copy link
Member

The updated binaries have been submitted to registry as tool-wlink and are awaiting approval by the PlatformIO team.

The package has been accepted for moderation. We will notify you on email when process it.

@maxgerhardt
Copy link
Member

maxgerhardt commented Nov 16, 2024

All binaries were actually updated in https://github.com/Community-PIO-CH32V/tool-wlink/ (PIO registry unused for that package), so it should all work right now.

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

2 participants