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 support@ccsinfo.com

Bootloader Pic18f2550 r232 with ccs c compiler and tera term
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
robertom



Joined: 15 Mar 2016
Posts: 12

View user's profile Send private message AIM Address

Bootloader Pic18f2550 r232 with ccs c compiler and tera term
PostPosted: Tue Mar 15, 2016 2:27 pm     Reply with quote

Hello everyone,

I have been trying to use the bootloader for r232 with a 18f2550, i'm using the example provided by CCS (ex_bootloader and ex_bootload) but something seems to be missing.

This is what i have tried.

ex_bootloader.c

i know that you have to load the ex_bootloader to the pic so it can receive the new program and run it as a main if not it will cycle in application function.

i use generic the fuses provided by the ccs
Code:
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)


also i use the internal oscillator
Code:
#use delay(internal=8MHz)

i modified this in the ex_bootloader and ex_bootload file
Code:
#elif defined(__PCH__)
#include <18F2550.h>
#fuses NOWDT,INTRC,NOLVP,NOXINST,NOVREGEN
#use delay(internal=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B0,rcv=PIN_B1,bits=8,stream=PORT1)
#define PUSH_BUTTON PIN_A1
#endif


ex_bootload.c

i modified it to put the same fuses

also modified this to match the other file
Code:
#elif defined(__PCH__)
#include <18F2550.h>
#fuses NOWDT,INTRC,NOLVP,NOXINST,NOVREGEN
#use delay(internal=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B0,rcv=PIN_B1,bits=8,stream=PORT1)
#define PUSH_BUTTON PIN_A1
#endif


the last thing i tried was defining the start of the memory to program the new code using this
Code:
//_____________________________________________________________________________
/* ------------------------------------------------------------------------- */
/* map reset vector and interrupt vector                                     */
/* 0x000-0x2FF (PLUS I ADDED 100) is used by the bootloader. The bootloader maps the original   */
/* reset vector (0x000) to 0x400 and the interrupt vector (0x008) to 0x408.  */
/* ------------------------------------------------------------------------- */
#build (reset=0x400, interrupt=0x408)
/* ------------------------------------------------------------------------- */
/* reserve boot block area NEED TO RESERVE EVERYTHING UNDER400 (NOT just 'til 2FF)                                                  */
/* This memory range is used by the bootloader, so the application must not  */
/* use this area.                                                            */
/* ------------------------------------------------------------------------- */
#org 0, 0x3FF {}
//_____________________________________________________________________________


and the main function just print some numbers
Code:
void main(void)
{
   int8 i;
   
   delay_ms(100);
   
   printf("\r\nApplication Version 1.0\r\n");

   while(TRUE)
      printf("%3u ",++i);
}


i compile it and load ex_bootloader.hex. i made the circuit to send a reset and the trigger in PIN_A1 to start the bootloader

https://www.dropbox.com/s/3ga29w1nkuddb6y/teraterm1.PNG?dl=0

i configure the tera term serial port with Xon/Xoff as flow control

https://www.dropbox.com/s/ndrky328uglvp5w/teraterm2.PNG?dl=0

i select the ex_bootload.hex file and send it to the pic,it transmit the file but the code remains the same.

Does anyone have a suggestion that i can try to get the example work?

thanks in advance for your time
temtronic



Joined: 01 Jul 2010
Posts: 9177
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Mar 15, 2016 2:53 pm     Reply with quote

I haven't played with bootloaders but..... have you confirmed that the PB on A1 does function ?
Perhaps add code after PB is pressed to say 'PB pressed...now downloading', or something to that effect.

Also I've never been a fan of 'if else code' as usually you're onlu running ONE compiler version for that PIC so maybe you've modified it incorrectly? I'd delete the 'not my compiler' portions of the if elses....

Jay
elcrcp



Joined: 11 Mar 2016
Posts: 62
Location: izmir / Turkey

View user's profile Send private message

PostPosted: Tue Mar 15, 2016 3:17 pm     Reply with quote

I didn't use bootloader before but I had a work with 18f2550 and these are my config settings, you can use as referance if you suspect on your config.
(I used USB functions so I use both internal and external clocks, also it was done with another compiler =) )

