This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

on-chip xdata on aduc832

Can anyone please help explaining me why this code won't access the on-chip xdata. When executing the below code nothing happens at all.

#include <ADUC832.H>
#include  <stdio.h>

void main (void)
{
  xdata int m[10];
  int j;
/*-----------------------------------------------
Configure the serial port to run at 9600 Baud.
-----------------------------------------------*/

        PLLCON = 0xF0; // core clock 16.78 MHz
        PCON |= 0x80;    // Set SMOD i.e. double baudrates
        SCON = 0x50;   // SCON: mode 1, 8-bit UART, enable rcvr
        TMOD = 0x20;   // TMOD: timer 1, mode 2, 8-bit reload
        TH1 = -9;            // TH1:  reload value for 9600 baud
        TR1 = 1;       // TR1:  timer 1 run
        TI = 1;

  for(j=0;j<10;j++)
    m[j] = j;

  for(j=0;j<10;j++)
        printf("int m[%i] = %i\n", j, m[j]);

        while(1);
}

In the startup code (START_AD.A51) I did enable xdata access

; XRAMEN     Val  Description
; ------     ---  -----------
XRAMEN EQU 1; 0 = disable on-chip XDATA RAM and access off-chip XDATA space
;           ; 1 = enable on-chip XDATA RAM

