|
|
View previous topic :: View next topic |
Author |
Message |
mvanvliet
Joined: 02 Jun 2009 Posts: 123 Location: The Netherlands
|
Bootloader with 16f1824 |
Posted: Mon Jan 09, 2012 4:53 am |
|
|
Compiler version 4.123
I've tried to adapt the bootloader example to use it for a 16f1824, but it isn't working. In first I've had the "out of rom" fault, which I removed with the help of PCMprogrammer's explanation. I've added 0x20 to the LOADER_END in the #org lines.
ex_bootloader.c
Code: |
#if defined(__PCM__)
#include <16F1824.h>
#FUSES INTRC_IO,NOWDT
#FUSES PUT,NOMCLR,NOPROTECT,NOCPD,NOBROWNOUT,BORV25
#FUSES NOCLKOUT,NOIESO
#FUSES NOFCMEN,WRT
#FUSES PLL_SW,NOSTVREN,NODEBUG,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, uart2)
#elif defined(__PCH__)
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) // Jumpers: 8 to 11, 7 to 12
#endif
#define _bootloader
#include <bootloader_917.h>
#include <loader_917.c>
#if defined(__PCM__)
#org LOADER_END+1,LOADER_END+10
#elif defined(__PCH__)
#org LOADER_END+2,LOADER_END+20
#endif
void application(void) {
while(TRUE);
}
#if defined(__PCH__)
#org 0x40,0x7F
#else
#org 0x20,0x3F + 0x20
#endif
void main(void) {
if(input(PIN_A4) == 0)
{
load_program();
}
application();
}
#ORG default
#int_global
void isr(void) {
jump_to_isr(LOADER_END+5*(getenv("BITS_PER_INSTRUCTION")/8));
} |
bootloader_917.h
Code: | #if defined(__PCM__)
#define LOADER_END (0x1FF + 0x60 + 0x20)
#define LOADER_SIZE (0x1BF + 0x60)
#elif defined(__PCH__)
#define FLASH_SIZE getenv("FLASH_ERASE_SIZE")
#warning FLASH_SIZE
#if ((0x500 % FLASH_SIZE) == 0 ) //IF 0x500 is even flash boundary
#define LOADER_END 0x4FF
#define LOADER_SIZE 0x3FF
#else //ELSE, goto next even boundary
#define LOADER_END ((0x500+FLASH_SIZE-(0x500%FLASH_SIZE))-1)
#define LOADER_SIZE (LOADER_END-0x100)
#endif
#endif
#ifndef _bootloader
#if defined(__PCM__)
#build(reset=LOADER_END+1, interrupt=LOADER_END+5)
#elif defined(__PCH__)
#build(reset=LOADER_END+1, interrupt=LOADER_END+9)
#endif
#org 0, LOADER_END {}
#endif |
In loader.c i've only changed:
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
to
#use rs232(baud=9600, uart2)
I've added a switch to pin A4 with a pull up resistor to +5V, A st232 board for changing the RS232 signals to TTL.
Compiling and programming works ok, but downloading the "new" software in the pic doesn't work. Siow.exe gives a time out warning when I use the "download software" button, Teraterm download the software without errors.
Ex_bootload code:
Code: |
#if defined(__PCM__)
#include <16F1824.h>
#FUSES INTRC_IO,NOWDT
#FUSES PUT,NOMCLR,NOPROTECT,NOCPD,NOBROWNOUT,BORV25 //PUT voor 64ms delay bij opstarten en bij brown-out
#FUSES NOCLKOUT,NOIESO //Codeprotectie aanzetten voor 0-rev?
#FUSES NOFCMEN,WRT
#FUSES PLL_SW,NOSTVREN,NODEBUG,NOLVP
//#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, uart2)
#elif defined(__PCH__)
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#endif
#include <bootloader.h>
void main(void) {
int i=0;
printf("\r\nApplication program version 1.00 \r\n");
while(TRUE)
printf("%u ",++i);
} |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Mon Jan 09, 2012 7:26 am |
|
|
hmm..
I don't have that chip but
first I'd get rid of any 'conditional' precompile code
those if ...pcm...else ...pch type statements.
Anything that looks confusing to the eye, might trip up the compiler.
Heck, you KNOW what chip you're using so why clutterup the code for another processor!
You're saying use 'uart2' but I don't know the default pins for that ,does the compiler ? AND is it the pins the bootloader is attached to??
You should add 'errors' to the us rs232(...) options. |
|
|
mvanvliet
Joined: 02 Jun 2009 Posts: 123 Location: The Netherlands
|
|
Posted: Mon Jan 09, 2012 8:07 am |
|
|
I don't have removed the PCH code for not introduce extra faults. I've changed as minimum as possible to make it work.
The UART2 pins are pin 12 and 13 of the processor. That works because I've used the UART2 and ST232 PCB before (for RS232 connection). |
|
|
mvanvliet
Joined: 02 Jun 2009 Posts: 123 Location: The Netherlands
|
|
Posted: Thu Jan 12, 2012 3:49 am |
|
|
I tried to use xmit and rcv instead of uart2, but that uses more ROM I think. Then I get again the "out of rom" error (01A9 left, need 001B7), but when I increase the #org segment and LOADER_END with another 20, it still gives that error.
ex_bootloader.c:
#org 0x20,0x3F + 0x40
bootloader.h:
#define LOADER_END (0x1FF + 0x60 + 0x40)
The rom allocation is:
ROM Allocation:
008A @12@PUTCHAR_2_
00E5 @12@FLASHWR
00B0 atoi_b16
0004 isr
Does anyone have an idea? |
|
|
|
|
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
|