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

bootloader 18F45J10
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
fernandokestering



Joined: 03 Sep 2018
Posts: 21

View user's profile Send private message MSN Messenger

bootloader 18F45J10
PostPosted: Sun Sep 23, 2018 6:17 pm     Reply with quote

I am trying to use the bootloader example "ex_bootloader.c" provided with the ccs compiler to load programs via RS232 to uC 18F45J10. I am doubtful where I need to change for this program to be compatible with this microcontroller.
Ttelmah



Joined: 11 Mar 2010
Posts: 19540

View user's profile Send private message

PostPosted: Mon Sep 24, 2018 12:28 am     Reply with quote

All that almost ever has to change in the examples, is the device configuration.

So the clock statement has to match your chip's clock.
The fuses have to be set to the working fuses your chip needs.
Then the I/O pin used has to change to suit your hardware.
Remember the fuse settings have to be ones that allow your chip to program it's own flash (so you can't write protect the flash memory for example).

The code itself then doesn't have to change at all.
fernandokestering



Joined: 03 Sep 2018
Posts: 21

View user's profile Send private message MSN Messenger

PostPosted: Tue Sep 25, 2018 12:08 pm     Reply with quote

I'm using the 18F45J10 uc, and trying to make the ex_bootloader.c example work with it, however I'm not succeeding.
I already configured the clock speed, apparently everything is correct, but I can not transfer the application file to the processor, I'm tantalizing via teraterm.
As a recorder I'm using pickit3, it works perfectly.
Ttelmah



Joined: 11 Mar 2010
Posts: 19540

View user's profile Send private message

PostPosted: Tue Sep 25, 2018 1:14 pm     Reply with quote

You need to start by proving your serial connection is working. Basic program to send some characters, and react to received characters. Then you need to test that you can see your trigger signal on B0. Once both of these are working, you can move on to trying to bootload.

Other comment though. The terminal program _must_ be set to use XON/XOFF handshaking, or it won't work.
fernandokestering



Joined: 03 Sep 2018
Posts: 21

View user's profile Send private message MSN Messenger

PostPosted: Wed Sep 26, 2018 10:39 am     Reply with quote

Yes, it's working perfect for uart. I just forgot to mention it, but I'm trying to upgrade using the HC-05 (bluetooth) module.
As soon as I want to update the uC, I send a command and write in an external memory (24LC256) a byte informing that the actuation will be done re reset of uC (cpu_reset ()), until everything works, only the update that is complicated
Ttelmah



Joined: 11 Mar 2010
Posts: 19540

View user's profile Send private message

PostPosted: Wed Sep 26, 2018 11:08 am     Reply with quote

The HC05, potentially raises a problem, since it introduces lag.
It contains it's own buffering, and if there is data in this, will continue to send data for a while after an XOFF character has been sent to the master. Problem is that the bootloader sends the XOFF, when it cannot receive any data because it is programming the flash memory and the processor has to halt while this is done.
You may need to actually slow the link a little, to ensure that data can be stopped quickly enough when required.

Standard debugging. You need to test the bootloader works without the HC-05 first. This tests that your settings are correct for both the terminal package, and the PIC code.
fernandokestering



Joined: 03 Sep 2018
Posts: 21

View user's profile Send private message MSN Messenger

PostPosted: Thu Sep 27, 2018 10:48 am     Reply with quote

Achieve downlaod of the program using the HC-05.
I confirmed by reading the program memory
The program starts to be written at position 0x1000, but after restarting and trying to make the firware execute directing the pointer to position 0x1000 with the function jump_to_isr (0x1000) ;, the firmware does not execute. Could someone help me solve it?
Ttelmah



Joined: 11 Mar 2010
Posts: 19540

View user's profile Send private message

PostPosted: Thu Sep 27, 2018 11:27 am     Reply with quote

Verify the memory. I'd be expecting the possibility of something corrupted higher up. So dump the memory from 0x1000, and use one of the packages that allows you to view/compare hex files, and see if it all compares correctly with what should have loaded.

Also the file you are loading, has been built to load at 0x1000. You have got booloader.h being loaded in this, with LOADER_SIZE set to 0xFFF
fernandokestering



Joined: 03 Sep 2018
Posts: 21

View user's profile Send private message MSN Messenger

PostPosted: Thu Sep 27, 2018 12:18 pm     Reply with quote

Yes, the looder_size is 0XFFF
I made the comparison of the files, the only different one for the original file for the read of the program mamypium, in addition to the bootloader area, is in the wares

Original file of the application to set recorded via bootloader
:04100000F5EF1FF0F9
:08100800046ED8CF05F0E0CF23

File read through pickit3

:10100000F5EF1FF0FFFFFFFF046ED8CF05F0E0CF34

The two lines of the original file have become one in program memory read file
fernandokestering



Joined: 03 Sep 2018
Posts: 21

View user's profile Send private message MSN Messenger

PostPosted: Thu Sep 27, 2018 12:43 pm     Reply with quote

Aplication code
Code:

#define _bootloader
#define LOADER_SIZE (0x0FFF)
#define LOADER_START (0)
#define LOADER_END (LOADER_SIZE)
#define APPLICATION_START (LOADER_SIZE+1)
#define APPLICATION_END (getenv("PROGRAM_MEMORY")-1)
#define APPLICATION_ISR (APPLICATION_START+8)
#build(reset=APPLICATION_START, interrupt=APPLICATION_ISR)
#org 0, LOADER_END {}
Ttelmah



