Programming the Dwengo board without a programmer

Installing the bootloader

Programming the bootloader on the Dwengo board can be done easily. For this you first download the hex file Dwengo bootloader that is attached to this page. This hex file contains the bootloader for the Dwengo board. With MPLAB you can program the Dwengo board with this hex file. The bootloader will now take the first 8192 bytes (0x0000 - 0x1FFF) of the program memory.

Writing a program

Since the bootloader takes the first 8192 bytes (0x0000-0x1FFF) of program memory, you have to take two things into account when writing your own programs: remapping the interrupt vectors and adjusting the linker script.

Remapping the interrupt routines is done with the following code:

  1. void YourHighPriorityISRCode();
  2. void YourLowPriorityISRCode();
  3.  
  4. // vector remapping
  5.  
  6. // Bootloader occupies addresses 0x000-0x1FFF and thus cannot be used.
  7. // Thus adresses 0x00, 0x08 and 0x18 (used for reset, high prior interrupt,
  8. // and low prior interrupt) have to be remapped.
  9. extern void _startup(void);
  10. #pragma code REMAPPED_RESET_VECTOR = 0x2000
  11. void _reset(void) {
  12. _asm goto _startup _endasm
  13. }
  14.  
  15. #pragma code REMAPPED_HIGH_INTERRUPT_VECTOR = 0x2008
  16. void Remapped_High_ISR(void) {
  17. _asm goto YourHighPriorityISRCode _endasm
  18. }
  19. #pragma code REMAPPED_LOW_INTERRUPT_VECTOR = 0x2018
  20. void Remapped_Low_ISR (void)
  21. {
  22. _asm goto YourLowPriorityISRCode _endasm
  23. }
  24.  
  25. #pragma code HIGH_INTERRUPT_VECTOR = 0x08
  26. void High_ISR(void) {
  27. _asm goto 0x2008 _endasm
  28. }
  29. #pragma code LOW_INTERRUPT_VECTOR = 0x18
  30. void Low_ISR(void) {
  31. _asm goto 0x2018 _endasm
  32. }
  33.  
  34. #pragma code
  35.  
  36. // Interrupt handler routines
  37. #pragma interrupt YourHighPriorityISRCode
  38. void YourHighPriorityISRCode() {
  39. //Check which interrupt flag caused the interrupt
  40. //Service the interrupt
  41. //Clear the interrupt flag
  42. }
  43. #pragma interruptlow YourLowPriorityISRCode
  44. void YourLowPriorityISRCode() {
  45. // Check which interrupt flag caused the interrupt
  46. // Service the interrupt
  47. // Clear the interrupt flag
  48. }

The linker script has to be adjusted in such a way the a piece of the program memory is reserved for the bootloader. Moreover, there also needs to be reserved a piece of memory for the interrupt vectors. The following lines describe a working linker script that can be used with the bootloader:

  1. LIBPATH .
  2.  
  3. FILES c018i.o
  4. FILES clib.lib
  5. FILES p18f4550.lib
  6.  
  7. CODEPAGE NAME=bootloader START=0x0 END=0x1FFF PROTECTED
  8. CODEPAGE NAME=vectors START=0x2000 END=0x2029 PROTECTED
  9. CODEPAGE NAME=page START=0x202A END=0x7FFF
  10. CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
  11. CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
  12. CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
  13. CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
  14.  
  15. ACCESSBANK NAME=accessram START=0x0 END=0x5F
  16. DATABANK NAME=gpr0 START=0x60 END=0xFF
  17. DATABANK NAME=gpr1 START=0x100 END=0x1FF
  18. DATABANK NAME=gpr2 START=0x200 END=0x2FF
  19. DATABANK NAME=gpr3 START=0x300 END=0x3FF
  20. DATABANK NAME=usb4 START=0x400 END=0x4FF PROTECTED
  21. DATABANK NAME=usb5 START=0x500 END=0x5FF PROTECTED
  22. DATABANK NAME=usb6 START=0x600 END=0x6FF PROTECTED
  23. DATABANK NAME=usb7 START=0x700 END=0x7FF PROTECTED
  24. ACCESSBANK NAME=accesssfr START=0xF60 END=0xFFF PROTECTED
  25.  
  26. SECTION NAME=CONFIG ROM=config
  27.  
  28. STACK SIZE=0x100 RAM=gpr3
  29.  
  30. SECTION NAME=USB_VARS RAM=usb4

Programming without a programmer

When the program is ready and you have generated a hex file, you can program the Dwengo board. First you have to download the USB framework from the Microchip website External link. Install this framework and under C:\Microchip Solutions\USB Device - Bootloaders\HID - Bootloader you can find the program HIDBootLoader.exe. Start this program. If the program does not want to start, you also have to install the Microsoft .NET framework External link.

After this connect the Dwengo board to your computer with a USB cable (without the programmer). Next reset the Dwengo board while pressing the C button. When you release the C button, the board is bootloader modus. The Dwengo board will now be detected by the HIDBootLoader program. With this HIDBootLoader program you can load you hex file and program it on the Dwengo board.