Code:
        __CONFIG    _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC4_PLL6_1L & _USBDIV_2_1L
        __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
        __CONFIG    _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _BORV_3_2L & _VREGEN_ON_2L
        __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
        __CONFIG    _CONFIG3H, _CCP2MX_ON_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
        __CONFIG    _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L

_________________
There is nothing you can't do if you try
robertom



Joined: 15 Mar 2016
Posts: 12

View user's profile Send private message AIM Address

PostPosted: Tue Mar 15, 2016 4:14 pm     Reply with quote

temtronic wrote:
I haven't played with bootloaders but..... have you confirmed that the PB on A1 does function ?
Perhaps add code after PB is pressed to say 'PB pressed...now downloading', or something to that effect.

Also I've never been a fan of 'if else code' as usually you're onlu running ONE compiler version for that PIC so maybe you've modified it incorrectly? I'd delete the 'not my compiler' portions of the if elses....

Jay


yes i have that confirmation like this
Code:

void main(void) {

   if(!input(PUSH_BUTTON))
   {
      printf("\r\nBootloader Version 1.0 149\r\n");
   
      //  Let the user know it is ready to accept a download
      printf("\r\nWaiting for download...");
      load_program();
   }
   application();
}

also in the loader.c wich is included in ex_bootloader i have this
Code:

void load_program(void)
{
      output_high(LED2);
      delay_ms(500);
      output_low(LED2);

   real_load_program();
}

to turn on a led for a moment, the real_load_program its where the reception of the hex are made.
robertom



Joined: 15 Mar 2016
Posts: 12

View user's profile Send private message AIM Address

PostPosted: Tue Mar 15, 2016 4:16 pm     Reply with quote

elcrcp wrote:
I didn't use bootloader before but I had a work with 18f2550 and these are my config settings, you can use as referance if you suspect on your config.
(I used USB functions so I use both internal and external clocks, also it was done with another compiler =) )

Code:
        __CONFIG    _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC4_PLL6_1L & _USBDIV_2_1L
        __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
        __CONFIG    _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _BORV_3_2L & _VREGEN_ON_2L
        __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
        __CONFIG    _CONFIG3H, _CCP2MX_ON_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
        __CONFIG    _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L


i could check that, i think there is something wrong with the clock because i see the data go from the pc to the pic with an osciloscope but the ack or any bit for autentification doesnt show up
temtronic



Joined: 01 Jul 2010
Posts: 9177
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Mar 15, 2016 4:44 pm     Reply with quote

OK... time to go back a few steps

Have you been able to compile/load and execute a simple '1Hz LED' program? All it needs to do is 'toggle' an LED on an I/O pin ?

Jay
robertom



Joined: 15 Mar 2016
Posts: 12

View user's profile Send private message AIM Address

PostPosted: Tue Mar 15, 2016 6:00 pm     Reply with quote

temtronic wrote:
OK... time to go back a few steps

Have you been able to compile/load and execute a simple '1Hz LED' program? All it needs to do is 'toggle' an LED on an I/O pin ?

Jay


done i compile one with toggle

Quote:
output_high(Led1);
output_low(Led2);
while(1){
delay_ms(timer1);
output_toggle(Led1);
output_toggle(Led2);
}


use a timer of 500 ms

and with the internal clock of 8MHZ

Code:
#include <18F2550.h>
#device ADC=10

#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)

#use delay(internal=8MHz)
#use FIXED_IO( C_outputs=PIN_C1,PIN_C0 )
#define Led1   PIN_C0
#define Led2   PIN_C1


these are the pins im ussing for debugging the example
robertom



Joined: 15 Mar 2016
Posts: 12

View user's profile Send private message AIM Address

PostPosted: Tue Mar 15, 2016 6:42 pm     Reply with quote

https://www.dropbox.com/s/mlv8zym0yf6g73i/2016-03-15_183355582.mp4?dl=0

hereĀ“s a video so you can see what i see,

the blue line its the data from the pic to pc and de yellow one its from the pc to the pic.

i notice now that the pic its responding with the ack and with the flags when te buffer its full and request more information but the pic doesnt show the program that i load its a basic one, just a counter this is the program without the fuses i program it on the pic to see if it was working and i recieve the data all its okay
Code:

#if defined(__PCM__)
#include <16F887.h>
#fuses NOWDT
#use delay(crystal=20MHz)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#define PUSH_BUTTON PIN_A1

