Uvision bin error

14 Jul 2011

I important this into Uvision trying to get a bin file but running into this error, does anybody know how to correct.

I understand what is going on just lack the knowledge of how to correct. I wanna try and get this publish for mbed as well.. as in importing it into the on line complier.

/*----------------------------------------------------------------------------
 * Name:    usbmain.c
 * Purpose: USB Audio Class Demo
 * Version: V1.20
 *----------------------------------------------------------------------------
 *      This software is supplied "AS IS" without any warranties, express,
 *      implied or statutory, including but not limited to the implied
 *      warranties of fitness for purpose, satisfactory quality and
 *      noninfringement. Keil extends you a royalty-free right to reproduce
 *      and distribute executable files created using this software for use
 *      on NXP Semiconductors LPC microcontroller devices only. Nothing else 
 *      gives you the right to use this software.
 *
 * Copyright (c) 2009 Keil - An ARM Company. All rights reserved.
 *---------------------------------------------------------------------------*/

#include "LPC17xx.h"                        /* LPC17xx definitions */
#include "type.h"

#include "usb.h"
#include "usbcfg.h"
#include "usbhw.h"
#include "usbcore.h"
#include "usbaudio.h"

uint8_t  Mute;                                 /* Mute State */
uint32_t Volume;                               /* Volume Level */

#if USB_DMA
uint32_t *InfoBuf = (uint32_t *)(DMA_BUF_ADR);
short *DataBuf = (short *)(DMA_BUF_ADR + 4*P_C);
#else
uint32_t InfoBuf[P_C];
short DataBuf[B_S];                         /* Data Buffer */
#endif

uint16_t  DataOut;                              /* Data Out Index */
uint16_t  DataIn;                               /* Data In Index */

uint8_t   DataRun;                              /* Data Stream Run State */
uint16_t  PotVal;                               /* Potenciometer Value */
uint32_t  VUM;                                  /* VU Meter */
uint32_t  Tick;                                 /* Time Tick */


/*
 * Get Potenciometer Value
 */

void get_potval (void) {
  uint32_t val;

  LPC_ADC->ADCR |= 0x01000000;              /* Start A/D Conversion */
  do {
    val = LPC_ADC->ADGDR;                   /* Read A/D Data Register */
  } while ((val & 0x80000000) == 0);        /* Wait for end of A/D Conversion */
  LPC_ADC->ADCR &= ~0x01000000;             /* Stop A/D Conversion */
  PotVal = ((val >> 8) & 0xF8) +            /* Extract Potenciometer Value */
           ((val >> 7) & 0x08);
}


/*
 * Timer Counter 0 Interrupt Service Routine
 *   executed each 31.25us (32kHz frequency)
 */

void TIMER0_IRQHandler(void) 
{
  long  val;
  uint32_t cnt;

  if (DataRun) {                            /* Data Stream is running */
    val = DataBuf[DataOut];                 /* Get Audio Sample */
    cnt = (DataIn - DataOut) & (B_S - 1);   /* Buffer Data Count */
    if (cnt == (B_S - P_C*P_S)) {           /* Too much Data in Buffer */
      DataOut++;                            /* Skip one Sample */
    }
    if (cnt > (P_C*P_S)) {                  /* Still enough Data in Buffer */
      DataOut++;                            /* Update Data Out Index */
    }
    DataOut &= B_S - 1;                     /* Adjust Buffer Out Index */
    if (val < 0) VUM -= val;                /* Accumulate Neg Value */
    else         VUM += val;                /* Accumulate Pos Value */
    val  *= Volume;                         /* Apply Volume Level */
    val >>= 16;                             /* Adjust Value */
    val  += 0x8000;                         /* Add Bias */
    val  &= 0xFFFF;                         /* Mask Value */
  } else {
    val = 0x8000;                           /* DAC Middle Point */
  }

  if (Mute) {
    val = 0x8000;                           /* DAC Middle Point */
  }

  LPC_DAC->DACR = val & 0xFFC0;             /* Set Speaker Output */

  if ((Tick++ & 0x03FF) == 0) {             /* On every 1024th Tick */
    get_potval();                           /* Get Potenciometer Value */
    if (VolCur == 0x8000) {                 /* Check for Minimum Level */
      Volume = 0;                           /* No Sound */
    } else {
      Volume = VolCur * PotVal;             /* Chained Volume Level */
    }
    val = VUM >> 20;                        /* Scale Accumulated Value */
    VUM = 0;                                /* Clear VUM */
    if (val > 7) val = 7;                   /* Limit Value */
  }

  LPC_TIM0->IR = 1;                         /* Clear Interrupt Flag */
}



