CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

problem of main application jump with bootload function

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
joe2008



Joined: 19 Aug 2008
Posts: 6

View user's profile Send private message

problem of main application jump with bootload function
PostPosted: Sun Nov 23, 2008 10:05 pm     Reply with quote

Devcie:16F886
MPLAB:V8.10
CCS C complier: V4.049
Bootload area:0x0000-0x2FF.
configure:#fuses HS,NOPUT,BROWNOUT,NOLVP,NOCPD,NOPROTECT,NOWDT

My project includes two C source files.

One is bootload.C

Code:
#define CONST_USER_CODE_START_INTR_ADDR 0x300     //user code area start - interrupt vector
#define CONST_USER_CODE_JUMP_ADDR       0x1200      //user code jump vector - allow max intr context save code
#build ( reset = CONST_USER_CODE_JUMP_ADDR, interrupt = CONST_USER_CODE_START_INTR_ADDR )
//#org CONST_RESET_VECTOR_START_ADDR,CONST_BTLDR_MAIN_END_ADDR {}
//================================================================== (Bootloader Embedded - ROM Implementation)
#rom   0x0000   =   {   0x3000,   0x008A,   0x2821,   0x0000,   0x00FF,   0x0E03,   0x0183,   0x00A1   }
#rom   0x0008   =   {   0x080A,   0x00A0,   0x018A,   0x3003,   0x008A,   0x2B00,   0x0009,   0x3FFF   }
#rom   0x0010   =   {   0x0041,   0x0041,   0x0032,   0x0035,   0x0034,   0x0032,   0x0030,   0x004C   }
........
#rom   0x02F8   =   {   0x3FFF,   0x3FFF,   0x3FFF,   0x3FFF,   0x3FFF,   0x3FFF,   0x3FFF,   0x3FFF   }

//==============================================================================
#endif


Another is main.C, including bootload.C and other header file.
Code:

void main()
   {
   sys_init();                  // Configure I/O ports, peripherals, interrupts, timers & buffers.
     
   epow_on = 1;
   inrush_en = 1;

   while(1)
   {
                main application();
               }
}



The problem is:
If application is not so large, the main application vector jump is correct.
Pls refer to below disassembly listing.

1200 3000 MOVLW 0
1201 008A MOVWF 0xa
1202 2EB7 GOTO 0x6b7
1203 0000 NOP

108: void main()
109: {
06B7 0184 CLRF 0x4
06B8 1383 BCF 0x3, 0x7
06B9 301F MOVLW 0x1f
06BA 0583 ANDWF 0x3, F
06BB 1683 BSF 0x3, 0x5
...
}

But if the application code is more larger, the main application vector
jump will be not correct. Pls refer to below disassembly listing.

1200 3000 MOVLW 0
1201 008A MOVWF 0xa
1202 2800 GOTO 0
1203 0000 NOP

108: void main()
109: {
0800 0184 CLRF 0x4
0801 1383 BCF 0x3, 0x7
0802 301F MOVLW 0x1f
0803 0583 ANDWF 0x3, F
0804 1683 BSF 0x3, 0x5
0805 1703 BSF 0x3, 0x6
...
}
Build result: Memory usage: ROM=26% RAM=38% - 42%
0 Errors, 12 Warnings.



I have bootloaded PIC18F4520 successfully with same method before, the application is more complex than this, and main application can jump correctly and runs no problem. Why is main application jump not correct with larger main application for PIC16886 ?
Ttelmah
Guest







PostPosted: Mon Nov 24, 2008 4:33 am     Reply with quote

It is very difficult to understand what you are doing from your description. You don't normally include the bootloader, in your application, which is what you seem to be showing.
However the obvious 'guess', is that on your larger version, the interrupt handler code, which you are writing at address 300, has got larger than 3840 bytes, meaning it no longer fits in the area you are allocating for it.
Normally, I'd suggest providing the 'default' layout for the interrupt handler, by placing its's code eight addresses above the main start location. This then allows the compiler to decide how much space it needs, and vector the initialisation jump to this.

Best Wishes
joe2008



Joined: 19 Aug 2008
Posts: 6

View user's profile Send private message

PostPosted: Mon Nov 24, 2008 9:11 am     Reply with quote

Ttelmah,

Firstly thanks your reply.

The part from #rom 0x0000 to 0x02FF are my bootloader. I has built my bootloader into hex file and don't list them out completely.
My interrupt handler is very simple, and don't occupy so much program memory.
I have noticed that if the size of my application is larger than 0x0800, it will jump error. If the size of my application code is not larger than 0x0800, it will jump correctly. I have checked the spec of PIC16F886,and find that one page of program memory is 0x0800. But I don't find what's relationship between them.
Anyway I'll try according to what you said.
Ttelmah
Guest







PostPosted: Mon Nov 24, 2008 10:08 am     Reply with quote

What I don't understand, is why the bootloader is present at all. The main application code, should not have any reference to the bootloader at all, except in it's relocated start address. You are showing the code, as if you are including the bootloader file in the final application.

Now, the obvious question, is what do you mean by your 'application'. Are you actually refering to the 'main'. If so, you may well need to be using more routines, to split this up. Basically, on the 16 chips, you are dealing with paged memory, and the compiler needs to be dealing with multiple small sections of code, which it can re-order to make things fit. Normally it'll complain if it can't fit things (giving an 'out of ROM' error, despite there being plenty of actual space still available). A search here wll find lots of threads about how to split up your code to avoid this. What I think is happening, is that you slightly 'odd' jump vector layout, is preventing the compiler from giving this error message, despite actually hitting this problem. On the 16 chips the normal location for the interrupt vector would be 4 locations above the boot entry point - 8 for 18 chips.