#elif defined(__PCH__)
#include <18F2550.h>
#fuses NOWDT,INTRC,NOLVP,NOXINST,NOVREGEN
#use delay(internal=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B0,rcv=PIN_B1,bits=8,stream=PORT1)
#define PUSH_BUTTON PIN_A1
#endif

//#define BOOTLOADER_MODE2X

//_____________________________________________________________________________
/* ------------------------------------------------------------------------- */
/* map reset vector and interrupt vector                                     */
/* 0x000-0x2FF (PLUS I ADDED 100) is used by the bootloader. The bootloader maps the original   */
/* reset vector (0x000) to 0x400 and the interrupt vector (0x008) to 0x408.  */
/* ------------------------------------------------------------------------- */
#build (reset=0x400, interrupt=0x408)
/* ------------------------------------------------------------------------- */
/* reserve boot block area NEED TO RESERVE EVERYTHING UNDER400 (NOT just 'til 2FF)                                                  */
/* This memory range is used by the bootloader, so the application must not  */
/* use this area.                                                            */
/* ------------------------------------------------------------------------- */
#org 0, 0x3FF {}
//_____________________________________________________________________________

//#include <bootloader.h>

void main(void)
{
   int8 i;
   
   delay_ms(100);
   
   printf("\r\nApplication Version 1.0\r\n");

   while(TRUE)
      printf("%3u ",++i);
}
temtronic



Joined: 01 Jul 2010
Posts: 9177
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Mar 15, 2016 7:27 pm     Reply with quote

hmm..
any time you use serial you need to add 'errors' to the use rs232(....options...)
..
I'm surprised the ccs example doesn't have it...
though as I said before, I haven't used their bootloaders yet.

Jay
robertom



Joined: 15 Mar 2016
Posts: 12

View user's profile Send private message AIM Address

PostPosted: Tue Mar 15, 2016 7:48 pm     Reply with quote

temtronic wrote:
hmm..
any time you use serial you need to add 'errors' to the use rs232(....options...)
..
I'm surprised the ccs example doesn't have it...
though as I said before, I haven't used their bootloaders yet.

Jay


so i have to modify something about the r232? seems to work fine with the data transfer and the osciloscope
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Tue Mar 15, 2016 8:15 pm     Reply with quote

If you don't add the "errors" to the RS232 config, one missed char etc. will cause the uart to lock up. According to my manual, it says "Used to cause the compiler to keep receive errors in the variable RS232_ERRORS and to reset errors when they occur". The last part is the key which prevents the lock-up. See the #USE RS232 directive in the compiler manual (my version 4 manual is pg 139). This has bitten many people (including me). One would think it would be on by default and you would have to disable it Evil or Very Mad

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
spilz



Joined: 30 Jan 2012
Posts: 218

View user's profile Send private message

PostPosted: Wed Mar 16, 2016 1:58 am     Reply with quote

Hi,
I never use uart bootloader, only usb bootloader, but what I think :

- don't have error in rs232 bootloader part, if there is an error during transfers, it need to stop/freeze. In a "normal" program, you need to add error because you want it still run.

- Add a delay in your main loop.

- maybe try just to load a blink led example with bootloader, it helped me to debug oscillator issue or change after load, the frequency of blink will show you better than a printf.

- don't forget that the fuse setup is the bootloader one, not the load program one.

- did you check the address where the program is load ?
- did you read the program memory after loading ? To check if it's well written
SeeCwriter



Joined: 18 Nov 2013
Posts: 160

View user's profile Send private message

PostPosted: Wed Mar 16, 2016 11:31 am     Reply with quote

Do the following bootloader and application work?

Bootloader:
Code:

#if !defined(__PCH__)
#error Compiler Not Supported!
#endif

#include <18F2550.h>
#device ADC=10

#define _bootloader

#fuses PUT, HSH, NOWDT, NOXINST, NOVREGEN

// NOTE - User must include bootloader.h in application program
#include <bootloader.h>
#include <loader.c>

#use delay(clock=8000000,internal=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,ERRORS)

#define PUSH_BUTTON PIN_A1

#INT_GLOBAL
void isr(void){
   jump_to_isr(LOADER_END+9);
}

#org LOADER_END+2, LOADER_END+4
void application(void) {
  while(TRUE);
}

