CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC24FJ128GB204 and usb.h

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Zardoz



Joined: 10 May 2010
Posts: 8
Location: Germany

View user's profile Send private message

PIC24FJ128GB204 and usb.h
PostPosted: Thu Apr 27, 2017 7:11 am     Reply with quote

We have built a prototype board with the PIC24FJ128GB204 to understand the exercises of the CCS exercise book for the demo board with the PIC24FJ256GB 206. We have changed the processor header file in the ccsusb.h and now we get the error#128 "A #DEVICE required before this line" from the PCD Compiler. In the linked PIC24FJ128GB204.h there is the device directive for this processor. What's going wrong ?
Confused
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Thu Apr 27, 2017 8:36 am     Reply with quote

Are you possibly compiling using MPLAB?.

If so, you must ensure that the only file in the list of files to compile is the one for your main code. Otherwise MPLAB, will try to compile each file _separately_, which will cause this error

Otherwise almost certainly something in the order of things.

Generally code must be met in the following order:
Include processor file
Fuses
clock statement
#pin selects
I/O setups (#use RS232, I2C etc)
Only then the #includes for things like USB
Then the code

Perfectly OK for these to be themselves included in other files, but you need to check that if you 'walked' through the main file, and loaded other files as you meet them, that this is how the things would be met...
Zardoz



Joined: 10 May 2010
Posts: 8
Location: Germany

View user's profile Send private message

PostPosted: Thu Apr 27, 2017 9:47 am     Reply with quote

Thank you for the rapid support Very Happy

Ttelmah wrote:
Are you possibly compiling using MPLAB?.


Yes we compile with MPLab and since shortly with MPLabX.


Ttelmah wrote:
If so, you must ensure that the only file in the list of files to compile is the one for your main code. Otherwise MPLAB, will try to compile each file _separately_, which will cause this error


In the Source Files directory of the Projects window is only the main code.

Ttelmah wrote:
Otherwise almost certainly something in the order of things.

Generally code must be met in the following order:
Include processor file
Fuses
clock statement
#pin selects
I/O setups (#use RS232, I2C etc)
Only then the #includes for things like USB
Then the code


We use the ex8.c from the CCS exercise book, only the ccsusb.h is changed to the new processor type and its specific i/o pins. So the order of the code should be correct.

Quote:
Perfectly OK for these to be themselves included in other files, but you need to check that if you 'walked' through the main file, and loaded other files as you meet them, that this is how the things would be met...
Zardoz



Joined: 10 May 2010
Posts: 8
Location: Germany

View user's profile Send private message

PostPosted: Thu Apr 27, 2017 2:04 pm     Reply with quote

Ttelmah wrote:
If so, you must ensure that the only file in the list of files to compile is the one for your main code. Otherwise MPLAB, will try to compile each file _separately_, which will cause this error


In the Source Files directory of the Projects window was only the main code, but in the header files directory was also the usb.c file. I think this problem is solved. Thank you for yor help.
jeremiah



Joined: 20 Jul 2010
Posts: 1358

View user's profile Send private message

PostPosted: Thu Apr 27, 2017 2:51 pm     Reply with quote

If you are using mplabx (your earlier post indicated you are moving to it), you can actually have all the source files in your project structure as long as you go to the dialog that lets you mark them to be excluded from the build. I like doing it this way so I can easily open up all the files from the project view. They have an option to check all. I do that and then uncheck the main file.
Zardoz



Joined: 10 May 2010
Posts: 8
Location: Germany

View user's profile Send private message

PostPosted: Thu Apr 27, 2017 11:38 pm     Reply with quote

This idea seems to be good. Is it useful that the header files still remain in the Header Files directory?
jeremiah



Joined: 20 Jul 2010
Posts: 1358

View user's profile Send private message

PostPosted: Fri Apr 28, 2017 6:47 am     Reply with quote

The header files don't get compiled independently, so they should be fine in the headers directory.

I Usually put all my source files in the source directory, exclude all of them but the main from the build, then put all the headers in the headers directory.

Certainly not the only way to do it, as it is up to programmer preference.
Zardoz



Joined: 10 May 2010
Posts: 8
Location: Germany

View user's profile Send private message

PostPosted: Mon May 01, 2017 11:08 pm     Reply with quote

I want to build a bootloader with the PIC24FJ128GB204 with help of the ex_usb_bootloader.c example. But in the ex_usb.common.h there is no define for this PIC. Which other define should I use or which values in the required files have to be customized?
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Tue May 02, 2017 12:55 am     Reply with quote

The key letters in "ex_usb.common.h", are the 'ex'. _Example_.
They are not designed to be suitable for anything but the example use.

You need to start by working out what settings your actual program wants. Clock speed. PPS settings (though provided you select NOIOL1WAY, these can be changed after boot - however it is safer to make sure these are right). Peripheral settings like ALTI2C1 etc..
Get yourself the data sheet, and a bit bit of paper. Draw out what peripheral pins go where, what clocks have to be setup (remember these need to be compatible with the USB setup). Use the closest example as a 'partial crib', though remember that this will be setting things up for the particular demo board it is built for.
Remember that the fuses in the bootloader will need to match those that you intend to use in the program.
Once you have them clear in your mind, generate your own "your_project_name_fuses.h" file, and include this in your bootloader as the first thing after the processor include.

The fuses always depend on what you are wanting to actually do....
Zardoz



Joined: 10 May 2010
Posts: 8
Location: Germany

View user's profile Send private message

PostPosted: Tue May 02, 2017 9:45 am     Reply with quote

I have built a bootloader with the small demo board from CCS with the 18F45K50 onboard a year ago. It works fine untill today. Now I have set up a prototype board with the 24F128GB204. I had considered all the things that Ttelmah suggested, only the fuse NOIOL1WAY is new for me. I have the fuse integrated into the hardware header file.

If I start without pushing the button, a small programm gets the yellow led blinking, if I start pushing the button, the green led illuminates and the Device Manager of the PC shows the entry "unknown usb device (error by request the device description)". Connecting the old demo board, the device manager recognizes the "CCS CDC Bootlader (COM8)".

I have used the internal resonator and no extern crystal (the chip is able to synchronize with USB-Host).
Zardoz



Joined: 10 May 2010
Posts: 8
Location: Germany

View user's profile Send private message

PostPosted: Wed May 03, 2017 2:51 am     Reply with quote

The problem is solved. I had used the internal oscillator as it is descriped in the data sheet. With the hint of Darren Rook I took an external 20 MHz crystal instead and the PC connects to the prototype board and the device manager recognizes the CCS CDC Bootloader on Com 8.

But why doesn't the internal oscillator work correctly? In the data sheet of the 24F128GB204 is written: "USB Device mode Operation from FRC Oscillator: - No crystal oscillator required".
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Wed May 03, 2017 3:39 am     Reply with quote

The internal oscillator is accurate enough for low speed USB, but is not _in itself_ accurate enough for 'full speed'.

You have to enable the automatic clock tuning.

What it supports is that when you connect to the USB bus, it'll tune itself to match the speed of the bus, to give the required accuracy. This is 'ACT' (automatic clock tuning). You have to add the statement 'ACT=USB' to the clock setup line, which tells the compiler to add the settings so that when you connect to a USB bus, the clock is automatically 'tuned' by the bus.

If you look at the oscillator diagram (Fig 9-1), this is the connection into the FRC section on the left, "Reference from USB D+/D"

The ACT=USB setting sets the STSRC bit, to say 'tune from the USB'.
Zardoz



Joined: 10 May 2010
Posts: 8
Location: Germany

View user's profile Send private message

PostPosted: Wed May 03, 2017 4:12 am     Reply with quote

@ Ttelmah: Many thanks for the fast support. Very Happy

With the order "#use delay(int=8MHz, clock=32MHz, USB_FULL, act=USB)" taken from the ex_usb_common.h definded for the 24FJ64GC006 my prototype board works also fine without the extern oscillator.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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