Best Wishes
joe2008



Joined: 19 Aug 2008
Posts: 6

View user's profile Send private message

PostPosted: Mon Nov 24, 2008 9:05 pm     Reply with quote

Sorry, I think I need give more details about the problem and program.

Now I updated I2C_Bootloader_PIC16F886_Library_2.01.c as below:

Code:
#define CONST_USER_CODE_START_INTR_ADDR 0x304     //user code area start - interrupt vector
#define CONST_USER_CODE_JUMP_ADDR       0x300     //user code jump vector - allow max intr context save code
#build ( reset = CONST_USER_CODE_JUMP_ADDR, interrupt = CONST_USER_CODE_START_INTR_ADDR )
//================================================================== (Bootloader Embedded - ROM Implementation)
#rom   0x0000   =   {   0x3000,   0x008A,   0x2821,   0x0000,   0x00FF,   0x0E03,   0x0183,   0x00A1   }
#rom   0x0008   =   {   0x080A,   0x00A0,   0x018A,   0x3003,   0x008A,   0x2B00,   0x0009,   0x3FFF   }
#rom   0x0010   =   {   0x0041,   0x0041,   0x0032,   0x0035,   0x0034,   0x0032,   0x0030,   0x004C   }
#rom   0x0018   =   {   0x0000,   0x3FFF,   0x3FFF,   0x3FFF,   0x3FFF,   0x3FFF,   0x3FFF,   0x3FFF   }
#rom   0x0020   =   {   0x3FFF,   0x0184,   0x1383,   0x301F,   0x0583,   0x1683,   0x1703,   0x1587   }
#rom   0x0028   =   {   0x3008,   0x1303,   0x0099,   0x3002,   0x009A,   0x30A6,   0x0098,   0x3090   }
#rom   0x0030   =   {   0x1283,   0x0098,   0x1683,   0x1703,   0x0809,   0x39C0,   0x0089,   0x1303   }
....
#rom   0x02F8   =   {   0x3FFF,   0x3FFF,   0x3FFF,   0x3FFF,   0x3FFF,   0x3FFF,   0x3FFF,   0x3FFF   }



Main.C as below:
Code:

#include "I2C_Bootloader_PIC16F886_Library_2.01.c"
#include <16F886REG.h>
#include <Software_UART.h>
#include <MASTER_ADM_I2C_MODULE.h>
#include <MATH.h>
// =======================================================================
// =======================================================================
void main()
{
   sys_init();                  // Configure I/O ports, peripherals, interrupts, timers & buffers.
     
   epow_on = 1;
   inrush_en = 1;

   while(1)
   {
        restart_wdt();                // Restart watchdog timer.
   acquire_adc();   // ADC procedures.
                          
   detect_epow();      // Early Power Off
                inrush_control();
                PWM_CONTROL();
       
                temp_monitor();   // Monitor PFC Temp
               
               refresh_bulkok();  // PFC Bulk Control
                fnUART_EVENTS();
              }
}


The procedure of my program will be:
First run into initial start address(0x0000), and jump to 0x300 if don't meet bootload mode. Then jump to start address of "main" of main.C and run application code.

Now I build the project file and don't show any errors:
Code:
  Memory usage:   ROM=26%      RAM=38% - 42%
      0 Errors,  12 Warnings.
BUILD SUCCEEDED: Tue Nov 25 10:38:10 2008


Then I pursue the procedure by watching disassembly listing.
Code:
  [color=red]0300[/color]  3008     MOVLW 0x8
  0301    008A     MOVWF 0xa
  0302    2800     [color=red]GOTO 0[/color]
  0303    0000     NOP
  0304    00FF     MOVWF 0x7f
  0305    0E03     SWAPF 0x3, W
  0306    0183     CLRF 0x3
  0307    00A1     MOVWF 0x21

....
032B 0E21 SWAPF 0x21, W
032C 0083 MOVWF 0x3
032D 0EFF SWAPF 0x7f, F
032E 0E7F SWAPF 0x7f, W
032F 0009 RETFIE
0330 118A BCF 0xa, 0x3
0331 120A BCF 0xa, 0x4
0332 2B33 GOTO 0x333[/code]

Code:
107:               void main()
108:                  {
  [color=red]0800 [/color]   0184     CLRF 0x4
  0801    1383     BCF 0x3, 0x7
  0802    301F     MOVLW 0x1f
  0803    0583     ANDWF 0x3, F
  0804    1683     BSF 0x3, 0x5
....
                            }



Code:
823:               #INT_EXT
824:               void service_RB0(void)
825:               {
826:                      INTCON_INTF=0; //must cleared in software
  0333    108B     BCF 0xb, 0x1
827:                       PWM_wait_cntr++; //For PWM control delay
  0334    0ABE     INCF 0x3e, F
828:                       // get sum of AC input voltage, put into i8_acv7
829:                     i8_acv7    = i8_acv2;   // Save the ave value, for the last 10ms
  0335    0838     MOVF 0x38, W
  0336    00BC     MOVWF 0x3c
  0337    0837     MOVF 0x37, W


My problem is it seems don't jump to 0x800 which "main" start when jump out bootload mode, while not any build error.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group