void main()
{
 
    // Enter Bootloader if PUSH_BUTTON Pin is low after a RESET.
    if( !input(PUSH_BUTTON) )
    {
        printf("\r\nBootloader v1.0\r\n");
        printf("Waiting for download...");
   
   load_program();
    }
   
    application();
}


Application:
Code:

#include <18F2550.h>
#device ADC=10

#fuses PUT, HSH, NOWDT, NOXINST, NOVREGEN

#use delay(clock=8000000,internal=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1)

#define PUSH_BUTTON PIN_A1
 

#include <bootloader.h>

 void main(void)
 {
    int8 i;
     
     printf("\r\nApplication Version 1.0\r\n");

    while( TRUE ) {
       printf( "%3u ", ++i );
       delay_ms(500);
    }
   
 }
spilz



Joined: 30 Jan 2012
Posts: 218

View user's profile Send private message

PostPosted: Mon Mar 21, 2016 4:27 pm     Reply with quote

Hi,

I'm not able to compile your code,
here are code that works :

bootloader :
Code:
#include <18F2550.h>
#fuses NOWDT
#use delay(clock=8000000,internal=8000000)
// #use delay(crystal=20MHz)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#define PUSH_BUTTON PIN_C0

#define _bootloader

#include <bootloader.h>
#include <loader.c>

#org LOADER_END+2,LOADER_END+4

void application(void) {
  while(TRUE);
}

void main(void) {
   printf("\r\nTest 1.0\r\n");
   delay_ms(2000);
   if(!input(PUSH_BUTTON))
   {
      printf("\r\nBootloader Version 1.0\r\n");
   
      // Let the user know it is ready to accept a download
      printf("\r\nWaiting for download...");
      load_program();
   }

   application();
}

#int_global
void isr(void) {
   jump_to_isr(LOADER_END+5*(getenv("BITS_PER_INSTRUCTION")/8));
}


Application :
Code:
#include <18F2550.h>
#fuses NOWDT
#use delay(clock=8000000,internal=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#define LED_PIN PIN_B7

#include <bootloader.h>


void main(void) {
   int i = 0;
   while(true){
      printf("Test %u\r\n",i++);
      output_toggle(LED_PIN);
      delay_ms(500);
      output_toggle(LED_PIN);
      delay_ms(500);
   }
}


be careful how you load your application code,
did you check that you send data at 9600 baud ?
what do you use to load it ?
robertom



Joined: 15 Mar 2016
Posts: 12

View user's profile Send private message AIM Address

PostPosted: Tue Mar 29, 2016 10:58 pm     Reply with quote

spilz wrote:
Hi,

I'm not able to compile your code,
here are code that works :

bootloader :
Code:
#include <18F2550.h>
#fuses NOWDT
#use delay(clock=8000000,internal=8000000)
// #use delay(crystal=20MHz)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#define PUSH_BUTTON PIN_C0

#define _bootloader

#include <bootloader.h>
#include <loader.c>

#org LOADER_END+2,LOADER_END+4

void application(void) {
  while(TRUE);
}

void main(void) {
   printf("\r\nTest 1.0\r\n");
   delay_ms(2000);
   if(!input(PUSH_BUTTON))
   {
      printf("\r\nBootloader Version 1.0\r\n");
   
      // Let the user know it is ready to accept a download
      printf("\r\nWaiting for download...");
      load_program();
   }

   application();
}

#int_global
void isr(void) {
   jump_to_isr(LOADER_END+5*(getenv("BITS_PER_INSTRUCTION")/8));
}


Application :
Code:
#include <18F2550.h>
#fuses NOWDT
#use delay(clock=8000000,internal=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#define LED_PIN PIN_B7

#include <bootloader.h>


void main(void) {
   int i = 0;
   while(true){
      printf("Test %u\r\n",i++);
      output_toggle(LED_PIN);
      delay_ms(500);
      output_toggle(LED_PIN);
      delay_ms(500);
   }
}


be careful how you load your application code,
did you check that you send data at 9600 baud ?
what do you use to load it ?



hi, i compiled your code but i tried to load the program but it does the same, maybe its something about my wiring. Does the ftdi the dtr and cts has to be connected ?

For loading the program i tried siow and TeraTerm 4.73. i configure the baudd 9600, data 8 bit, parity none, stop 1 bit, flow control xon/xoff.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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