|
|
View previous topic :: View next topic |
Author |
Message |
siemel
Joined: 06 Dec 2024 Posts: 2
|
Problem: DSPIC33CK128GM310 and bootloader |
Posted: Mon Dec 09, 2024 2:43 am |
|
|
Hi everyone,
I am working on a project where a microcontroller must be upgradable permanently. So, a bootloader must be used and stayed in the program.
Microcontroller : DSPIC33CKEP128GM310
IDE : MPLAB x IDE
CCS C compiler : PCD version 5.109
For starting, I am using the examples "ex_pcd_bootloader.c" and "ex_pcd_bootload.c". I had modified them.
I have programmed the µcontroller with the following program :
Code: | /// EX_PCD_BOOTLOADER.C ////
//#define ROM_WRITE_CAN_MODIFY_CONFIG_BITS
#include <33EP128GM310.h>
#fuses NOIOL1WAY //allow multiple reconfigurations of peripheral pins, so application can assign it's peripheral pins
#use delay(internal=140MHz)
#define UART_TX_PIN PIN_B7
#define UART_RX_PIN PIN_C10
#define UART_BAUD 9600
#pin_select U1TX=UART_TX_PIN
#pin_select U1RX=UART_RX_PIN
#use rs232(uart1, xmit=UART_TX_PIN, rcv=UART_RX_PIN, baud=UART_BAUD, errors)
#define PUSH_BUTTON PIN_C9 // PRG1
#define LED_RED PIN_C7
#define LOADER_PAGES 4
#define _bootloader
//#define BOOTLOADER_MODE2X
#include <pcd_bootloader.h>
#include <loader_pcd.c>
#org APPLICATION_START
void application(void)
{
printf("\r\nbootloader App reset cause %d\r\n", restart_cause());
delay_ms(100);
printf("\r\nApplication bootloader");
while(TRUE){
output_toggle(LED_RED);
delay_ms(500);
if(!input(PUSH_BUTTON))
{
printf("\r\nBootloader Version 1.0\r\nflash erase size %x\r\nLOADER_END %x\r\n APPLICATION_START %x\r\nAPPLICATION_END %x\r\n", getenv("FLASH_ERASE_SIZE"),LOADER_END, APPLICATION_START,APPLICATION_END);
// Let the user know it is ready to accept a download
printf("\r\nWaiting for download...");
// Load the program
load_program();
}
}
}
void main(void)
{
printf("\r\nbootloader Main reset cause %d\r\n", restart_cause());
printf("\r\nbootloader Main reset cause %d\r\n", restart_cause());
output_high(LED_RED);
if(!input(PUSH_BUTTON))
{
delay_ms(140);
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 the program
load_program();
}
application();
}
#int_default
void isr(void)
{
jump_to_isr(LOADER_END+5);
}
|
On my terminal, I have
"bootloader Main reset cause 0
bootloader Main reset cause 16
bootloader App reset cause 16
Application bootloader"
When I push the button, the "load_program" function is called.
I am using SIOW.exe for download the following program :
Code: |
//// EX_PCD_BOOTLOAD.c ////
#include <33EP128GM310.h>
#fuses NOIOL1WAY //allow multiple reconfigurations of peripheral pins, so application can assign it's peripheral pins
#use delay(internal=140MHz)
#define UART_TX_PIN PIN_B7
#define UART_RX_PIN PIN_C10
#define UART_BAUD 9600
#pin_select U1TX=UART_TX_PIN
#pin_select U1RX=UART_RX_PIN
#use rs232(uart1, xmit=UART_TX_PIN, rcv=UART_RX_PIN, baud=UART_BAUD, errors)
#define LED_RED PIN_C7
#define LOADER_PAGES 4
//#define BOOTLOADER_MODE2X
//This is a necessary include file. It reserves space so that the bootloader is not overwritten.
#include <pcd_bootloader.h>
rom char version[] = "Application Version 1.0";
void main()
{
output_low(LED_RED);
delay_ms(100);
printf("\r\n%s\r\n", version);
printf("You can put whatever code you want here.\r\n");
printf("So enjoy!\r\n");
while(TRUE)
{
}
} |
7 lines before the end of the files, I have obtained an error "timeout while downloading".
The terminal displays
"bootloader App reset cause 0
Application bootloader"
The value "0" means "restart at power up".
So, the microcontroller resets.
I have also tried the command line "ccsbootloader". I have got the error "PIC Stopped responding"
Do you have any idea of the cause of this reset ?
If I press again the push button, I can finish the downloading of the program.
Thanks for your help |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Mon Dec 09, 2024 5:38 am |
|
|
quick comments...
1) I hope you copied the original bootloader and modified YOUR copy and NOT the original CCS programs ! You should never edit them.
2) timeout error.. seems to indicate either the WDT has been enabled or SIOW has a 'timer' enabled.
I don't use that PIC or bootloader but curios how you know it's 7 lines before end of program it quits. I've seen a terminal program 'timeout' when the micro has to deal with a long line of code. that takes too long, so the terminal program aborts the download process.
I'm sure someone will reply soon with the real reason..... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Mon Dec 09, 2024 10:50 am |
|
|
First get rid of the pin definitions in the #USE RS232. UART1 says to use the
hardware UART, no pins needed. You have already assigned the pins.
Then, the application loaded internally with the bootloader, is only meant to
be a 'placeholder'. It should not contain any code. Having code here upsets
the sizes allocated as part of the bootloader process. It is possible to
have a program included with the bootloader, but this requires special
setting up, not adding to the bootloader code like this. You seem to be
trying to put bootloader code into the space for the application. This is
not how the this is done. |
|
|
siemel
Joined: 06 Dec 2024 Posts: 2
|
|
Posted: Wed Dec 11, 2024 1:45 am |
|
|
@temtronic
Yes, I made a copy of the programs.
I will look at the settings of te terminals.
Thanks for your reply
@Ttelmah
I will do some other researchs for doing this.
Thank you also for your reply |
|
|
|
|
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
|