/*****************************************************************************
**   Main Function  main()
******************************************************************************/
int main (void)
{
  volatile uint32_t pclkdiv, pclk;

  SystemInit();

  LPC_PINCON->PINSEL1 &=~((0x03<<18)|(0x03<<20));  
  /* P0.25, A0.0, function 01, P0.26 AOUT, function 10 */
  LPC_PINCON->PINSEL1 |= ((0x01<<18)|(0x02<<20));

  /* Enable CLOCK into ADC controller */
  LPC_SC->PCONP |= (1 << 12);

  LPC_ADC->ADCR = 0x00200E04;		/* ADC: 10-bit AIN2 @ 4MHz */
  LPC_DAC->DACR = 0x00008000;		/* DAC Output set to Middle Point */

  /* By default, the PCLKSELx value is zero, thus, the PCLK for
  all the peripherals is 1/4 of the SystemFrequency. */
  /* Bit 2~3 is for TIMER0 */
  pclkdiv = (LPC_SC->PCLKSEL0 >> 2) & 0x03;
  switch ( pclkdiv )
  {
	case 0x00:
	default:
	  pclk = SystemFrequency/4;
	break;
	case 0x01:
	  pclk = SystemFrequency;
	break; 
	case 0x02:
	  pclk = SystemFrequency/2;
	break; 
	case 0x03:
	  pclk = SystemFrequency/8;
	break;
  }

  LPC_TIM0->MR0 = pclk/DATA_FREQ - 1;	/* TC0 Match Value 0 */
  LPC_TIM0->MCR = 3;					/* TCO Interrupt and Reset on MR0 */
  LPC_TIM0->TCR = 1;					/* TC0 Enable */
  NVIC_EnableIRQ(TIMER0_IRQn);

  USB_Init();				/* USB Initialization */
  USB_Connect(TRUE);		/* USB Connect */

  /********* The main Function is an endless loop ***********/ 
  while( 1 ); 
}

/******************************************************************************
**                            End Of File
******************************************************************************/

/media/uploads/mbed2f/code.bundle.lpc17xx.keil.zip

Build target 'mbed NXP LPC1768' compiling usbdmain.c... ..\..\..\code.bundle.lpc17xx.keil\LPC17xxSampleSoftware.102\keil\USBAudio\usbdmain.c(143): error: #20: identifier "SystemFrequency" is undefined Target not created

14 Jul 2011

Try rename the SystemFrequency to SystemCoreFrequency. Look in the "LPC17xx.h" for the correct name, I think it's in there. It's part of the CMSIS library

14 Jul 2011

This is the file it is link to, it looks ok? I will try the systemcore in a min

/******************************************************************************
 * @file:    system_LPC17xx.h
 * @purpose: CMSIS Cortex-M3 Device Peripheral Access Layer Header File
 *           for the NXP LPC17xx Device Series 
 * @version: V1.01
 * @date:    22. Jul. 2009
 *----------------------------------------------------------------------------
 *
 * Copyright (C) 2009 ARM Limited. All rights reserved.
 *
 * ARM Limited (ARM) is supplying this software for use with Cortex-M3 
 * processor based microcontrollers.  This file can be freely distributed 
 * within development tools that are supporting such ARM based processors. 
 *
 * THIS SOFTWARE IS PROVIDED "AS IS".  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.
 * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
 * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
 *
 ******************************************************************************/


#ifndef __SYSTEM_LPC17xx_H
#define __SYSTEM_LPC17xx_H

#ifdef __cplusplus
 extern "C" {
#endif 

extern uint32_t SystemFrequency;    /*!< System Clock Frequency (Core Clock)  */


/**
 * Initialize the system
 *
 * @param  none
 * @return none
 *
 * @brief  Setup the microcontroller system.
 *         Initialize the System and update the SystemFrequency variable.
 */
extern void SystemInit (void);

#ifdef __cplusplus
}
#endif

#endif /* __SYSTEM_LPC17xx_H */
14 Jul 2011

oh, i see. It's SystemFrequency alright. You need to add the CMSIS library (.lib) to the project. I have not uvision so can't show you how.

14 Jul 2011

Yoko Hama wrote:

oh, i see. It's SystemFrequency alright. You need to add the CMSIS library (.lib) to the project. I have not uvision so can't show you how.

Am I missing something else .. LPC SC is define in LPCxx.h

Build target 'mbed NXP LPC1768' compiling usbdmain.c... .\mbed\LPC1768\system_LPC17xx.h(427): error: #20: identifier "LPC_SC" is undefined .\mbed\LPC1768\system_LPC17xx.h(478): error: #20: identifier "LPC_SC" is undefined .\mbed\LPC1768\system_lpc17xx.h(418): error: #148: variable "SystemCoreClock" has already been initialized .\mbed\LPC1768\system_lpc17xx.h(424): error: #247: function "SystemCoreClockUpdate" has already been defined .\mbed\LPC1768\system_lpc17xx.h(475): error: #247: function "SystemInit" has already been defined compiling usbhw.c... .\mbed\LPC1768\system_LPC17xx.h(427): error: #20: identifier "LPC_SC" is undefined .\mbed\LPC1768\system_LPC17xx.h(478): error: #20: identifier "LPC_SC" is undefined compiling system_LPC17xx.c... .\mbed\LPC1768\system_LPC17xx.h(427): error: #20: identifier "LPC_SC" is undefined .\mbed\LPC1768\system_LPC17xx.h(478): error: #20: identifier "LPC_SC" is undefined system_LPC17xx.c(418): error: #148: variable "SystemCoreClock" has already been initialized system_LPC17xx.c(424): error: #247: function "SystemCoreClockUpdate" has already been defined system_LPC17xx.c(475): error: #247: function "SystemInit" has already been defined Target not created