If I change to XRAMEN EQU 0 and run the code, the output is ten "-1" on the serial port (this I understand as xdata isn't available)

Parents
  • I mean nothing. No output.
    If I try this code, with a printf statement not using xdata variable:

    #include <ADUC832.H>
    #include  <stdio.h>
    
    void main (void)
    {
      xdata int m[3]= {20,30,40};
      int j;
    /*-----------------------------------------------
    Configure the serial port to run at 9600 Baud.
    -----------------------------------------------*/
    
            PLLCON = 0xF0; // core clock 16.78 MHz
            PCON |= 0x80;    // Set SMOD i.e. double baudrates
            SCON = 0x50;   // SCON: mode 1, 8-bit UART, enable rcvr
            TMOD = 0x20;   // TMOD: timer 1, mode 2, 8-bit reload
            TH1 = -9;            // TH1:  reload value for 9600 baud
            TR1 = 1;       // TR1:  timer 1 run
            TI = 1;
    
      printf("Starting\n");
      for(j=0;j<3;j++)
            printf("int m[%i] = %i\n", j, m[j]);
    
            while(1);
    }
    


    I get no output on the serial port. If I use this START_AD.A51, i.e. XRAMEN = 0:

    XRAMEN EQU 0; 0 = disable on-chip XDATA RAM and access off-chip XDATA space
    ;           ; 1 = enable on-chip XDATA RAM
    ;
    ; Extended Stack Mode (16-bit Stack Pointer)
    ; EXSP       Val  Description
    ; ----       ---  -----------
    EXSP EQU 0  ; 0 = classic 8051 stack pointer (8-bit) addressing IDATA space
    ;           ; 1 = extended 16-bit stack pointer addressing XDATA space
    ; NOTE: The Extended Stack Mode works only with enabled on-chip XDATA RAM!
    ;
    ; CPU Stack Size Definition in Extended Stack Mode:
    ; The following EQU statements defines the stack space available in extended
    ; stack mode (EXSP set to 1) for the application program.  It should be noted
    ; that the stack space must be adjusted according the actual requirements of
    ; the application.  This STARTUP file allocates the stack in extended stack
    ; mode in XDATA memory beginning at XSTACKSTART.  The extended stack must
    ; be within the on-chip XDATA memory and XSTACKSTART must be not less than
    ; 100H.
    ;
    STACKSIZE   EQU 200H             ; set to 200H Bytes.
    XSTACKSTART EQU 800H - STACKSIZE ; 800H is top of on-chip XRAM.
    ;
    ;------------------------------------------------------------------------------
    ;
    ;  User-defined Power-On Initialization of Memory
    ;
    ;  With the following EQU statements the initialization of memory
    ;  at processor reset can be defined:
    ;
    ;               ; the absolute start-address of IDATA memory is always 0
    IDATALEN        EQU     80H     ; the length of IDATA memory in bytes.
    ;
    XDATASTART      EQU     0H      ; the absolute start-address of XDATA memory
    XDATALEN        EQU     0H      ; the length of XDATA memory in bytes.
    ;
    PDATASTART      EQU     0H      ; the absolute start-address of PDATA memory
    PDATALEN        EQU     0H      ; the length of PDATA memory in bytes.
    ;
    ;  Notes:  The IDATA space overlaps physically the DATA and BIT areas of the
    ;          8051 CPU. At minimum the memory space occupied from the C51
    ;          run-time routines must be set to zero.
    ;------------------------------------------------------------------------------
    ;
    ;  Reentrant Stack Initilization
    ;
    ;  The following EQU statements define the stack pointer for reentrant
    ;  functions and initialized it:
    ;
    ;  Stack Space for reentrant functions in the SMALL model.
    IBPSTACK        EQU     0       ; set to 1 if small reentrant is used.
    IBPSTACKTOP     EQU     0FFH+1  ; set top of stack to highest location+1.
    ;
    ;  Stack Space for reentrant functions in the LARGE model.
    XBPSTACK        EQU     0       ; set to 1 if large reentrant is used.
    XBPSTACKTOP     EQU     0FFFFH+1; set top of stack to highest location+1.
    ;
    ;  Stack Space for reentrant functions in the COMPACT model.
    PBPSTACK        EQU     0       ; set to 1 if compact reentrant is used.
    PBPSTACKTOP     EQU     0FFFFH+1; set top of stack to highest location+1.
    ;
    ;------------------------------------------------------------------------------
    ;
    ;  Page Definition for Using the Compact Model with 64 KByte xdata RAM
    ;
    ;  The following EQU statements define the xdata page used for pdata
    ;  variables. The EQU PPAGE must conform with the PPAGE control used
    ;  in the linker invocation.
    ;
    PPAGEENABLE     EQU     1       ; set to 1 if pdata object are used.
    PPAGE           EQU     0       ; define PPAGE number.
    
    etc.
    


    then the output on the serial port is
    .... serial start ............
    Starting
    int m[0] = -1
    int m[1] = -1
    int m[2] = -1
    ...... serial end..............
    Maybe my aduc832 chip has a physical fault, or my computer mess up in some way.
    Is it possible to get a copy of the .hex file you (ninja Z) produced - just to conclude that it is the chip that has failed.

Reply
  • I mean nothing. No output.
    If I try this code, with a printf statement not using xdata variable:

    #include <ADUC832.H>
    #include  <stdio.h>
    
    void main (void)
    {
      xdata int m[3]= {20,30,40};
      int j;
    /*-----------------------------------------------
    Configure the serial port to run at 9600 Baud.
    -----------------------------------------------*/
    
            PLLCON = 0xF0; // core clock 16.78 MHz
            PCON |= 0x80;    // Set SMOD i.e. double baudrates
            SCON = 0x50;   // SCON: mode 1, 8-bit UART, enable rcvr
            TMOD = 0x20;   // TMOD: timer 1, mode 2, 8-bit reload
            TH1 = -9;            // TH1:  reload value for 9600 baud
            TR1 = 1;       // TR1:  timer 1 run
            TI = 1;
    
      printf("Starting\n");
      for(j=0;j<3;j++)
            printf("int m[%i] = %i\n", j, m[j]);
    
            while(1);
    }
    


    I get no output on the serial port. If I use this START_AD.A51, i.e. XRAMEN = 0:

    XRAMEN EQU 0; 0 = disable on-chip XDATA RAM and access off-chip XDATA space
    ;           ; 1 = enable on-chip XDATA RAM
    ;
    ; Extended Stack Mode (16-bit Stack Pointer)
    ; EXSP       Val  Description
    ; ----       ---  -----------
    EXSP EQU 0  ; 0 = classic 8051 stack pointer (8-bit) addressing IDATA space
    ;           ; 1 = extended 16-bit stack pointer addressing XDATA space
    ; NOTE: The Extended Stack Mode works only with enabled on-chip XDATA RAM!
    ;
    ; CPU Stack Size Definition in Extended Stack Mode:
    ; The following EQU statements defines the stack space available in extended
    ; stack mode (EXSP set to 1) for the application program.  It should be noted
    ; that the stack space must be adjusted according the actual requirements of
    ; the application.  This STARTUP file allocates the stack in extended stack
    ; mode in XDATA memory beginning at XSTACKSTART.  The extended stack must
    ; be within the on-chip XDATA memory and XSTACKSTART must be not less than
    ; 100H.
    ;
    STACKSIZE   EQU 200H             ; set to 200H Bytes.
    XSTACKSTART EQU 800H - STACKSIZE ; 800H is top of on-chip XRAM.
    ;
    ;------------------------------------------------------------------------------
    ;
    ;  User-defined Power-On Initialization of Memory
    ;
    ;  With the following EQU statements the initialization of memory
    ;  at processor reset can be defined:
    ;
    ;               ; the absolute start-address of IDATA memory is always 0
    IDATALEN        EQU     80H     ; the length of IDATA memory in bytes.
    ;
    XDATASTART      EQU     0H      ; the absolute start-address of XDATA memory
    XDATALEN        EQU     0H      ; the length of XDATA memory in bytes.
    ;
    PDATASTART      EQU     0H      ; the absolute start-address of PDATA memory
    PDATALEN        EQU     0H      ; the length of PDATA memory in bytes.
    ;
    ;  Notes:  The IDATA space overlaps physically the DATA and BIT areas of the
    ;          8051 CPU. At minimum the memory space occupied from the C51
    ;          run-time routines must be set to zero.
    ;------------------------------------------------------------------------------
    ;
    ;  Reentrant Stack Initilization
    ;
    ;  The following EQU statements define the stack pointer for reentrant
    ;  functions and initialized it:
    ;
    ;  Stack Space for reentrant functions in the SMALL model.
    IBPSTACK        EQU     0       ; set to 1 if small reentrant is used.
    IBPSTACKTOP     EQU     0FFH+1  ; set top of stack to highest location+1.
    ;
    ;  Stack Space for reentrant functions in the LARGE model.
    XBPSTACK        EQU     0       ; set to 1 if large reentrant is used.
    XBPSTACKTOP     EQU     0FFFFH+1; set top of stack to highest location+1.
    ;
    ;  Stack Space for reentrant functions in the COMPACT model.
    PBPSTACK        EQU     0       ; set to 1 if compact reentrant is used.
    PBPSTACKTOP     EQU     0FFFFH+1; set top of stack to highest location+1.
    ;
    ;------------------------------------------------------------------------------
    ;
    ;  Page Definition for Using the Compact Model with 64 KByte xdata RAM
    ;
    ;  The following EQU statements define the xdata page used for pdata
    ;  variables. The EQU PPAGE must conform with the PPAGE control used
    ;  in the linker invocation.
    ;
    PPAGEENABLE     EQU     1       ; set to 1 if pdata object are used.
    PPAGE           EQU     0       ; define PPAGE number.
    
    etc.
    


    then the output on the serial port is
    .... serial start ............
    Starting
    int m[0] = -1
    int m[1] = -1
    int m[2] = -1
    ...... serial end..............
    Maybe my aduc832 chip has a physical fault, or my computer mess up in some way.
    Is it possible to get a copy of the .hex file you (ninja Z) produced - just to conclude that it is the chip that has failed.

Children
  • Sorry,I just simulate your code in Keil Debugger!

  • Oh I see, if I use the debugger I also get correct results. The debugger apperently assumes that off-chip XRAM is available and disregards the XRAMEN setting in the startup code.
    I have tested the code from my previous post on a second (and brand new) aduc832 board just to obtain the same result - no output on the serial port at all when using XRAMEN EQU 1.
    If I simplify my code even further to e.g.:

    #include <ADUC832.H>
    
    sbit LED = P2^0;
    void main (void)
    {
     unsigned int j;
    
     while(1) {
       LED = !LED;
       for(j=1;j>0;j++)
       {};
     }
    }
    


    Then still nothing happens when using XRAMEN EQU 1 - the LED connected to pin P2.0 remains in the same state

    However, if I exclude the STARTUP_AD.A51 from the project and do it in the following way, then the aduc832 board do as I expect it to.

    #include <ADUC832.H>
    #include  <stdio.h>
    
    #define MAX 1024
    
    sbit LED = P2^0;
    void main (void)
    {
     xdata int m[MAX];  // On-chip xram array
     unsigned int j;
    CFG831 |= 0x01;     // enable on-chip xram by setting XRAMEN
                        // in SFR ... funny name 'CFG831', why isn't
                        // named 'CFG832'
    
    /*-----------------------------------------------
    Configure the serial port to run at 9600 Baud.
    -----------------------------------------------*/
    
           PLLCON = 0xF0; // core clock 16.78 MHz
           PCON |= 0x80;    // Set SMOD i.e. double baudrates
           SCON = 0x50;   // SCON: mode 1, 8-bit UART, enable rcvr
           TMOD = 0x20;   // TMOD: timer 1, mode 2, 8-bit reload
           TH1 = -9;            // TH1:  reload value for 9600 baud
           TR1 = 1;       // TR1:  timer 1 run
           TI = 1;
    
     printf("Starting\n");
     for(j=0;j<MAX;j++) {
       m[j] = j;
           printf("int m[%i] = %i\n", j, m[j]);
     }
    
           while(1) {
       LED = !LED;
       for(j=1;j>0;j++)
       {};
     }
    }