Hello,
I'm working with a MK64FN1M0VLL12 in Kinetis Design Studio 3.2.0, I have a const buffer of 64 bytes allocated at 0x000F F000 and a RAM buffer of 64 bytes allocated at 0x2000 0000.
I've tried to follow "Relocating Code and Data Using the KDS GCC Linker File for Kinetis".
I can compile without errors but I cannot debug because I get the error "CMSIS-DAP: Write Error (0x04)" after "writing buffer of 64 byte at 0x000ff000".
But if I don't force the location of one of the two buffers, so the const buffer goes in the m_text section, or the RAM buffer goes in the m_data section, it works.
Do you know what it is wrong with this relocation?
Thank you,
Gabriele
This is the code:
#include "board.h" #include "pin_mux.h" #include "clock_config.h" __attribute__ ((section(".xxx"))) uint8_t ucHeap[64]; __attribute__ ((section(".params"))) const uint8_t pars[64]; int main(void) { BOARD_InitPins(); BOARD_BootClockRUN(); memset(ucHeap, 0xEE, sizeof(ucHeap)); memcpy(ucHeap, pars, sizeof(pars)); for (;;) __asm("NOP"); }
These are the changes done on the linker file:
MEMORY { m_interrupts (RX) : ORIGIN = 0x00000000, LENGTH = 0x00000400 m_flash_config (RX) : ORIGIN = 0x00000400, LENGTH = 0x00000010 m_text (RX) : ORIGIN = 0x00000410, LENGTH = 0x000FEBF0 m_params (RW) : ORIGIN = 0x000FF000, LENGTH = 0x00000100 m_data (RW) : ORIGIN = 0x1FFF0000, LENGTH = 0x00010000 m_data_2 (RW) : ORIGIN = 0x20000000, LENGTH = 0x00030000 } ... (after .text) .params_section : { . = ALIGN(4); KEEP (*(.params)) . = ALIGN(4); } > m_params ... (after .bss) .xxx_section : { *(.xxx) } > m_data_2
And this is the error:
Debug: 457 821 gdb_server.c:2647 gdb_input_inner(): received packet: 'Xff000,40:<binary-data>'
Debug: 458 821 gdb_server.c:1495 gdb_write_memory_binary_packet(): addr: 0x000ff000, len: 0x00000040
Debug: 459 821 target.c:1849 target_write_buffer(): writing buffer of 64 byte at 0x000ff000
Error: 460 832 cmsis_dap_usb.c:489 cmsis_dap_swd_write_reg(): CMSIS-DAP: Write Error (0x04)
Error: 461 836 arm_adi_v5.c:363 mem_ap_write(): Failed to write memory at 0x000ff004
Debug: 462 836 gdb_server.c:2647 gdb_input_inner(): received packet: 'X20000000,40:<binary-data>'
Debug: 463 836 gdb_server.c:1320 gdb_error(): Reporting -4 to GDB as generic error
Debug: 464 836 gdb_server.c:1495 gdb_write_memory_binary_packet(): addr: 0x20000000, len: 0x00000040
Debug: 465 836 target.c:1849 target_write_buffer(): writing buffer of 64 byte at 0x20000000
Debug: 466 871 gdb_server.c:2649 gdb_input_inner(): received packet: 'qL1200000000000000000'
Debug: 467 871 gdb_server.c:2649 gdb_input_inner(): received packet: 'm4d8,4'
Debug: 468 872 gdb_server.c:1363 gdb_read_memory_packet(): addr: 0x000004d8, len: 0x00000004
Debug: 469 872 target.c:1910 target_read_buffer(): reading buffer of 4 byte at 0x000004d8
Debug: 470 878 gdb_server.c:2649 gdb_input_inner(): received packet: 'D'
Debug: 471 878 target.c:1395 target_call_event_callbacks(): target event 24 (gdb-detach)
Debug: 472 878 gdb_server.c:1002 gdb_connection_closed(): GDB Close, Target: kinetis.cpu, state: halted, gdb_actual_connections=0
Debug: 473 878 target.c:1395 target_call_event_callbacks(): target event 6 (gdb-end)
Debug: 474 878 target.c:1395 target_call_event_callbacks(): target event 24 (gdb-detach)
Info : 475 878 server.c:476 server_loop(): dropped 'gdb' connection
And the GDB trace:
924,536 &"load F:\\\\PROGETTI\\\\Workspace\\\\test_ram\\\\Debug\\\\test_ram.elf\n"
924,537 ~"Loading section .params_section, size 0x40 lma 0xff000\n"
924,537 25+download,{section=".params_section",section-size="64",total-size="663166"}
924,537 25+download,{section=".params_section",section-sent="64",section-size="64",total-sent="64",t\
otal-size="663166"}
924,537 ~"Loading section .xxx_section, size 0x40 lma 0x20000000\n"
924,552 &"Load failed\n"
924,552 25^error,msg="Load failed"
924,553 (gdb)
924,554 27-gdb-exit
924,593 26^done,threads=[{id="1",target-id="Remote target",frame={level="0",addr="0x000004d8",func="\
Reset_Handler",args=[],file="../startup/startup_MK64F12.S",fullname="F:\\PROGETTI\\Workspace\\test_r\
am\\startup\\startup_MK64F12.S",line="326"},state="stopped"}]
924,593 (gdb)
924,594 27^exit
924,594 =thread-group-exited,id="i1"
As described here, it is possible that the kinetis driver of OpenOCD is not able to automatically recognizes the second flash bank. By manually configuring both the banks of the MK64FN1M0VLL12 I was able to solve the problem.
A clumsy workaround is to define the RAM buffer as 'extern' and then define its address in the SECTIONS of the linker file:
ucHeap = 0x20000000;
It is necessary to manually allocate the buffer by moving the start of m_data_2 in the MEMORY section:
m_data_2 (RW) : ORIGIN = 0x20000100, LENGTH = 0x0002FF00