/******************************************************************************/
/*                         Peripheral declaration                             */
/******************************************************************************/
#define LPC_SC                ((LPC_SC_TypeDef        *) LPC_SC_BASE       )
#define LPC_GPIO0             ((LPC_GPIO_TypeDef      *) LPC_GPIO0_BASE    )
#define LPC_GPIO1             ((LPC_GPIO_TypeDef      *) LPC_GPIO1_BASE    )
#define LPC_GPIO2             ((LPC_GPIO_TypeDef      *) LPC_GPIO2_BASE    )
#define LPC_GPIO3             ((LPC_GPIO_TypeDef      *) LPC_GPIO3_BASE    )
#define LPC_GPIO4             ((LPC_GPIO_TypeDef      *) LPC_GPIO4_BASE    )
#define LPC_WDT               ((LPC_WDT_TypeDef       *) LPC_WDT_BASE      )
#define LPC_TIM0              ((LPC_TIM_TypeDef       *) LPC_TIM0_BASE     )
#define LPC_TIM1              ((LPC_TIM_TypeDef       *) LPC_TIM1_BASE     )
#define LPC_TIM2              ((LPC_TIM_TypeDef       *) LPC_TIM2_BASE     )
#define LPC_TIM3              ((LPC_TIM_TypeDef       *) LPC_TIM3_BASE     )
#define LPC_RIT               ((LPC_RIT_TypeDef       *) LPC_RIT_BASE      )
#define LPC_UART0             ((LPC_UART0_TypeDef     *) LPC_UART0_BASE    )
#define LPC_UART1             ((LPC_UART1_TypeDef     *) LPC_UART1_BASE    )
#define LPC_UART2             ((LPC_UART_TypeDef      *) LPC_UART2_BASE    )
#define LPC_UART3             ((LPC_UART_TypeDef      *) LPC_UART3_BASE    )
#define LPC_PWM1              ((LPC_PWM_TypeDef       *) LPC_PWM1_BASE     )
#define LPC_I2C0              ((LPC_I2C_TypeDef       *) LPC_I2C0_BASE     )
#define LPC_I2C1              ((LPC_I2C_TypeDef       *) LPC_I2C1_BASE     )
#define LPC_I2C2              ((LPC_I2C_TypeDef       *) LPC_I2C2_BASE     )
#define LPC_I2S               ((LPC_I2S_TypeDef       *) LPC_I2S_BASE      )
#define LPC_SPI               ((LPC_SPI_TypeDef       *) LPC_SPI_BASE      )
#define LPC_RTC               ((LPC_RTC_TypeDef       *) LPC_RTC_BASE      )
#define LPC_GPIOINT           ((LPC_GPIOINT_TypeDef   *) LPC_GPIOINT_BASE  )
#define LPC_PINCON            ((LPC_PINCON_TypeDef    *) LPC_PINCON_BASE   )
#define LPC_SSP0              ((LPC_SSP_TypeDef       *) LPC_SSP0_BASE     )
#define LPC_SSP1              ((LPC_SSP_TypeDef       *) LPC_SSP1_BASE     )
#define LPC_ADC               ((LPC_ADC_TypeDef       *) LPC_ADC_BASE      )
#define LPC_DAC               ((LPC_DAC_TypeDef       *) LPC_DAC_BASE      )
#define LPC_CANAF_RAM         ((LPC_CANAF_RAM_TypeDef *) LPC_CANAF_RAM_BASE)
#define LPC_CANAF             ((LPC_CANAF_TypeDef     *) LPC_CANAF_BASE    )
#define LPC_CANCR             ((LPC_CANCR_TypeDef     *) LPC_CANCR_BASE    )
#define LPC_CAN1              ((LPC_CAN_TypeDef       *) LPC_CAN1_BASE     )
#define LPC_CAN2              ((LPC_CAN_TypeDef       *) LPC_CAN2_BASE     )
#define LPC_MCPWM             ((LPC_MCPWM_TypeDef     *) LPC_MCPWM_BASE    )
#define LPC_QEI               ((LPC_QEI_TypeDef       *) LPC_QEI_BASE      )
#define LPC_EMAC              ((LPC_EMAC_TypeDef      *) LPC_EMAC_BASE     )
#define LPC_GPDMA             ((LPC_GPDMA_TypeDef     *) LPC_GPDMA_BASE    )
#define LPC_GPDMACH0          ((LPC_GPDMACH_TypeDef   *) LPC_GPDMACH0_BASE )
#define LPC_GPDMACH1          ((LPC_GPDMACH_TypeDef   *) LPC_GPDMACH1_BASE )
#define LPC_GPDMACH2          ((LPC_GPDMACH_TypeDef   *) LPC_GPDMACH2_BASE )
#define LPC_GPDMACH3          ((LPC_GPDMACH_TypeDef   *) LPC_GPDMACH3_BASE )
#define LPC_GPDMACH4          ((LPC_GPDMACH_TypeDef   *) LPC_GPDMACH4_BASE )
#define LPC_GPDMACH5          ((LPC_GPDMACH_TypeDef   *) LPC_GPDMACH5_BASE )
#define LPC_GPDMACH6          ((LPC_GPDMACH_TypeDef   *) LPC_GPDMACH6_BASE )
#define LPC_GPDMACH7          ((LPC_GPDMACH_TypeDef   *) LPC_GPDMACH7_BASE )
#define LPC_USB               ((LPC_USB_TypeDef       *) LPC_USB_BASE      )