Joined: 11 Mar 2010
Posts: 19540

View user's profile Send private message

PostPosted: Thu Sep 27, 2018 12:49 pm     Reply with quote

Are you using interrupts in the application?.
If so, does your bootloader have the global_isr to relocate this?.
Have you got the fuse to allow peripherals to be reprogrammed more than once?. This is essential if the bootloader is configuring any peripheral.
fernandokestering



Joined: 03 Sep 2018
Posts: 21

View user's profile Send private message MSN Messenger

PostPosted: Thu Sep 27, 2018 12:57 pm     Reply with quote

Yes, I am using interrupts in the application,

Follow bootloader code
Code:
#if defined (__ PCM__)
#include <16F887.h>
#fuses NOWDT
#use delay (crystal = 20MHz)
#use rs232 (baud = 9600, xmit = PIN_C6, rcv = PIN_C7)


#elif defined (__ PCH__)
#include <18F45J10.h>
#fuses HS
#use delay (crystal = 20MHz)
#use rs232 (baud = 9600, xmit = PIN_C6, rcv = PIN_C7)

#endif

#define _bootloader

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


#if defined (__ PCM__)
 #org LOADER_END + 1, LOADER_END + 2
#elif defined (__ PCH__)
 #org LOADER_END + 2, LOADER_END + 4
#endif
void application (void) {
    while (true);
}

void main (void) {
   char c = '';
   output_high (pin_e2);
  while (c! = '#') {
   if (kbhit ()) {
      c = getc ();
      putc (c);
   }
  }
  printf ("\ r \ nEdit E (Run) or G (Write) \ r \ n");
  c = getc ();
  if (c == 'G') {
      // let the user know it is ready to accept to download
      printf ("\ r \ nWaiting for download ...");
      load_program ();
  } else {
    printf ("Execute \ r \ n");
    #asm
    goto 0x1000
    More
    // application ();
   
  }
}
#int_global
void isr (void) {
  jump_to_isr (LOADER_END + 5 * (getenv ("BITS_PER_INSTRUCTION") / 8));
}

and the application header
Code:

#include <18f45J10.h>
#fuses HS
#device PASS_STRINGS = IN_RAM
#use delay (clock = 20Mhz)
#use rs232 (baud = 9600, xmit = pin_c6, rcv = pin_c7, stream = blue)
#use rs232 (baud = 9600, xmit = pin_d2, rcv = pin_d3, stream = bug)
#use rs232 (baud = 19200, xmit = pin_d7, rcv = pin_d6, stream = ext19200)
#use rs232 (baud = 9600, xmit = pin_d7, rcv = pin_d6, stream = ext9600)

#INCLUDE <ctype.h>
#include <variaveis.c>
#include <eeprom.c>

#byte RCSTA = GETENV ("SFR: RCSTA")

#include <definicoes.c>
#include <rc522.c>
#include <string.h>
#INCLUDE <ctype.h>
#include <stdlib.h>
#include <lcd_74hc595.c>
#define _bootloader
#define LOADER_SIZE (0x0FFF)
#define LOADER_START (0)
#define LOADER_END (LOADER_SIZE)
#define APPLICATION_START (LOADER_SIZE + 1)
#define APPLICATION_END (getenv ("PROGRAM_MEMORY") - 1)
#define APPLICATION_ISR (APPLICATION_START + 8)
#build (reset = APPLICATION_START, interrupt = APPLICATION_ISR)
#org 0, LOADER_END {}

#IGNORE_WARNINGS 216
Ttelmah



Joined: 11 Mar 2010
Posts: 19540

View user's profile Send private message

PostPosted: Thu Sep 27, 2018 1:24 pm     Reply with quote

Some comments:

1) If using a hardware UART, you should always have 'ERRORS' in the declaration for this, unless your code has hardware error handling. Without this the UART can become hung.

You should have HS, NOWDT, NOXINST, NOPROTECT

Otherwise you are relying on the default. A lot of code will not run if XINST is used, and this in many cases is the default.

2) Your bootloader global ISR, should be:
Code:

#int_global
void isr(void)
{
   jump_to_isr(APPLICATION_ISR);
}


Your application can just have

#FUSES NONE

Since it is dependant on the fuses already set in the bootloader.

3) Glaring issue.

In the application you have:

#define _bootloader

Wrong. This _must_ only be set in the bootloader. This is what will be stopping it from working. The application will be being compiled as if it is a bootloader....

Look at the ex_bootload.c example, this shows how a program should be compiled to be used with the bootloader.

4) As a further comment, the bootloader.h include, must be before any other code is included. So change your layout, and move:

#INCLUDE <ctype.h>
#include <variaveis.c>
#include <eeprom.c>

After the bootloader.h include.

3) Is the killer. Your setting here will be preventing the code from compiling correctly.
4) Will also potentially cause problems.
fernandokestering



Joined: 03 Sep 2018
Posts: 21

View user's profile Send private message MSN Messenger

PostPosted: Thu Sep 27, 2018 4:04 pm     Reply with quote

Ttelmah


Solved problem!!!!!

Thanks,
Ttelmah



Joined: 11 Mar 2010
Posts: 19540

View user's profile Send private message

PostPosted: Fri Sep 28, 2018 12:48 am     Reply with quote

Good. Smile

Have a nice weekend.
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