Bootloader - 200 x l PIC18F on same RS485 bus

Coding and general discussion relating to user created compiler modules

Moderators: David Barker, Jerry Messina

Post Reply
TonyR
Posts: 75
Joined: Fri Jan 14, 2011 11:49 pm
Location: Sydney
Contact:

Bootloader - 200 x l PIC18F on same RS485 bus

Post by TonyR » Thu Jan 14, 2016 12:04 am

Has anyone tried to use the SF boot loader over RS485. I assume (dangerous I know) it will work immediately - if there's only one device on the bus.

But what if there are 200?

Has anyone tried it. I thought I could maybe put all the ones not being boot loaded to sleep for 30 seconds, at any instant, except the one I want to upload to?

ie. If I want to bootload PIC number #135 I send a broadcast command putting all PICs to sleep except that one, then do the upload?

Suggestions welcome!

SHughes_Fusion
Posts: 219
Joined: Wed Sep 11, 2013 1:27 pm
Location: Chesterfield

Re: Bootloader - 200 x l PIC18F on same RS485 bus

Post by SHughes_Fusion » Thu Jan 14, 2016 9:22 am

I've written my own bootloader for RS485, I've never used the Swordfish one so I can only give a few hints and thoughts.

The first one being, I'm assuming you have modified the bootloader to control the bus direction.

Secondly, and this one is causing me a slight headache still, don't forget there is no way to pause transmission over RS485 - i.e. no hardware handshaking and software handshaking of the normal XON/XOFF type isn't easy to implement. I don't know how the Swordfish bootloader works but my earlier Bluetooth ones just dumped the .hex file over the Bluetooth link and the bootloader controlled CTS to pause transmission when it came to write a page. My temporary 'fix' under RS485 is to add a delay between each line I send but that slows things down. I'm intending to explore writing my own uploader in VB which sends the .hex file a line at a time and waits for a response from the bootloader before sending the next. Don't forget the processor will stall for several microseconds while erasing and writing each flash page.

The way I enter my bootloader is by getting the PIC to execute the 'Reset' command which I pick up via the status of RCON. The bootloader check if RCON.4 is set. This indicates the processor reset didn't come from the Reset command. I then perform a secondary test - generally checking a jumper but it can also be a sequence of button presses - which allows the user to force the bootloader to run. If this test fails then I jump to the firmware start location, otherwise I run the bootloader.

If you can implement something similar then all you need to do is to send your broadcast command to put the rest to sleep, send a command directly to the one you want to bootload telling it to enter bootloader mode and go from there.

I'd consider having a 'wake' command as well as a 'sleep' command so you can put the rest of the devices to sleep for as long as necessary. Take care that this couldn't be a sequence encountered in transmitting a hex file though.

Jerry Messina
Swordfish Developer
Posts: 1469
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: Bootloader - 200 x l PIC18F on same RS485 bus

Post by Jerry Messina » Thu Jan 14, 2016 1:39 pm

Secondly, and this one is causing me a slight headache still, don't forget there is no way to pause transmission over RS485...
What about using a protocol like XMODEM? It's pretty light-weight, uses small 128-byte packets, and is designed for half-duplex links.

I like it since most terminal emulators support it, so with a simple command-line mode I can use it to transfer hex files w/out requiring any special software on the PC end.

SHughes_Fusion
Posts: 219
Joined: Wed Sep 11, 2013 1:27 pm
Location: Chesterfield

Re: Bootloader - 200 x l PIC18F on same RS485 bus

Post by SHughes_Fusion » Thu Jan 14, 2016 2:15 pm

Interesting idea... My preferred terminal (Coolterm) doesn't seem to support it but I guess it is easy enough to look at another.

Presumably it complicated matters slightly as you might not get a full block of data in one go from the .hex file as it is split in to fixed size chunks rather than send in line feed terminated blocks?

I'm probably missing something but from the Wikipedia description it seems to be limited to 255 blocks which is a shade under 32k - what happens for bigger files?

It would have the benefit of allowing me to develop in a comfortable environment - I'm just trying to fathom how you use Visual Basic so I can write a simple bootloader program but it isn't that intuitive and I haven't located a 'get you started' guide yet, although I've only been looking for 5 minutes so far.

Jerry Messina
Swordfish Developer
Posts: 1469
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: Bootloader - 200 x l PIC18F on same RS485 bus

Post by Jerry Messina » Thu Jan 14, 2016 6:12 pm

Presumably it complicated matters slightly as you might not get a full block of data in one go from the .hex file as it is split in to fixed size chunks rather than send in line feed terminated blocks?
Probably... I just collect data from the hex file into a buffer the size of the flash programming block, and write the buffer to the chip whenever:
- a new hex address record comes in
- the flash block buffer fills
- the hex address isn't in the same programming block as the buffer
- an END record comes in
... it seems to be limited to 255 blocks which is a shade under 32k - what happens for bigger files?
The block number just wraps around to 0. Since you ACK/NACK each block as it comes in you only really need to keep track of two block numbers (previous and current) so that you can detect any errors/tell it to retransmit a packet.

TeraTerm is the program I use most often on the PC side... works w/serial, network, usb, supports a number of protocols, and it's free. http://logmett.com/

TonyR
Posts: 75
Joined: Fri Jan 14, 2011 11:49 pm
Location: Sydney
Contact:

Re: Bootloader - 200 x l PIC18F on same RS485 bus

Post by TonyR » Thu Jan 14, 2016 10:00 pm

Thanks for suggestions. I will try and set up something to test it the sleep wake idea. Messing with the direction/hand shaking sounds scary.

I've used VB for heaps of things since its so fast to get things working and has dozens of libraries. It works great with the $5 USB to RS485 converters with the FTDI part on them. If you need to know anything let me know.

Post Reply