#endif  // __LPC17xx_H__

14 Jul 2011

I think you might have 2 different version of the CMSIS library installed. Check in the include path settings and make sure that all Path for CMSIS point to the same one. Check also to see if you have a local version of the LCP17xx.h. Make sure it that there are no conflicts.

I use CodeRed the project folders are as follow :

/WorkingFolder
     +- CMSISv2p00_LPC17xx
     +- MyProject

As I know the CMSIS from CodeRed uses SystemCoreClock instead of SystemFrequency. The standard CMSIS lib is SystemFrequency.

14 Jul 2011

Yoko Hama wrote:

I think you might have 2 different version of the CMSIS library installed. Check in the include path settings and make sure that all Path for CMSIS point to the same one. Check also to see if you have a local version of the LCP17xx.h. Make sure it that there are no conflicts.

I use CodeRed the project folders are as follow :

/WorkingFolder
     +- CMSISv2p00_LPC17xx
     +- MyProject

As I know the CMSIS from CodeRed uses SystemCoreClock instead of SystemFrequency. The standard CMSIS lib is SystemFrequency.

I try again and I am getting this now, I will try what you say tho and report back:)

Build target 'mbed NXP LPC1768' compiling usbdmain.c... linking... .\build\Blinky.axf: Error: L6218E: Undefined symbol vtable for cxxabiv1::class_type_info (referred from stdio.cpp.lpc1768.arm.o). .\build\Blinky.axf: Error: L6218E: Undefined symbol vtable for cxxabiv1::si_class_type_info (referred from stdio.cpp.lpc1768.arm.o). .\build\Blinky.axf: Error: L6218E: Undefined symbol vtable for cxxabiv1::vmi_class_type_info (referred from stdio.cpp.lpc1768.arm.o). .\build\Blinky.axf: Error: L6218E: Undefined symbol operator delete (void*) (referred from stdio.cpp.lpc1768.arm.o). .\build\Blinky.axf: Error: L6218E: Undefined symbol cxa_pure_virtual (referred from stdio.cpp.lpc1768.arm.o). .\build\Blinky.axf: Error: L6218E: Undefined symbol dynamic_cast (referred from stdio.cpp.lpc1768.arm.o). .\build\Blinky.axf: Error: L6218E: Undefined symbol operator delete[] (void*) (referred from Base.cpp.lpc1768.arm.o). .\build\Blinky.axf: Error: L6218E: Undefined symbol operator new[] (unsigned) (referred from Base.cpp.lpc1768.arm.o). .\build\Blinky.axf: Error: L6218E: Undefined symbol operator new(unsigned) (referred from Base.cpp.lpc1768.arm.o). Target not created

14 Jul 2011

Looks like you have mixed projects together usb & blinky. usbmain.c is a C project and Blinky is a C++ project. You cannot use usbmain.c (C code) with other C++ source code. To use C++ source you need to convert your usbmain.c to usbmain.cpp and the project has to be a C++ project. C++ project has other startup code & library require. C++ project can have C code in it but C project cannot have C++ code.

16 Jul 2011

I don't think I was not using the blinky files with this anyway.. I was just using the project file or how ever it is set up to be use with uvision....

I was using this guide and then just adding the usb files to the src file I must I have added C++ files or C by mistake but trying to get focused on it...

I think maybe reprogramming is needed for this tho not sure...

http://mbed.org/forum/mbed/topic/1932/

16 Jul 2011

I think it's better create a new project and add source code in.

The errors showed that you are compiling Blinky project. So there may be a mix project & source somewhere

16 Jul 2011

I was using the src file so I could get a bin file because I don't know how to set up to get a bin file... and I can only get a hex file with the usbaudio project.

So I would do what you say but I don't know how to.

16 Jul 2011

I don't have uvision so cannot help you on that. Your best bet is to post questions on Keil support forum.

16 Jul 2011

I need a C LPC17xx header file you know where there is one.

16 Jul 2011
16 Jul 2011

What is your thinking or thoughts of me using this you will have to explain what you think I can do with eclipse. They banned coffee today how dare they:(

16 Jul 2011

Sooo... I thought I would be posh and brought a organic beer:) oooh I do say:) silicon that makes it atomic number 14:)

16 Jul 2011

Well, you had so much trouble with uvision so I though may be the instruction there could help. It shows you step by step to create & build offline project. Although it's Eclipse, at least you can compile a project and it's free. uvision is a commercial and very expensive ide. If you have a uvision license, then ask keil supports. They'll help you to setup your project properly. You can also buy a LPCXpresso board ($30). It comes with a free limited license of CodeRed (also Eclipse).

16 Jul 2011

Yoko Hama wrote:

Well, you had so much trouble with uvision so I though may be the instruction there could help. It shows you step by step to create & build offline project. Although it's Eclipse, at least you can compile a project and it's free. uvision is a commercial and very expensive ide. If you have a uvision license, then ask keil supports. They'll help you to setup your project properly. You can also buy a LPCXpresso board ($30). It comes with a free limited license of CodeRed (also Eclipse).

Yes I have LPCXpresso board and the free IDE... but I have the free IDE uvision with the 32K code limit and when programming in especial in Assembly Language, you will never probably need more than that:)

