Hi,
Thanks very much for your help. I'll give it a go.
Stuart
I am quite new to programming using bootloader so please don't mind elementary doubts. I read in the AN2295 document that the MCU needs to be programmed with the bootloader software once using BDM interface. Having done that do I need to include the bootloader source code anywhere in my user-code to enable bootloader programming? Or it resides permanently in the protected flash memory of the MCU until I re-program it with BDM interface?
--
Cmux
Latter option is right. AN2295 bootloader has been designed with 'user code independence' in mind. The user code does not know anything about the bootloader (just taking in account few limitations given). The user code simply needs to be squeezed into lesser memory and FPROT/FOPT options ignored. Also the internal oscillator TRIM value is programmed together with the bootloader, not with the user code.
Vice versa, the bootloader does not know anything about the user code. Bootloader code is Flash protected (where applicable), occupying the top memory area, completely resident till erased via the BDM.
Thanks for your reply. Another doubt just came up. As you said that the internal oscillator TRIM value is set by the bootloader code, can my user-code still select an external oscillator as the clock source and disable the internal reference clock thus overriding the bootloader clock selection?
--
Cmux
Sure, your application can do *almost* anything with the MCU, no limitations. Again, the user code starts to execute with very minimum changes (against reset-state). Just look what happens between ILOP-reset and user application:
main: LDA SRS ; fetch RESET status reg. TSTA ; check if zero (this happens if RESET pulse is too short) BEQ slfprg ; if so, jump to self programming AND #%10000000 ; mask only POR RESET source BNE slfprg ; any of these sources, go to self programming LDHX #(REL_VECT|$00FF)&$FFFE ; there should be relocated reset vector of the new app. LDA ,X PSHA AND 1,X LDX 1,X PULH INCA BEQ slfprg ; don't jump if empty vector JMP ,X ; jump to relocated application
Simply, SRS is read and few instructions executed, all registers are in reset state, including internal oscillator ones.
Pre-set internal trim value is the one stored in Flash (typically during initial Flash programming) and it's the user application responsibility to copy this value to run-time TRIM register, where it effectivelly controls internal oscillator.
Pavel
I have made the hardware for bootloading my S08. I am facing two problems with it.
1.I flashed the bootloader code onto the microcontroller and then used the bootloader GUI to program the chip. It did fine but after that I was unable to flash the chip again using the bootloader GUI. The program gets stuck waiting for reset ACK. I read the flash to check if my user-code had accidently erased the bootloader (inspite of the flash protection) but it was not the case. If I flash the bootloader source code again then I am able to bootload my user code into it.
2. The above behaviour is not repeatable though. Most of the times the bootloader GUI gets stuck waiting for reset ACK.
What might I be doing wrong? I don't doubt the hardware connections because I was able to bootload the chip a couple of times. Loose connections, I have checked.
--
Cmux
An update:
The erratic behaviour (unpredictable programming) was because of my serial port being left open. That problem is solved. But the main problem is still there. After every time I program using the bootloader GUI, I have to flash the bootloader source again using Multilink. The flash contains both the sources (user and bootloader). I also checked where the PC is pointing to so as to verify that it indeed points to the bootloader area in the flash. In both cases (after flashing bootloader using Multilink and after programming the user code using bootloader GUI) the PC points to the same address i.e. FE19. Yet the second time I try to bootload the chip, the GUI keeps waiting for reset ACK.
Can anyone help me out here?
--
Cmux
This behaviour may be related to the following 'lazy' hw issue: see this link.
The reason why initial programming (without any user code) vs. sequential programming (some user code already programmed) differs is that:
- without any user code, ACK char is being transmitted periodically, so if first character is lost, any subsequent char is properly received (by PC) and the bootloading could start.
- with the user code, ACK chat is sent out only once, then (once the communication is not established), user code is started.
Pavel
hi,
We use the bootloader so customers can upgrade as the bootloader app is free and all you need to program is a serial port. I use a PnE BDM programmer during development.