Important update: Arm Announces End of Life Timeline for Mbed. This site will be archived in July 2026. Read the full announcement.
Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
Uvision bin error
Topic last updated 25 Jul 2011, by Philips Philips.
31
replies
I want to do this, power down the LED on the usb cable. You know the blue LED that lets you know the mbed is on.
http://mbed.org/users/simon/notebook/interface-powerdown/?page=1#comment-1169
I know how to do it in online compiler. but not in uvision. Not sure what the function is in libs. the xpresso does not have the blue LED and the uvision code is written for the xpresso I think.
server huh? guess I am better at something than you...
/*---------------------------------------------------------------------------- * 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; semihost_powerdown(); 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 ******************************************************************************/
server huh? guess I am better at something than you...
<<code>>
/*----------------------------------------------------------------------------
* 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;
semihost_powerdown();
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
******************************************************************************/
<</code>>
I want to do this, power down the LED on the usb cable. You know the blue LED that lets you know the mbed is on.
http://mbed.org/users/simon/notebook/interface-powerdown/?page=1#comment-1169
I know how to do it in online compiler. but not in uvision. Not sure what the function is in libs. the xpresso does not have the blue LED and the uvision code is written for the xpresso I think.