hmm... you see at the moment I can not program my way out of a paper bag.. So all I am trying to do here is create a bin out of the files.. you think this is not to diffucult with Eclipse then.. I have messed with Eclipse before tho:)

18 Jul 2011

Here is usb file you can test hopefully it should work..

/media/uploads/mbed2f/usbaudio.bin

Well we did it:) can not test bin file yet.. because I don't think it safe to just connect the output of the usb port of my laptop to the cool components board I have... it does not have any regulators on it:)

19 Jul 2011

Well good news it works need to published it because it now turns mbed into a media device.. you just plug it in with usb B or A whatever you choice.. I use the cool components board..

I need to write page...

20 Jul 2011

do you know how I could add this

Function to power down magic USB interface chip with new firmware

  1. define USR_POWERDOWN (0x104) int semihost_powerdown() { uint32_t arg; return semihost(USR_POWERDOWN, &arg); }

int main() { int result;

}

..\..\..\..\mbednew\main.cpp(8): error: #20: identifier "uint32_t" is undefined ..\..\..\..\mbednew\main.cpp(14): warning: #177-D: variable "result" was declared but never referenced Target not created

20 Jul 2011

How do I edit the object files to stop it been defined multiply times

Build target 'Flash' compiling main.cpp... ..\..\..\..\mbednew\main.cpp(15): warning: #177-D: variable "result" was declared but never referenced linking... .\Obj\usbaudio.axf: Error: L6200E: Symbol semihost_powerdown multiply defined (by usbcore.o and usbuser.o). .\Obj\usbaudio.axf: Error: L6200E: Symbol semihost_powerdown multiply defined (by usbdesc.o and usbuser.o). .\Obj\usbaudio.axf: Error: L6200E: Symbol semihost_powerdown multiply defined (by usbdmain.o and usbuser.o). .\Obj\usbaudio.axf: Error: L6200E: Symbol semihost_powerdown multiply defined (by usbhw.o and usbuser.o). .\Obj\usbaudio.axf: Error: L6200E: Symbol semihost_powerdown multiply defined (by adcuser.o and usbuser.o). .\Obj\usbaudio.axf: Error: L6200E: Symbol ARM_use_no_argv multiply defined (by main.o and usbdmain.o). .\Obj\usbaudio.axf: Error: L6200E: Symbol main multiply defined (by main.o and usbdmain.o). Target not created

20 Jul 2011

can you show the code how that function is define ? It looks like you put the function definition in a .h file

21 Jul 2011

Yoko Hama wrote:

can you show the code how that function is define ? It looks like you put the function definition in a .h file

This is it then I am linking it to the lpc17xx.h libs for the semihost_powerdown, but it seems to be define in all them other object files?

I can't remember what I was linking it too, I found it and now have lost it.. but it was link right yesturday.

#include "lpc17xx.h"


// Function to power down magic USB interface chip with new firmware
#define USR_POWERDOWN    (0x104)
int semihost_powerdown() {
    uint32_t arg;
    return __semihost(USR_POWERDOWN, &arg);
}


int main() {
    int result;
    
    }
21 Jul 2011

Philips Philips wrote:

Yoko Hama wrote:

can you show the code how that function is define ? It looks like you put the function definition in a .h file

This is it then I am linking it to the lpc17xx.h libs for the semihost_powerdown, but it seems to be define in all them other object files?

I can't remember what I was linking it too, I found it and now have lost it.. but it was link right yesturday. I don't think semihost_powerdown is in lpc17xx.h

#include "lpc17xx.h"


// Function to power down magic USB interface chip with new firmware
#define USR_POWERDOWN    (0x104)
int semihost_powerdown() {
    uint32_t arg;
    return __semihost(USR_POWERDOWN, &arg);
}


int main() {
    int result;
    
    }

21 Jul 2011

How do I fix then Yoko

Build target 'Flash' linking... .\Obj\usbaudio.axf: Error: L6200E: Symbol ARM_use_no_argv multiply defined (by low.o and usbdmain.o). .\Obj\usbaudio.axf: Error: L6200E: Symbol main multiply defined (by low.o and usbdmain.o). Target not created

#include "lpc17xx.h"
//#include "PowerControl/PowerControl.h"
//#include "PowerControl/EthernetPowerControl.h"

// Function to power down magic USB interface chip with new firmware
#define USR_POWERDOWN    (0x104)
int semihost_powerdown() { uint32_t arg;
    return __semihost(USR_POWERDOWN, &arg);
}


int main() {
    int result;
    
    }

I have added uint32_t arg; to lpc17xx.h

21 Jul 2011

the last error said that you have main() defined in both usbmain.c and low.c. You have to remove one of them.

I don't quite understand what you tried to do with the #define USR_POWERDOWN ? From the look at it, every time you use that constant it will generate a copy of the semihost_powerdown function. Hence your previous errors.

22 Jul 2011

I got bin created but I can not get the code to work where is this code linked to in the mbed library

#include "lpc17xx.h"


// Function to power down magic USB interface chip with new firmware
#define USR_POWERDOWN    (0x104)
int semihost_powerdown() {
    uint32_t arg;
    return __semihost(USR_POWERDOWN, &arg);
}


int main() {
    int result;
    
    }

This is how I have manged to add to the code of usb audio

