+ Post New Thread
Results 1 to 2 of 2
  1. #1
    Full Member level 2
    Points: 2,926, Level: 12
    umairsiddiqui's Avatar
    Join Date
    Apr 2004
    Location
    Sweden
    Posts
    144
    Helped
    7 / 7
    Points
    2,926
    Level
    12

    arm cortex m0 and STDIO mapping in ARM Debugger

    Hi,

    I want to simulate the following Code for Cortex M0 design-start core in RVDS. In this code the fputc and printf are overridden, so instead of using UART in Cortex M0, fputc will write at memory location

    0x40000000U

    typically when you simulate the design, printf output is displayed in STDIO window in ARM debugger. But in this case no output is shown in STDIO
    window.

    I can see CPU is overwriting the memory loc (0x40000000U), but i want to
    capture the complete output. Please tell me how to configure the debugger
    so that every write at that particular memory location is appended in STDIO window...



    Code:
    //------------------------------------------------------------------------------
    // Cortex-M0 DesignStart C program example
    //------------------------------------------------------------------------------
    
    //------------------------------------------------------------------------------
    // Include standard C library and RealView Compiler header.
    //------------------------------------------------------------------------------
    
    #include <stdio.h>
    #include <time.h>
    #include <rt_misc.h>
    
    //------------------------------------------------------------------------------
    // The following code implements all the functions required for semihosting
    // using the Cortex-M0 DesignStart testbench, mapping output from C to the
    // console output of the testbench.
    //------------------------------------------------------------------------------
    
    // Disable the inclusion of semihosting support; see the "ARM Compiler
    // toolchain Using ARM C and C++ Libraries and Floating-Point Support"
    // (ARM DUI 0475) for further details.
    #pragma import(__use_no_semihosting)
    
    // Define where the top of memory is.
    #define TOP_OF_RAM 0x20000U
    
    //------------------------------------------------------------------------------
    // Define location of C stack and heap
    //------------------------------------------------------------------------------
    
    // Initialize stack and heap to span from the end of the zero-initialized
    // region to the value defined by TOP_OF_RAM; see the "ARM Compiler toolchain
    // Linker Reference" (ARM DUI 0493) and the "ARM Compiler toolchain Using ARM
    // C and C++ Libraries and Floating-Point Support" (ARM DUI 0475) for further
    // details.
    
    extern unsigned int Image$$ZI$$Limit;
    
    struct __initial_stackheap
    __user_initial_stackheap
    (unsigned int r0,
     unsigned int r1,
     unsigned int r2,
     unsigned int r3)__value_in_regs
    {
      struct __initial_stackheap sh;
    
      sh.heap_base   = Image$$ZI$$Limit;
      sh.stack_base  = TOP_OF_RAM;
      sh.heap_limit  = sh.stack_base;
      sh.stack_limit = sh.heap_base;
    
      return sh;
    }
    
    //------------------------------------------------------------------------------
    // Implement the minimum number of functions required to support
    // standard C input/output operations without a debugger attached.
    //------------------------------------------------------------------------------
    
    // Define the location of the output console in the DesignStart testbench.
    volatile unsigned char *console = (volatile unsigned char *) 0x40000000U;
    
    // Implement a simple structure for C's FILE handle.
    struct __FILE { int handle; };
    FILE __stdout;
    FILE __stdin;
    
    // Implement file IO handling, only console output is supported.
    time_t time(time_t* t)        { static time_t clock = 0; return clock++; }
    int fputc(int ch, FILE *f)    { *console = ch; return ch; }
    int ferror(FILE *f)           { return 0; }
    int fgetc(FILE *f)            { return -1; }
    int __backspace(FILE *stream) { return 0; }
    void _ttywrch(int ch)         { fputc(ch,&__stdout); }
    
    // Writing 0x4 to the console causes the DesignStart testbench to finish.
    void _sys_exit(void)          { fputc(0x04,&__stdout); while(1); }
    
    //------------------------------------------------------------------------------
    // Implement the vector table in its own area to facilitate linking first
    //------------------------------------------------------------------------------
    
    extern void __main(void);     // Use C-library initialization function.
    
    __attribute__ ((section("vectors")))
      static void (* const vector_table[])(void) =
    {
      (void (*)(void)) TOP_OF_RAM, // Initial value for stack pointer.
      __main,                      // Reset handler is C initialization.
      0,                           // No HardFault handler, just cause lockup.
      0,                           // No NMI handler, just cause lockup.
      0//...                       // Additional handlers would be listed here.
    };
    
    //------------------------------------------------------------------------------
    // Simple "Hello World" program.
    //------------------------------------------------------------------------------
    
    int main(void) {
      printf("Hello World!\n");
    
      printf("This message was printed from helloworld.c provided\n");
      printf("with the ARM Cortex-M0 DesignStart processor\n");
    
      return 0;
    }
    regards

    •   Alt31st March 2011, 15:22

      advertising

        
       

  2. #2
    Newbie level 1
    Points: 179, Level: 2

    Join Date
    Dec 2011
    Posts
    1
    Helped
    0 / 0
    Points
    179
    Level
    2

    Re: arm cortex m0 and STDIO mapping in ARM Debugger

    Then how about semihosting?

    I use nuvoton Cortex-M0. It's easy to output debug message to Keil/IAR ide via semihosting,
    which need not a real UART at all.

    Steps:
    1. Get a M0 dev board (NUC100, M052 or Mini51) and Nu-Link debugger
    2. Install Nu-Link driver for Keil or IAR
    Mini51 series development resource (Dec, 06, 2011) - Cortex M0 forum -
    3. Compile code with semihosting
    In file startup_Mini51.s
    SEMIHOSTED SETL {TRUE}
    In file system_NUC1xx
    #define DEBUG_ENABLE_SEMIHOST

    And then, printf will output message to IDE window.
    Keil->View->Serial Window->UART1
    IAR->Terminal IO



--[[ ]]--