18F BOOTLOADER AND FW INFO

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
mrk89
Posts: 19
Joined: 10 Jan 2015 01:05

18F BOOTLOADER AND FW INFO

#1 Post by mrk89 » 11 Apr 2022 21:58

Hi guys,
I loaded the bootloader into my PIC18F2458 and it works well!
Now I would like to add the information of the firmware loaded into the PIC to the Bootloader info record in the config.c file.

I would like to replace the "DEVICE_NAME" everytime I upload a new firmware using the bootloader.

Can someone explain me how to do that?
Thank you very much in advance, it's been 5 days now and I'm not able to succede in this :(

Code: Select all

#define DEVICE_NAME "NO NAME"

// Bootloader start address equasion:
const unsigned long BOOTLOADER_START  = ((__FLASH_SIZE-BOOTLOADER_SIZE)/_FLASH_ERASE)*_FLASH_ERASE;
const unsigned char RESET_VECTOR_SIZE = 4;    // MCU reset vector size in bytes.

// Bootloader info record.
// It is used by PC application tool to identify device and get device
// specific information.
const TBootInfo BootInfo = { sizeof(TBootInfo),                   // This record's size in bytes.
                            {bifMCUTYPE,    MCU_TYPE},            // MCU family.
                            {bifMCUSIZE,    __FLASH_SIZE},        // MCU flash size.
                            {bifERASEBLOCK, _FLASH_ERASE},        // MCU Flash erase block size in bytes.
                            {bifWRITEBLOCK, _FLASH_WRITE_LATCH},  // MCU Flash write block size in bytes.
                            {bifBOOTREV,    BOOTLOADER_REVISION}, // Version of bootlaoder firmware.
                            {bifBOOTSTART,  BOOTLOADER_START},    // Bootloader code start address.
                            {bifDEVDSC,     DEVICE_NAME}          // Name of this device.
                           };

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: 18F BOOTLOADER AND FW INFO

#2 Post by filip » 14 Apr 2022 12:45

Hi,

What happens if you replace NO NAME with your custom name ?

Regards,
Filip.

mrk89
Posts: 19
Joined: 10 Jan 2015 01:05

Re: 18F BOOTLOADER AND FW INFO

#3 Post by mrk89 » 14 Apr 2022 20:18

Hi Filip,
What happens if you replace NO NAME with your custom name ?
it works, so my name is showed.
But that's not the problem, I'm going to explain it better...
What I'm trying to do is something like this:

In the bootloader

Code: Select all

//I upload the bootloader with blank DEVICE_NAME
char DEVICE_NAME[40]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} absolute 0x0580;

In every firmware I'll upload using the bootloader

Code: Select all

//1: I upload the firmware with name and firmware version in DEVICE_NAME
char DEVICE_NAME[40]={'M','y',' ','F','W',' ','V','e','r','s','i','o','n',' ','x','.','x','x',' ',M','y',' ','F','W',' ','N','a','m','e'} absolute 0x0580;//
I can run this kind of code, and it do not return any error, but when I get device name, I get random chars insteaad of my vector.

Can you (or anyone else reading this post) give me any hint on how to solve this?

Thank you in advance

jumper
Posts: 466
Joined: 07 Mar 2007 14:36

Re: 18F BOOTLOADER AND FW INFO

#4 Post by jumper » 15 Apr 2022 10:18

Hi,

if you first erase the entire pic,
then use a programmer to load the bootloader and make sure the configuration bits are not set for code protection.

then read back the entire FLASH and view the hex data and see what is stored at 0x0580.

now let the bootloader load the firmware and now read the flash again to see what is at 0x0580.

if this looks correct then i can only suggest that you use the hardware debugger with breakpoints just before you read this data and see what happens. How do you move the data from the FLASH string to a RAM string so it can be used in the bootloader answer to rhe pc? Single stepping might even take you inside the generated asm code to see what is happening.

jumper
Posts: 466
Joined: 07 Mar 2007 14:36

Re: 18F BOOTLOADER AND FW INFO

#5 Post by jumper » 17 Apr 2022 09:30

and have you tried to add a null character 0x00 in the end of your firmware string to make sure it is zero terminated?

and be aware that strncpy does NOT add a zero termination to the destination string so if you use that in your code.

mrk89
Posts: 19
Joined: 10 Jan 2015 01:05

Re: 18F BOOTLOADER AND FW INFO

#6 Post by mrk89 » 19 Apr 2022 06:47

Hi Guys,
thank you for your very precious help.

I think I'm done, but didn't test it on a phisical device yet.

This is how I fill the information I need to transmit to the PC along with the BootInfo (BOOTLOADER CODE):

Code: Select all

static void SendBootInfo() {
  int  num=0;
  
  typedef struct {
    char fArray[sizeof(TBootInfo)];
  } TBootInfoArray; // structure with an array type to handle copying.

  // Note: Additional handling needs to be taken if boot info record's size
  // exceeds HidWriteBuff size (64 bytes).
  *(TBootInfoArray *)(void *)HidWriteBuff = BootInfo; // Copy boot info record into transmit buffer.
  
  for(num=0;num<40;num++)
     {
      HidWriteBuff[23+num]=FLASH_Read(0x5100+num);
     }

  HID_Write(HidWriteBuff, 64);                        // Send boot info.
}
This is how I tried to write the FLASH memory with the info (APPLICATION CODE NOT WORKING):

Code: Select all

const unsigned char FW_VERSION[40]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39} absolute 0x5100; //FIRMWARE VERSION AND NAME
And this is how I write the FLASH memory with the info (APPLICATION CODE WORKING):

Code: Select all

const char* ptr;
const unsigned char FW_VERSION[40]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39} absolute 0x5100; //FIRMWARE VERSION AND NAME

void main(void)
{
 ptr = FW_VERSION;
 ...
 ...
 ...
}
I found this solution just copying the structure of the sintax from other lines of pre-written code.
I'm not able to use pointers, I'm very bad on this, and I'm not able to fully understand this code.
Can someone explain me why the first code is not working (variable[] Absolute 0xnnnn;),
but it will works adding a pointer in the main?
Thank you again

mrk89
Posts: 19
Joined: 10 Jan 2015 01:05

Re: 18F BOOTLOADER AND FW INFO

#7 Post by mrk89 » 23 Apr 2022 00:08

Can someone explain me why the first code is not working (variable[] Absolute 0xnnnn;),
but it will works adding a pointer in the main?
Yes, me! :roll:
The problem here is that if I declare a constant that's not used in the firmware, the compiler automatically remove it... :shock:

So I need to use it in the main to make it stored in the flash...
So it's not about the pointer.

Now I've some other problems, but I won't bother you. I'll try to find a solution on my own.

Thank you

Post Reply

Return to “mikroC PRO for PIC General”