/*----------------------------------------------------------------------------
 * Name:    usbmain.c
 * Purpose: USB Audio Class Demo
 * Version: V1.20
 *----------------------------------------------------------------------------
 *      This software is supplied "AS IS" without any warranties, express,
 *      implied or statutory, including but not limited to the implied
 *      warranties of fitness for purpose, satisfactory quality and
 *      noninfringement. Keil extends you a royalty-free right to reproduce
 *      and distribute executable files created using this software for use
 *      on NXP Semiconductors LPC microcontroller devices only. Nothing else 
 *      gives you the right to use this software.
 *
 * Copyright (c) 2009 Keil - An ARM Company. All rights reserved.
 *---------------------------------------------------------------------------*/

#include "LPC17xx.h"                        /* LPC17xx definitions */
#include "type.h"

#include "usb.h"
#include "usbcfg.h"
#include "usbhw.h"
#include "usbcore.h"
#include "usbaudio.h"

#define USR_POWERDOWN    (0x104)

uint8_t  Mute;                                 /* Mute State */
uint32_t Volume;                               /* Volume Level */

#if USB_DMA
uint32_t *InfoBuf = (uint32_t *)(DMA_BUF_ADR);
short *DataBuf = (short *)(DMA_BUF_ADR + 4*P_C);
#else
uint32_t InfoBuf[P_C];
short DataBuf[B_S];                         /* Data Buffer */
#endif

uint16_t  DataOut;                              /* Data Out Index */
uint16_t  DataIn;                               /* Data In Index */

uint8_t   DataRun;                              /* Data Stream Run State */
uint16_t  PotVal;                               /* Potenciometer Value */
uint32_t  VUM;                                  /* VU Meter */
uint32_t  Tick;                                 /* Time Tick */
uint32_t arg;

int semihost_powerdown() {
    uint32_t arg;
    return __semihost(USR_POWERDOWN, &arg);
}


/*
 * Get Potenciometer Value
 */

void get_potval (void) {
  uint32_t val;

  LPC_ADC->ADCR |= 0x01000000;              /* Start A/D Conversion */
  do {
    val = LPC_ADC->ADGDR;                   /* Read A/D Data Register */
  } while ((val & 0x80000000) == 0);        /* Wait for end of A/D Conversion */
  LPC_ADC->ADCR &= ~0x01000000;             /* Stop A/D Conversion */
  PotVal = ((val >> 8) & 0xF8) +            /* Extract Potenciometer Value */
           ((val >> 7) & 0x08);
}


/*
 * Timer Counter 0 Interrupt Service Routine
 *   executed each 31.25us (32kHz frequency)
 */

void TIMER0_IRQHandler(void) 
{
  long  val;
  uint32_t cnt;

  if (DataRun) {                            /* Data Stream is running */
    val = DataBuf[DataOut];                 /* Get Audio Sample */
    cnt = (DataIn - DataOut) & (B_S - 1);   /* Buffer Data Count */
    if (cnt == (B_S - P_C*P_S)) {           /* Too much Data in Buffer */
      DataOut++;                            /* Skip one Sample */
    }
    if (cnt > (P_C*P_S)) {                  /* Still enough Data in Buffer */
      DataOut++;                            /* Update Data Out Index */
    }
    DataOut &= B_S - 1;                     /* Adjust Buffer Out Index */
    if (val < 0) VUM -= val;                /* Accumulate Neg Value */
    else         VUM += val;                /* Accumulate Pos Value */
    val  *= Volume;                         /* Apply Volume Level */
    val >>= 16;                             /* Adjust Value */
    val  += 0x8000;                         /* Add Bias */
    val  &= 0xFFFF;                         /* Mask Value */
  } else {
    val = 0x8000;                           /* DAC Middle Point */
  }

  if (Mute) {
    val = 0x8000;                           /* DAC Middle Point */
  }

  LPC_DAC->DACR = val & 0xFFC0;             /* Set Speaker Output */

  if ((Tick++ & 0x03FF) == 0) {             /* On every 1024th Tick */
    get_potval();                           /* Get Potenciometer Value */
    if (VolCur == 0x8000) {                 /* Check for Minimum Level */
      Volume = 0;                           /* No Sound */
    } else {
      Volume = VolCur * PotVal;             /* Chained Volume Level */
    }
    val = VUM >> 20;                        /* Scale Accumulated Value */
    VUM = 0;                                /* Clear VUM */
    if (val > 7) val = 7;                   /* Limit Value */
  }

  LPC_TIM0->IR = 1;                         /* Clear Interrupt Flag */
}



