5 Replies Latest reply on Feb 8, 2019 4:07 PM by ilg

    OpenOCD help with Semihosting

    unknowncoder

      Hello,

       

      I am trying to setup a semihosting project using OpenOCD. I have partial semihosting feature working but not all.

       

      What I need Working

      • To pass arguments to main() via standard argument list using semihosting
        • I have tired passing these argument via "arm semihosting_cmdline".
          • I have tired this both from openOCD script file and OpenOCD plug for eclipse. Neither work

       

      What I have work

      • Standard IO like printf/scanf
      • File IO like read/write/opening/close

       

      Environment

      • OpenOCD
        • 0.10.0+dev-00463-g436782ba9 (2019-02-08-15:03)
      • Ubuntu 18
      • Eclipse Oxygen
        • CDT Plugin
        • OpenOCD Plugin
      • GNU toolchain
        • 7-2017-q4-major
      • MCU
        • STM32F1
        • STM32F0

       

      Any help is greatly appreciated

      Thanks

        • Re: OpenOCD help with Semihosting
          ilg

          prefix the command with 'monitor', like:

           

          monitor arm semihosting enable
          monitor arm semihosting_cmdline name 4 3 2
            • Re: OpenOCD help with Semihosting
              unknowncoder

              Hello,

               

              I have tired this but it doesn't work. As you can see from the OpenOCD command output the argument count is "ARGC: 536870912", it should be 4.

               

              GDB Commands

              (gdb) target remote :3333
              Remote debugging using :3333
              0x00000000 in ?? ()
              (gdb) monitor arm semihosting enable
              semihosting is enabled
              (gdb) monitor arm semihosting_cmdline name 4 3 2
              semihosting command line is [name 4 3 2]
              (gdb) load
              Loading section .isr_vector, size 0x1e4 lma 0x8005000
              Loading section .text, size 0xba98 lma 0x80051e4
              Loading section .rodata, size 0x468 lma 0x8010c7c
              Loading section .init_array, size 0x4 lma 0x80110e4
              Loading section .fini_array, size 0x4 lma 0x80110e8
              Loading section .data, size 0xb8 lma 0x80110ec
              Start address 0x8009d64, load size 49572
              Transfer rate: 19 KB/sec, 6196 bytes/write.
              (gdb) continue
              Continuing.

               

              OpenOCD Output

              | openocd -f CN_Debug.cfg 
              Open On-Chip Debugger 0.10.0+dev-00463-g436782ba9 (2019-02-08-15:03)
              Licensed under GNU GPL v2
              For bug reports, read
              http://openocd.org/doc/doxygen/bugs.html
              srst_only separate srst_nogate srst_open_drain connect_assert_srst
              Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
              adapter speed: 1000 kHz
              adapter_nsrst_delay: 100
              srst_only separate srst_nogate srst_open_drain connect_assert_srst
              Info : Listening on port 6666 for tcl connections
              Info : Listening on port 4444 for telnet connections
              Info : clock speed 1000 kHz
              Info : STLINK V2J32S0 (API v2) VID:PID 0483:3748
              Info : Target voltage: 2.955277
              Info : STM32F107VCTx.cpu: hardware has 6 breakpoints, 4 watchpoints
              Info : Listening on port 3333 for gdb connections
              Info : accepting 'gdb' connection on tcp/3333
              Info : Halt timed out, wake up GDB.
              Error: timed out while waiting for target halted
              
              
              
              
              Info : device id = 0x10016418
              Warn : STM32 flash size failed, probe inaccurate - assuming 256k flash
              Info : flash size = 256kbytes
              Warn : negative reply, retrying
              Warn : negative reply, retrying
              semihosting is enabled
              semihosting command line is [name 4 3 2]
              target halted due to debug-request, current mode: Thread 
              xPSR: 0x01000000 pc: 0x080027fc msp: 0x20010000, semihosting
              target halted due to breakpoint, current mode: Thread 
              xPSR: 0x61000000 pc: 0x2000003a msp: 0x20010000, semihosting
              target halted due to debug-request, current mode: Thread 
              xPSR: 0x01000000 pc: 0x080027fc msp: 0x20010000, semihosting
              ARGC: 536870912
              buf: fopen example

               

              Code

                   MEMMAP_Paint_Stack();
                  HAL_Init();
                  SystemClock_Config();
              
              
                  extern void initialise_monitor_handles(void);
              
              
                  initialise_monitor_handles();
                  printf("ARGC: %d\n", argc);