|
|
View previous topic :: View next topic |
Author |
Message |
drnewbury
Joined: 21 May 2018 Posts: 2
|
PIC16F1455 USB Bootloader & HID Enumeration issue |
Posted: Mon May 21, 2018 2:13 am |
|
|
Hi
I am trying to use either the Microchip MLA USB bootloader or the USB DFU Bootloader.
(https://www.microchip.com/mplab/microchip-libraries-for-applications or https://github.com/majbthrd/PIC16F1-USB-DFU-Bootloader)
Both seem to be functioning correctly when I compile a program in CCS using the following headers:
Code: |
///////////////////////////////////////////////////////////////////////////
//// USB_BOOTLOADER.H ////
//// ////
//// ////
///////////////////////////////////////////////////////////////////////////
//how big is the bootloader?
//the bootloader will reside from address 0x0000 to this location. the
//application will then sit at this location+1 to the end of program memory.
#define LOADER_SIZE (0x903)
#define LOADER_START (0)
#define LOADER_END (LOADER_SIZE)
#define APPLICATION_START (LOADER_SIZE+1)
#define APPLICATION_END (getenv("PROGRAM_MEMORY")-1)
#define APPLICATION_ISR (APPLICATION_START+8)
#ifndef _bootloader
//in the application, this moves the reset and isr vector out of the bootload
//space. it then reserves the loader space from being used by the application.
#build(reset=APPLICATION_START, interrupt=APPLICATION_ISR)
#org 0, LOADER_END {}
#endif
|
or
Code: |
/* --- BEGIN: changes required for bootloader ------------------------------ */
/* ------------------------------------------------------------------------- */
/* map reset vector and interrupt vector */
/* 0x000-0x7FF is used by the bootloader. The bootloader maps the original */
/* reset vecotr (0x000) to 0x800 and the reset vector (0x008) to 0x800. */
/* ------------------------------------------------------------------------- */
#build (reset=0x201, interrupt=0x209)
/* ------------------------------------------------------------------------- */
/* reserve boot block area */
/* This memory range is used by the bootloader, so the application must not */
/* use this area. */
/* ------------------------------------------------------------------------- */
#org 0, 0x200 {}
/* --- END: changes required for bootloader -------------------------------- */
|
However, when I use usb_init(); something strange is happening.
If the while loop of the program is empty the USB device enumerates correctly, but if I include anything inside the while loop the USB device no longer enumerates and shows as "USB Device (Device Descriptor Request Failed)"
I have attempted this with the unaltered output from the CCS Project Wizard.
I generated the project with nothing but the USB functionality, compiled it, and loaded it using a pickit and it functioned perfectly.
Then I added one of the above headers, compiled it and loaded it with the bootloader, and with both bootloaders, I get the same issue, it appears to function until I add anything inside the while loop, then it fails.
I also attempted to mirror the fuses in the project to those in the bootloader:
Code: |
#fuses INTRC_IO, WDT_SW, PUT, NOMCLR, PROTECT, BROWNOUT, NOIESO, NOFCMEN, WRT, NOCPUDIV, LS48MHZ, PLL3X, PLLEN, STVREN, LPBOR, NODEBUG, NOLVP
|
Again, using these the program functions correctly when loaded directly but not when loaded using the bootloader.
Finally, when I create a project not using the USB functionality there seems to be no issue with the program compiled by CCS functioning after loading with the bootloaders.
Has anyone got any thoughts on what I am doing wrong?
P.S. this is the c generated by the project wizard that I am using:
main.c:
Code: |
#include <main.h>
/* TODO: Use usb_put_packet() to transmit data to USB HID,
using USB_HID_ENDPONT for the endpoint and the payload size
needs to match USB_CONFIG_HID_TX_SIZE. Use usb_get_packet()
to read incomming data, using USB_HID_ENDPOINT for the
endpoint. usb_enumerated() can be used to see if connected to
a host and ready to communicate. */
void main()
{
usb_init();
while(TRUE)
{
//TODO: User Code
}
}
|
main.h:
Code: |
#include <16F1455.h>
#device ADC=10
#FUSES NOWDT //No Watch Dog Timer
#use delay(internal=48MHz,USB_FULL,ACT=USB)
#define USB_CONFIG_BUS_POWER 500
#define USB_STRINGS_OVERWRITTEN
char USB_STRING_DESC_OFFSET[]={0,4,12};
char const USB_STRING_DESC[]={
//string 0 - language
4, //length of string index
0x03, //descriptor type (STRING)
0x09,0x04, //Microsoft Defined for US-English
//string 1 - manufacturer
8, //length of string index
0x03, //descriptor type (STRING)
'f',0,
'o',0,
'o',0,
//string 2 - product
8, //length of string index
0x03, //descriptor type (STRING)
'b',0,
'a',0,
'r',0
};
#define USB_CONFIG_HID_TX_SIZE 0
#define USB_CONFIG_HID_RX_SIZE 0
#include <pic16f_usb.h>
#include <usb_desc_hid.h>
#include <usb.c>
| [/url] |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Mon May 21, 2018 7:30 am |
|
|
Bootloaders must end on page boundaries. Not odd sizes like 0x903.
Now your two different headers are for very different bootloader sizes. The GitHub one is optimised to fit in 0x1FF bytes, so should use:
#build (reset=0x200, interrupt=0x204)
#org 0, 0x1FF {}
On your chip the block size is 32 instruction words. The main code must be on a boundary of this count.
The interrupt vector on a PIC16, is four bytes up the ROM, not 8 bytes up as you seem to be trying to use. 8 bytes up, is the location for a PIC18.
You can build your run time code with
#FUSES NONE
However your code must be designed to run with the fuses the bootloader is setting. |
|
|
drnewbury
Joined: 21 May 2018 Posts: 2
|
Thankyou |
Posted: Tue May 22, 2018 10:12 am |
|
|
Thank you so much!
Everything is running perfectly now.
I fundamentally did not understand the significance of the byte difference between the PIC16 chip and the PIC18 examples I was using.
Also, in all honesty, I have been trying to find an explanation and I think I am still failing to fully understand the boundaries and interrupt vectors.
This showed up in my rss feed today and seems very timely:
https://www.designnews.com/design-hardware-software/soon-be-extinct-embedded-software-engineer/39152617858743
Anyway, thanks again for taking the time to reply.
David |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Tue May 22, 2018 11:55 am |
|
|
Well done.
A few little hints and you've got it. Very impressive. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|