/*****************************************************************************
**   Main Function  main()
******************************************************************************/
int main (void)
{
  volatile uint32_t pclkdiv, pclk;

  SystemInit();

  LPC_PINCON->PINSEL1 &=~((0x03<<18)|(0x03<<20));  
  /* P0.25, A0.0, function 01, P0.26 AOUT, function 10 */
  LPC_PINCON->PINSEL1 |= ((0x01<<18)|(0x02<<20));

  /* Enable CLOCK into ADC controller */
  LPC_SC->PCONP |= (1 << 12);

  LPC_ADC->ADCR = 0x00200E04;		/* ADC: 10-bit AIN2 @ 4MHz */
  LPC_DAC->DACR = 0x00008000;		/* DAC Output set to Middle Point */

  /* By default, the PCLKSELx value is zero, thus, the PCLK for
  all the peripherals is 1/4 of the SystemFrequency. */
  /* Bit 2~3 is for TIMER0 */
  pclkdiv = (LPC_SC->PCLKSEL0 >> 2) & 0x03;
  switch ( pclkdiv )
  {
	case 0x00:
	default:
	  pclk = SystemFrequency/4;
	break;
	case 0x01:
	  pclk = SystemFrequency;
	break; 
	case 0x02:
	  pclk = SystemFrequency/2;
	break; 
	case 0x03:
	  pclk = SystemFrequency/8;
	break;
  }

  LPC_TIM0->MR0 = pclk/DATA_FREQ - 1;	/* TC0 Match Value 0 */
  LPC_TIM0->MCR = 3;					/* TCO Interrupt and Reset on MR0 */
  LPC_TIM0->TCR = 1;					/* TC0 Enable */
  NVIC_EnableIRQ(TIMER0_IRQn);

  USB_Init();				/* USB Initialization */
  USB_Connect(TRUE);		/* USB Connect */

  /********* The main Function is an endless loop ***********/ 
  while( 1 ); 
}
int result;
/******************************************************************************
**                            End Of File
******************************************************************************/
24 Jul 2011

I have not been able to get it working properly yet. I can not find what LEDMSK is use for in the whole of the code..the zip file. I know what it does.. it enables the led 1 and then turns it off once the usb is reconsigned

I am trying to find the code which is use for that function .. LEDMSK and then add the semihost_powerdown to it.

I got it this to work but crashes the code it turn off the usb led but crashes somewhat.

if (Mute){ semihost_powerdown();}

this is where if LEDMSK

/*--------------------------------------------------------------------------
 *      Name:    usbaudio.h
 *      Purpose: USB Audio Demo Definitions
 *      Version: V1.10
 *----------------------------------------------------------------------------
 *      This software is supplied "AS IS" without any warranties, express,
 *      implied or statutory, including but not limited to the implied
 *      warranties of fitness for purpose, satisfactory quality and
 *      noninfringement. Keil extends you a royalty-free right to reproduce
 *      and distribute executable files created using this software for use
 *      on NXP Semiconductors LPC family microcontroller devices only. Nothing 
 *      else gives you the right to use this software.
 *
 * Copyright (c) 2009 Keil - An ARM Company. All rights reserved.
 *---------------------------------------------------------------------------*/

/* Audio Definitions */
#define DATA_FREQ 32000                 /* Audio Data Frequency */
#define P_S       32                    /* Packet Size */
#if USB_DMA
#define P_C       4                     /* Packet Count */
#else
#define P_C       1                     /* Packet Count */
#endif
#define B_S       (8*P_C*P_S)           /* Buffer Size */

/* Push Button Definitions */
// #define PBINT     0x00004000            /* P0.14 */

/* LED Definitions */
#define LEDMSK    0x000000FF            /* P2.0..7 */

/* Audio Demo Variables */
extern uint8_t  Mute;                      /* Mute State */
extern uint32_t Volume;                    /* Volume Level */
extern uint16_t  VolCur;                    /* Volume Current Value */
#if !USB_DMA
extern uint32_t InfoBuf[P_C];              /* Packet Info Buffer */
extern short DataBuf[B_S];              /* Data Buffer */
#else
extern uint32_t *InfoBuf;
extern short *DataBuf;
#endif
extern uint16_t  DataOut;                   /* Data Out Index */
extern uint16_t  DataIn;                    /* Data In Index */
extern uint8_t   DataRun;                   /* Data Stream Run State */

This is the code crashes but usb LED goes off

/*----------------------------------------------------------------------------
 * Name:    usbmain.c
 * Purpose: USB Audio Class Demo
 * Version: V1.20
 *----------------------------------------------------------------------------
 *      This software is supplied "AS IS" without any warranties, express,
 *      implied or statutory, including but not limited to the implied
 *      warranties of fitness for purpose, satisfactory quality and
 *      noninfringement. Keil extends you a royalty-free right to reproduce
 *      and distribute executable files created using this software for use
 *      on NXP Semiconductors LPC microcontroller devices only. Nothing else 
 *      gives you the right to use this software.
 *
 * Copyright (c) 2009 Keil - An ARM Company. All rights reserved.
 *---------------------------------------------------------------------------*/

#include "LPC17xx.h"                        /* LPC17xx definitions */
#include "type.h"

#include "usb.h"
#include "usbcfg.h"
#include "usbhw.h"
#include "usbcore.h"
#include "usbaudio.h"




uint8_t  Mute;                                 /* Mute State */
uint32_t Volume;                               /* Volume Level */

#if USB_DMA
uint32_t *InfoBuf = (uint32_t *)(DMA_BUF_ADR);
short *DataBuf = (short *)(DMA_BUF_ADR + 4*P_C);
#else
uint32_t InfoBuf[P_C];
short DataBuf[B_S];                         /* Data Buffer */
#endif

uint16_t  DataOut;                              /* Data Out Index */
uint16_t  DataIn;                               /* Data In Index */

uint8_t   DataRun;                              /* Data Stream Run State */
uint16_t  PotVal;                               /* Potenciometer Value */
uint32_t  VUM;                                  /* VU Meter */
uint32_t  Tick;                                 /* Time Tick */
uint32_t arg;
//uint32_t  con;
//uint32_t  power;

