chipKIT® Development Platform

Inspired by Arduino™

Trouble getting USB Bootloader working...

Created Fri, 02 Dec 2011 20:36:04 +0000 by Jacob Christ


Jacob Christ

Fri, 02 Dec 2011 20:36:04 +0000

I'm trying to get Rich's USB bootloader working and MPLAB X is complaining about nvm_operation_lib.c. I also notice that it is missing from the repo... I've found it on-line but I'm not sure it it is the correct version. Anyone know where to get the right version from?

Jacob


Jacob Christ

Sat, 03 Dec 2011 05:14:54 +0000

We found the missing files in the C32 directories that came with MPLAB X.

Jacob


Jacob Christ

Sat, 03 Dec 2011 22:08:21 +0000

Well, I've gotten the bootloader to enumerate and even talk to MPIDE but I'm getting an error when uploading.

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0180
         0x00 != 0xff
avrdude: verification error; content mismatch
avrdude: Send: . [1b] W [57] . [00] . [03] . [0e] . [11] . [01] . [01] P [50] 
avrdude: Recv: . [1b] 
avrdude: Recv: W [57] 
avrdude: Recv: . [00] 
avrdude: Recv: . [02] 
avrdude: Recv: . [0e] 
avrdude: Recv: . [11] 
avrdude: Recv: . [00] 
avrdude: Recv: Q [51] 

avrdude done.  Thank you.

I'm using PIC32MX440F512H (same as on the CUI32 board). I've also been using the CUI32 board when I compile.

Plugging away...

Jacob


Jacob Christ

Sat, 03 Dec 2011 23:14:29 +0000

The plot thickens...

I found a couple of things...

  1. On the WIKI I found this little blurb that sounds a lot like what I'm experiencing:

Avrdude: verification error; content mismatch There is a known issue with the PIC32MX3XX/4XX series parts that affects the flash programming timing.

I checked the repo for the serial bootloader and can find no reference as to when this was fixed.

  1. There exists (at least) two USB bootloader repositories.

This one appears to have the latest commits but the readme says its superseded by the second link below: https://github.com/rtestardi/PIC32-CDC-ACM-Stk500v2-Bootloader

https://github.com/chipKIT32/pic32-Arduino-USB-Bootloader


So it would be nice to understand if the bug listed above is in the USB bootloader.

Jacob


Mark

Sun, 04 Dec 2011 01:57:20 +0000

Jacob

Thanks for finding this, it was a simple oversight in the MPLAB-X project properties. It has been fixed and updated on github

Mark


Jacob Christ

Sun, 04 Dec 2011 02:42:13 +0000

There is an issue in avrbl_run(void) as well...

This code...

#ifndef PRGSWITCH
			// if we've been here too long without stk500v2 becoming active...
			if (loops >= AVRBL_LOOPS && !active)
			{
				// launch the application!
				jump_to_app();
			}
		#endif

should read...

#ifndef PRGSWITCH
			// if we've been here too long without stk500v2 becoming active...
			if (gLoops >= AVRBL_LOOPS && !gActive)
			{
				// launch the application!
				jump_to_app();
			}
		#endif

Jacob


Jacob Christ

Sun, 04 Dec 2011 06:02:48 +0000

After spending all day banging my head against the wall I finally got the USB Bootloader to work. My issue was an old issue that was only partially fixed (writing too fast to flash). When the issue was corrected is was done so for specific targets and not for the offending chips.

#if defined(_BOARD_MIKROE_MULTIMEDIA_) || defined(_BOARD_MIKROE_MIKROMEDIA_)
	#define _USE_WORD_WRITE_
#endif

I would suggest using chip defines rather than board defines, since the CUI32 uses a MX4 as well as the custom target I was trying to add. Instead the code might be better like this:

#if defined(__32MX440F512H__) || defined( ...list of all offending chips... )
	#define _USE_WORD_WRITE_
#endif

I'm specificlly using the PIC32MX440F512H, I'm not sure what chip are on the MIKROE MULTIMEDIA boards.

Jacob


Ernie

Mon, 14 May 2012 00:37:24 +0000

I'm trying to get Rich's USB bootloader working and MPLAB X is complaining about nvm_operation_lib.c. I also notice that it is missing from the repo... I've found it on-line but I'm not sure it it is the correct version. Anyone know where to get the right version from? Jacob

I am getting the same error with MPLAB X 1.10 and the C32 2.02.

Where did you get the missing file nvm_operation_lib.c from?

Or can someone link me a .hex of the bootloader I can install with a Picikit3?

For a 32MX795F512H


Jacob Christ

Mon, 14 May 2012 06:47:22 +0000

Where did you get the missing file nvm_operation_lib.c from?

I can't remember where I got it from but here it is:

/*********************************************************************
 *
 *                  NVM Operation Library Source
 *
 *********************************************************************
 * FileName:        nvm_operation_lib.c
 * Dependencies:
 * Processor:       PIC32
 *
 * Complier:        MPLAB C32
 *                  MPLAB IDE
 * Company:         Microchip Technology Inc..
 *
 * Software License Agreement
 *
 * The software supplied herewith by Microchip Technology Incorporated
 * (the “Company”) for its PIC32 Microcontroller is intended
 * and supplied to you, the Company’s customer, for use solely and
 * exclusively on Microchip PIC32 Microcontroller products.
 * The software is owned by the Company and/or its supplier, and is
 * protected under applicable copyright laws. All rights are reserved.
 * Any use in violation of the foregoing restrictions may subject the
 * user to criminal sanctions under applicable laws, as well as to
 * civil liability for the breach of the terms and conditions of this
 * license.
 *
 * THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES,
 * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
 * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
 * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
 * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
 *
 *
 * $Id: NVM.h,v 1.1 2006/10/16 20:30:29 C10737 Exp $
 * $Name: $
 *
 ********************************************************************/
#include <peripheral/nvm.h>
#include <peripheral/int.h>
#include <peripheral/dma.h>
#include <peripheral/lock.h>

unsigned int __attribute__((nomips16)) _NVMOperation(unsigned int nvmop)
{
    int	int_status;
    int	susp;

    // Disable DMA & Disable Interrupts
	#ifdef _DMAC
	int_status = INTDisableInterrupts();
	susp = DmaSuspend();
	#else
	int_status = INTDisableInterrupts(); 
	#endif	// _DMAC

    // Enable Flash Write/Erase Operations
    NVMCON = NVMCON_WREN | nvmop;

    NVMKEY 		= 0xAA996655;
    NVMKEY 		= 0x556699AA;
    NVMCONSET 	= NVMCON_WR;

    // Wait for WR bit to clear
    while(NVMCON & NVMCON_WR);

    // Disable Flash Write/Erase operations
    NVMCONCLR = NVMCON_WREN;

	// Enable DMA & Enable Interrupts
	#ifdef _DMAC
	DmaResume(susp);
	INTRestoreInterrupts(int_status);
	#else
	INTRestoreInterrupts(int_status);
	#endif // _DMAC

	// Return Error Status
    return(NVMIsError());
}