Author Topic: Customizing Bootloader  (Read 1375 times)

RatTrap

  • NewMember
  • *
  • Posts: 20
Customizing Bootloader
« on: January 25, 2019, 06:55:55 PM »
Good afternoon everyone and Felix you as well.  I have another slightly bizarre question for you.  If I wanted to modify your bootloader to move the FlashSS pin from C7 to B1 and I modified all of the places that referenced C7 to B1 along with the corresponding port information in the optiboot.c file.  I have already successfully recompiled it to 8MHz for the Atmega1284p, but for whatever reason whenever I put the mcu into powerdown mode and try wake it up using an external rtc it crashes and restarts.  Mind you when I leave the flashSS pin at ddrc, portc, and pinc7 everything works fine, except that the memory slave select pin is now on the wrong pin for the hardware board I have to deal with.  Do you have any advice or thoughts?  You are afterall the master of all things to do with the ATMEGA1284p :).  here are the code sections that I found that reference this after I made the changes.  This is adapted from your dual-optiboot source.

Your Code:

My code:
Code: [Select]
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega88) || defined(__AVR_ATmega8__) || defined(__AVR_ATmega88__)
  #define FLASHSS_DDR     DDRB
  #define FLASHSS_PORT    PORTB
  #define FLASHSS         PINB0
  #define SS              PINB2
#elif defined (__AVR_ATmega1284P__) || defined (__AVR_ATmega644P__)
  #define FLASHSS_DDR     DDRB
  #define FLASHSS_PORT    PORTB
  #define FLASHSS         PINB1
  #define SS              PINB4
#endif

My other modification

Code: [Select]
//SPI INIT
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega88) || defined(__AVR_ATmega8__) || defined(__AVR_ATmega88__)
  DDRB |= _BV(FLASHSS) | _BV(SS) | _BV(PB3) | _BV(PB5); //OUTPUTS for FLASH_SS and SS, MOSI, SCK
  FLASH_UNSELECT; //unselect FLASH chip
  PORTB |= _BV(SS); //set SS HIGH
#elif defined (__AVR_ATmega1284P__) || defined (__AVR_ATmega644P__)
  DDRB |= _BV(FLASHSS); //OUTPUT for FLASH_SS
  DDRB |= _BV(SS) | _BV(PB5) | _BV(PB7); //OUTPUTS for SS, MOSI, SCK
  FLASH_UNSELECT; //unselect FLASH chip
  PORTB |= _BV(SS); //set SS HIGH
#endif

granted all of the # weren't in the actual code.  They seem to have just been added by pasteing here.  lol
Charlie
« Last Edit: February 22, 2019, 02:59:10 PM by Felix »

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6490
  • Country: us
    • LowPowerLab
Re: Customizing Bootloader
« Reply #1 on: January 25, 2019, 07:17:13 PM »
Mind you when I leave the flashSS pin at ddrc, portc, and pinc7 everything works fine, except that the memory slave select pin is now on the wrong pin for the hardware board I have to deal with.
Hi Charlie,
You need to focus on finding out why just moving a pin causes your board to reset.
I'm not sure I want to try guessing why that would be.
I'm assuming your port re-assignments are correct.

RatTrap

  • NewMember
  • *
  • Posts: 20
Re: Customizing Bootloader
« Reply #2 on: January 25, 2019, 07:46:40 PM »
I assume they are correct. I have to meet a friend for dinner I will review the code when I finish here. I can go a little from memory now though. I donít recall seeing any reference to the flash in pins.h, pin_arduino.h, or the makefile. The only reference to the flashSs pins are the ones I copied above from the optimist.c. You may not remember me but I would never resort to a forum unless I was really at a loss. I canít fathom a reason for the crashing. The strange thing is that it crashes on wake up. Perhaps the problem is on that end, you think. Thatís pin 12 which is pcint28 but I canít remember itís port number off the top of my head. Sorry

RatTrap

  • NewMember
  • *
  • Posts: 20
Re: Customizing Bootloader
« Reply #3 on: January 26, 2019, 01:08:32 PM »
Hi Felix,

I solved it.  It was so bizarre. Everything worked if I didn't modify the flashss pin or the flash port. Which ofcourse wouldn't solve my issue because I needed to move that pin (really annoyed that the hardware got changed on me lol ). It also worked fine with the new slave select pin if I used any other sleep mode except power-down.  You ready for the completely crazy reason for the restarting when it was to wake up.  I upload my code using atmel studio and an AVRISP-mkii.  Give you one guess what port that sits on.  In a nut shell the problem was solved by unplugging the avrisp-mkii after programming it.  If it is plugged in when the chip wakes up, it forces a reset.  Not sure why but there it is.  Thank you for your help.

Charlie

satblip

  • NewMember
  • *
  • Posts: 1
Re: Customizing Bootloader
« Reply #4 on: February 22, 2019, 01:56:42 PM »
Hi Charlie,

Quick question, how did you sucessfuly recompiled the DualOptiBoot for the 1284p 8mhz. When I clone Optiboot, I successfuly build the bootloader, but as soon as I copy the "Optiboot.c", "pin_defs.h" and "Makefile" from https://github.com/LowPowerLab/DualOptiboot into Optiboot folder, I received this error:

Code: [Select]
$ make atmega1284p
make: *** No rule to make target 'optiboot_atmega1284p.hex', needed by 'atmega1284'.  Stop.

RatTrap

  • NewMember
  • *
  • Posts: 20
Re: Customizing Bootloader
« Reply #5 on: April 22, 2019, 12:31:06 PM »
Hi There sorry for the delay in my response.  I have been out of town doing some testing and haven't gotten online.  So the process is relatively simple, but stuff can definitely go wrong.  Here are the steps I take.

0) Go to the Arduino hardware file/bootloaders/optiboot
1) Back up the PinsDef, Optiboot, and make file into a different file so that you don't damage them and can replace them later
2) Copy the duel optiboot files (make, optiboot, and pinsdef) into Arduino/hardware/bootloaders/optiboot file to replace the files you just removed
3) Open the Command prompt and change the directory to the same Arduino/hardware/bootloaders/optiboot file that you placed your new duel optiboot files (make, optiboot, and pinsdef) in
4) In the command prompt type Make atmega1284p
6) Your new bootloader will appear in the folder and you can simply drag it to a different folder
7) remove your files from the optiboot folder and relace with the originals you backed up.


Note that if you changed the oscillator to something like an 8MHz one, you will need to change the clock speeds in the Make file, as well as possibly commenting out those sections or correcting them for your oscillator in the optiboot.c file.  Most of my problems were the result of my using an 8MHz resonator and it took a while for me to figure out.  If that is your issue, look for where it say Fcpu and modify as you need in the optiboot.c and change the baud in the makefile to be within the correct error range.

I really hope that this helps.

Charlie