int semihost_powerdown() {
    uint32_t arg;
    return __semihost(USR_POWERDOWN, &arg);
}


/*
 * Get Potenciometer Value
 */

void get_potval (void) {
  uint32_t val;

  LPC_ADC->ADCR |= 0x01000000;              /* Start A/D Conversion */
  do {
    val = LPC_ADC->ADGDR;                   /* Read A/D Data Register */
  } while ((val & 0x80000000) == 0);        /* Wait for end of A/D Conversion */
  LPC_ADC->ADCR &= ~0x01000000;             /* Stop A/D Conversion */
  PotVal = ((val >> 8) & 0xF8) +            /* Extract Potenciometer Value */
           ((val >> 7) & 0x08);
}


/*
 * Timer Counter 0 Interrupt Service Routine
 *   executed each 31.25us (32kHz frequency)
 */

void TIMER0_IRQHandler(void) 
{
  long  val;
  uint32_t cnt;

  if (DataRun) {                            /* Data Stream is running */
    val = DataBuf[DataOut];                 /* Get Audio Sample */
    cnt = (DataIn - DataOut) & (B_S - 1);   /* Buffer Data Count */
    if (cnt == (B_S - P_C*P_S)) {           /* Too much Data in Buffer */
      DataOut++;                            /* Skip one Sample */
    }
    if (cnt > (P_C*P_S)) {                  /* Still enough Data in Buffer */
      DataOut++;                            /* Update Data Out Index */
    }
    DataOut &= B_S - 1;                     /* Adjust Buffer Out Index */
    if (val < 0) VUM -= val;                /* Accumulate Neg Value */
    else         VUM += val;                /* Accumulate Pos Value */
    val  *= Volume;                         /* Apply Volume Level */
    val >>= 16;                             /* Adjust Value */
    val  += 0x8000;                         /* Add Bias */
    val  &= 0xFFFF;                         /* Mask Value */
  } else {
    val = 0x8000;                           /* DAC Middle Point */
  }

  if (Mute) {
    val = 0x8000;                           /* DAC Middle Point */
  }
  if (Mute){
semihost_powerdown();}


  LPC_DAC->DACR = val & 0xFFC0;             /* Set Speaker Output */

  if ((Tick++ & 0x03FF) == 0) {             /* On every 1024th Tick */
    get_potval();                           /* Get Potenciometer Value */
    if (VolCur == 0x8000) {                 /* Check for Minimum Level */
      Volume = 0;                           /* No Sound */
    } else {
      Volume = VolCur * PotVal;             /* Chained Volume Level */
    }
    val = VUM >> 20;                        /* Scale Accumulated Value */
    VUM = 0;                                /* Clear VUM */
    if (val > 7) val = 7;                   /* Limit Value */
  }

  LPC_TIM0->IR = 1;                         /* Clear Interrupt Flag */
}



/*****************************************************************************
**   Main Function  main()
******************************************************************************/
int main (void)
{
  volatile uint32_t pclkdiv, pclk;

  SystemInit();

  LPC_PINCON->PINSEL1 &=~((0x03<<18)|(0x03<<20));  
  /* P0.25, A0.0, function 01, P0.26 AOUT, function 10 */
  LPC_PINCON->PINSEL1 |= ((0x01<<18)|(0x02<<20));

  /* Enable CLOCK into ADC controller */
  LPC_SC->PCONP |= (1 << 12);

  LPC_ADC->ADCR = 0x00200E04;		/* ADC: 10-bit AIN2 @ 4MHz */
  LPC_DAC->DACR = 0x00008000;		/* DAC Output set to Middle Point */

  /* By default, the PCLKSELx value is zero, thus, the PCLK for
  all the peripherals is 1/4 of the SystemFrequency. */
  /* Bit 2~3 is for TIMER0 */
  pclkdiv = (LPC_SC->PCLKSEL0 >> 2) & 0x03;
  switch ( pclkdiv )
  {
	case 0x00:
	default:
	  pclk = SystemFrequency/4;
	break;
	case 0x01:
	  pclk = SystemFrequency;
	break; 
	case 0x02:
	  pclk = SystemFrequency/2;
	break; 
	case 0x03:
	  pclk = SystemFrequency/8;
	break;
  }
 

  LPC_TIM0->MR0 = pclk/DATA_FREQ - 1;	/* TC0 Match Value 0 */
  LPC_TIM0->MCR = 3;					/* TCO Interrupt and Reset on MR0 */
  LPC_TIM0->TCR = 1;					/* TC0 Enable */
  NVIC_EnableIRQ(TIMER0_IRQn);

  USB_Init();				/* USB Initialization */
  USB_Connect(TRUE);		/* USB Connect */

  /********* The main Function is an endless loop ***********/ 
  
  while( 1 ); 

 
	 
  
}
  int result;   
	

/******************************************************************************
**                            End Of File
******************************************************************************/
24 Jul 2011

I have no idea what you want to do with semihost_powerdown() neither what that function actually do. I don't think it could run within interrupt service. semihosting functions are for debugging purpose only.

This link may give you more info about semihosting. Don't know if it could help you. http://knowledgebase.nxp.com/showthread.php?t=190