Life.augmented
Skip to main content
Go Search
  

STM32 Evaluation Tools

Modify settings and columns
STM32 Discovery Kit, STM32 Nucleo, STM32 Eval Board
Share Discussion
  
View: 
Post
Edited: 6/8/2013 12:19 PM
j0hn
  Posts : 15
stm32 adc multi channel
thi is my code .when i debug it i faced  a error .i dont know how to fix it .plz guide me .the error is :-GCC HOME: C:\Program Files (x86)\GNU Tools ARM Embedded\4.7 2013q1\bin
compile:
    [mkdir] Created dir: C:\CooCox\CoIDE\workspace\rrr\rrr\Debug\bin
    [mkdir] Created dir: C:\CooCox\CoIDE\workspace\rrr\rrr\Debug\obj
       [cc] 9 total files to be compiled.
       [cc] arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -Wall -ffunction-sections -g -O0 -flto -fno-builtin -c -DSTM32F407VG -DSTM32F4XX -DUSE_STDPERIPH_DRIVER -D__ASSEMBLY__ -IC:\CooCox\CoIDE\workspace\rrr\cmsis -IC:\CooCox\CoIDE\workspace -IC:\CooCox\CoIDE\workspace\rrr\cmsis_lib -IC:\CooCox\CoIDE\workspace\rrr -IC:\CooCox\CoIDE\workspace\rrr\cmsis_lib\include -IC:\CooCox\CoIDE\workspace\rrr\cmsis_boot C:\CooCox\CoIDE\workspace\rrr\cmsis_lib\source\stm32f4xx_pwr.c C:\CooCox\CoIDE\workspace\rrr\cmsis_boot\startup\startup_stm32f4xx.c C:\CooCox\CoIDE\workspace\rrr\main.c C:\CooCox\CoIDE\workspace\rrr\cmsis_lib\source\stm32f4xx_rcc.c C:\CooCox\CoIDE\workspace\rrr\cmsis_lib\source\stm32f4xx_adc.c C:\CooCox\CoIDE\workspace\rrr\cmsis_lib\source\stm32f4xx_gpio.c C:\CooCox\CoIDE\workspace\rrr\cmsis_boot\system_stm32f4xx.c C:\CooCox\CoIDE\workspace\rrr\cmsis_lib\source\stm32f4xx_dma.c C:\CooCox\CoIDE\workspace\rrr\cmsis_lib\source\stm32f4xx_tim.c
       [cc] C:\CooCox\CoIDE\workspace\rrr\main.c: In function 'main':
       [cc] C:\CooCox\CoIDE\workspace\rrr\main.c:61:1: warning: control reaches end of non-void function [-Wreturn-type]
       [cc] Starting link
       [cc] arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -g -nostartfiles -flto -Wl,-Map=rrr.map -O0 -Wl,--gc-sections -Wl,--entry=main -LC:\CooCox\CoIDE\configuration\ProgramData\rrr -Wl,-TC:\CooCox\CoIDE\configuration\ProgramData\rrr/arm-gcc-link.ld -g -o rrr.elf ..\obj\stm32f4xx_pwr.o ..\obj\startup_stm32f4xx.o ..\obj\main.o ..\obj\stm32f4xx_rcc.o ..\obj\stm32f4xx_adc.o ..\obj\stm32f4xx_gpio.o ..\obj\system_stm32f4xx.o ..\obj\stm32f4xx_dma.o ..\obj\stm32f4xx_tim.o
       [cc] C:\Users\AKG\AppData\Local\Temp\cciWMwmp.s: Assembler messages:
       [cc] C:\Users\AKG\AppData\Local\Temp\cciWMwmp.s:180: Error: offset out of range
       [cc] C:\Users\AKG\AppData\Local\Temp\cciWMwmp.s:181: Error: offset out of range
       [cc] c:/program files (x86)/gnu tools arm embedded/4.7 2013q1/bin/../lib/gcc/arm-none-eabi/4.7.3/../../../../arm-none-eabi/bin/ld.exe: lto-wrapper failed
       [cc] lto-wrapper: C:\Program Files (x86)\GNU Tools ARM Embedded\4.7 2013q1\bin\arm-none-eabi-gcc returned 1 exit status
       [cc] collect2.exe: error: ld returned 1 exit status


#include "stm32f4xx_adc.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx.h"
#include "stm32f4xx_tim.h"
#include "stm32f4xx_dma.h"


#define ADC_CDR_ADDRESS    ((uint32_t)0x40012308)
__IO uint32_t ADCValue[9];

TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;

uint16_t PWM_PrescalerValue = 0;
uint16_t PWM_Period = 4095;

uint16_t PWM_CCR1 = 0;
uint16_t PWM_CCR2 = 0;
uint16_t PWM_CCR3 = 0;
uint16_t PWM_CCR4 = 0;
uint16_t PWM_CCR5 = 0;
uint16_t PWM_CCR6 = 0;

void  USBConfig();
void  DMA_ADC_Config();
void  ADC__SoftwareStartConv();
void  ADC_Config();
void  PWM_Config();
void  TIM8_Config();
void TIM8_IRQHandler();



int main(void)
{
  RCC_ClocksTypeDef RCC_Clocks;

 /* SysTick end of count event each 10ms */
  RCC_GetClocksFreq(&RCC_Clocks);
 // SysTick_Config(RCC_Clocks.
HCLK_Frequency / 100);

 /* USB configuration */
 // USBConfig();


  //Configuration of the PWM (Timers) channels used
  PWM_Config();

}

void ADC_Config(void)
{
      GPIO_InitTypeDef      GPIO_AdcInit;
     ADC_InitTypeDef       ADC_InitStructure;
     ADC_CommonInitTypeDef ADC_CommonInitStructure;

      /* Deinitializes the ADC peripheral registers */
      ADC_DeInit();

     /* Enable the GPIOC Clock & ADC1 Periph Clock */
      RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2 | RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC, ENABLE);
      RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC2 | RCC_APB2Periph_ADC3, ENABLE);

      /* Configure the  PA0 pin (ADC123_IN0)
       *                PA1 pin (ADC123_IN1)
       *                PA2 pin (ADC123_IN2)
      *                PA3 pin (ADC123_IN3)
     *                PA4 pin (ADC12_IN4) */
   GPIO_AdcInit.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4;
      GPIO_AdcInit.GPIO_Mode = GPIO_Mode_AN;
      GPIO_AdcInit.GPIO_PuPd = GPIO_PuPd_NOPULL;
      GPIO_Init(GPIOA, &GPIO_AdcInit);

      /* Configure the  PB0 pin (ADC12_IN8)
       *                PB1 pin (ADC12_IN9) */
      GPIO_AdcInit.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
      GPIO_AdcInit.GPIO_Mode = GPIO_Mode_AN;
      GPIO_AdcInit.GPIO_PuPd = GPIO_PuPd_NOPULL;
      GPIO_Init(GPIOB, &GPIO_AdcInit);

      /* Configure the  PC0 pin (ADC123_IN10)
       *                PC2 pin (ADC123_IN12) */
     GPIO_AdcInit.GPIO_Pin = GPIO_Pin_0  |  GPIO_Pin_2;
      GPIO_AdcInit.GPIO_Mode = GPIO_Mode_AN;
      GPIO_AdcInit.GPIO_PuPd = GPIO_PuPd_NOPULL;
      GPIO_Init(GPIOC, &GPIO_AdcInit);

      /* ADC Common configuration -- ADC_CCR Register */
     ADC_CommonInitStructure.ADC_Mode = ADC_TripleMode_RegSimult ;
      ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_10Cycles;
      ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_1  ;
      ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;
      ADC_CommonInit(&ADC_CommonInitStructure);


     /* ADC1 regular channel 6 configuration -- ADC_CR1, ADC_CR2, ADC_SQR1 Register */
     ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
      ADC_InitStructure.ADC_ScanConvMode = ENABLE;
      ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
      ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
     ADC_InitStructure.ADC_ExternalTrigConv = 0;
     ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
      ADC_InitStructure.ADC_NbrOfConversion = 3;
      ADC_Init(ADC1, &ADC_InitStructure);
     ADC_Init(ADC2, &ADC_InitStructure);
     ADC_Init(ADC3, &ADC_InitStructure);

      /* ADC1 regular channel6 configuration -- ADCx->SMPR1,SMPR2 et ADCx->SQR1,SQR2,SQR3
       *              channel8 */
      ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 1, ADC_SampleTime_15Cycles );
      ADC_RegularChannelConfig(ADC1, ADC_Channel_8, 2, ADC_SampleTime_15Cycles );
      ADC_RegularChannelConfig(ADC1, ADC_Channel_9, 3, ADC_SampleTime_15Cycles );

    /* ADC2 regular channel12 configuration -- ADCx->SMPR1,SMPR2 et ADCx->SQR1,SQR2,SQR3  */
      ADC_RegularChannelConfig(ADC2, ADC_Channel_12, 1, ADC_SampleTime_15Cycles );
     ADC_RegularChannelConfig(ADC2, ADC_Channel_4, 2, ADC_SampleTime_15Cycles );
      ADC_RegularChannelConfig(ADC2, ADC_Channel_1, 3, ADC_SampleTime_15Cycles );

      /* ADC3 regular channel12 configuration -- ADCx->SMPR1,SMPR2 et ADCx->SQR1,SQR2,SQR3  */
      ADC_RegularChannelConfig(ADC3, ADC_Channel_0, 1, ADC_SampleTime_15Cycles );
      ADC_RegularChannelConfig(ADC3, ADC_Channel_3, 2, ADC_SampleTime_15Cycles );
      ADC_RegularChannelConfig(ADC3, ADC_Channel_10, 3, ADC_SampleTime_15Cycles );

      /* DMA2 Stream0 channel0 configuration */
     DMA_ADC_Config();

      /* Enable DMA request after last transfer (Multi-ADC mode)  */
      ADC_MultiModeDMARequestAfterLastTransferCmd(ENABLE);

      /* Enable ADC1 -- ADC_CR2_ADON */
      ADC_Cmd(ADC1, ENABLE);

      /* Enable ADC2 */
      ADC_Cmd(ADC2, ENABLE);

      /* Enable ADC3 */
     ADC_Cmd(ADC3, ENABLE);

      /* Enable ADC1 DMA since ADC1 is the Master*/
      ADC_DMACmd(ADC1, ENABLE);
}




void DMA_ADC_Config(void)
{
  DMA_InitTypeDef DMA_InitStructure;
  DMA_InitStructure.DMA_Channel = DMA_Channel_0;
  DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&ADCValue;
  DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC_CDR_ADDRESS;
  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
  DMA_InitStructure.DMA_BufferSize = 9;
  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
  DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
 DMA_InitStructure.DMA_Priority = DMA_Priority_High;
  DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable;
  DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull;
 DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
  DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
  DMA_Init(DMA2_Stream0, & DMA_InitStructure);

  /* DMA2_Stream0 enable */
  DMA_Cmd(DMA2_Stream0, ENABLE);
}


void PWM_Config(void)
{
 /* TIM Configuration */
  TIM8_Config();

 /* Time base configuration */
 TIM_TimeBaseStructure.TIM_Period = PWM_Period;
  TIM_TimeBaseStructure.TIM_Prescaler = PWM_PrescalerValue;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

  TIM_TimeBaseInit(TIM8, &TIM_TimeBaseStructure);

  /* PWM1 Mode configuration: Channel1 */
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_Pulse = PWM_CCR1;
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

  TIM_OC1Init(TIM8, &TIM_OCInitStructure);

  TIM_OC1PreloadConfig(TIM8, TIM_OCPreload_Enable);

  /* PWM1 Mode configuration: Channel2 */
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_Pulse = PWM_CCR2;

  TIM_OC2Init(TIM8, &TIM_OCInitStructure);
  TIM_OC2PreloadConfig(TIM8, TIM_OCPreload_Enable);

  /* PWM1 Mode configuration: Channel3 */
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_Pulse = PWM_CCR3;

  TIM_OC3Init(TIM8, &TIM_OCInitStructure);
  TIM_OC3PreloadConfig(TIM8, TIM_OCPreload_Enable);

  /* PWM1 Mode configuration: Channel4 */
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_Pulse = PWM_CCR4;

  TIM_OC4Init(TIM8, &TIM_OCInitStructure);
  TIM_OC4PreloadConfig(TIM8, TIM_OCPreload_Enable);

  /* Enable TIM8 Preload register on ARR */
  TIM_ARRPreloadConfig(TIM8, ENABLE);

  /* TIM8 enable counter */
 TIM_Cmd(TIM8, ENABLE);

  /* TIM8 Main Output Enable */
 TIM_CtrlPWMOutputs(TIM8, ENABLE);

  // TIM IT enable
  TIM_ITConfig(TIM8, TIM_IT_Update, ENABLE);

}


void TIM8_Config(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;

 /* TIM8 clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE);
  /* GPIOC clocks enable */
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
  GPIO_Init(GPIOC, &GPIO_InitStructure);

 /* Connect TIM8 pins to AF2 */
  GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_TIM8);
  GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_TIM8);
 GPIO_PinAFConfig(GPIOC, GPIO_PinSource8, GPIO_AF_TIM8);
  GPIO_PinAFConfig(GPIOC, GPIO_PinSource9, GPIO_AF_TIM8);
}

void TIM8_IRQHandler(void)
{
  if (TIM_GetITStatus(TIM8, TIM_IT_Update) != RESET)
  {
   TIM_ClearITPendingBit(TIM8, TIM_IT_Update);

    TIM8->CCR1 = ADCValue[0]; // PWM output 1
   TIM8->CCR2 = ADCValue[1]; // PWM output 2
    TIM8->CCR3 = ADCValue[2]; // PWM output 3
   TIM8->CCR4 = ADCValue[3]; // PWM output 4
  }
}


  //Configuration of DMA for the ADC channels
  DMA_ADC_Config();

 //Configuration of the ADC channels used
  ADC_Config();

  /* Start ADC1 Software Conversion */
 // ADC__SoftwareStartConv(ADC1);

Tags: #stm32 #discovery ,
Edited: 6/8/2013 12:38 PM
clive1
  Posts : 8797
Looks to be a tool problem with the code generation, suggest you take it to the CooCox forum or GNU/GCC devs.

You could try a different optimization level, ie not -O0

Tags: coocox ,
Posted: 6/10/2013 6:49 AM
j0hn
  Posts : 15

right now i am using coocox software.but i did nt find solution .could you forward me some adc multichannel sample code .
Posted: 6/10/2013 7:26 PM
clive1
  Posts : 8797
You'll need to review the forum posts, and firmware examples. I don't distribute a package of examples.

I can't fix issues with your tools, you will need to find a different tool chain if the one you have doesn't compile/link code properly. Support for CooCox will need to be sought from them, perhaps via their forum, they do not participate here.
Edited: 6/11/2013 12:08 PM
j0hn
  Posts : 15
hey ..i am facing a problem in this code .i attached two potentiometer  on pc0 and pc5.i am getting same value when i rotate one potentiometer and another is fixed.so plz guide me how could i get value of 2 potentiometer on different channel..here is my code


#include "stm32f4xx_adc.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"

int ConvertedValue = 0;
int ConvertedValue1=0;
//Converted value readed from ADC


void adc_configure(){
 ADC_InitTypeDef ADC_init_structure; //Structure for adc confguration
 GPIO_InitTypeDef GPIO_initStructre; //Structure for analog input pin
 //Clock configuration
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE);//The ADC1 is connected the APB2 peripheral bus thus we will use its clock source
 RCC_AHB1PeriphClockCmd(RCC_AHB1ENR_GPIOCEN,ENABLE);//Clock for the ADC port!! Do not forget about this one ;)
 //Analog pin configuration
 GPIO_initStructre.GPIO_Pin = GPIO_Pin_0;//The channel 10 is connected to PC0
 GPIO_initStructre.GPIO_Mode = GPIO_Mode_AN; //The PC0 pin is configured in analog mode
 GPIO_initStructre.GPIO_PuPd = GPIO_PuPd_NOPULL; //We don't need any pull up or pull down
 GPIO_Init(GPIOC,&GPIO_initStructre);//Affecting the port with the initialization structure configuration
 //ADC structure configuration
 GPIO_initStructre.GPIO_Pin = GPIO_Pin_5;//The channel 15 is connected to PC5
 GPIO_initStructre.GPIO_Mode = GPIO_Mode_AN; //The PC0 pin is configured in analog mode
 GPIO_initStructre.GPIO_PuPd = GPIO_PuPd_NOPULL; //We don't need any pull up or pull down
 GPIO_Init(GPIOC,&GPIO_initStructre);//Affecting the port with the initialization structure configuration
 //ADC structure configuration
 ADC_DeInit();
 ADC_init_structure.ADC_DataAlign = ADC_DataAlign_Right;//data converted will be shifted to right
 ADC_init_structure.ADC_Resolution = ADC_Resolution_12b;//Input voltage is converted into a 12bit number giving a maximum value of 4096
 ADC_init_structure.ADC_ContinuousConvMode = ENABLE; //the conversion is continuous, the input data is converted more than once
 ADC_init_structure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;// conversion is synchronous with TIM1 and CC1 (actually I'm not sure about this one :/)
 ADC_init_structure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;//no trigger for conversion
 ADC_init_structure.ADC_NbrOfConversion = 2;//I think this one is clear :p
 ADC_init_structure.ADC_ScanConvMode = ENABLE;//The scan is configured in one channel
 ADC_Init(ADC1,&ADC_init_structure);//Initialize ADC with the previous configuration
 //Enable ADC conversion
 ADC_Cmd(ADC1,ENABLE);
 //Select the channel to be read from
 ADC_RegularChannelConfig(ADC1,ADC_Channel_10,1,ADC_SampleTime_144Cycles);
 ADC_RegularChannelConfig(ADC1,ADC_Channel_15,2,ADC_SampleTime_144Cycles);
}
int adc_convert(){
 ADC_SoftwareStartConv(ADC1);//Start the conversion
 while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC));//Processing the conversion
 return ADC_GetConversionValue(ADC1); //Return the converted data
}

int adc_convert1(){
 ADC_SoftwareStartConv(ADC1);//Start the conversion
 while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC));//Processing the conversion
 return ADC_GetConversionValue(ADC1); //Return the converted data
}
int main(void){
 adc_configure();//Start configuration
    while(1){//loop while the board is working
     ConvertedValue = adc_convert();//Read the ADC converted value
     ConvertedValue1 = adc_convert1();//Read the ADC converted value
    }
}





Posted: 6/11/2013 2:14 PM
clive1
  Posts : 8797

Tags: Plz != Please ,
Posted: 6/11/2013 2:35 PM
fm
  Posts : 1013
...
       [cc] C:\Users\AKG\AppData\Local\Temp\cciWMwmp.s: Assembler messages:
       [cc] C:\Users\AKG\AppData\Local\Temp\cciWMwmp.s:180: Error: offset out of range
       [cc] C:\Users\AKG\AppData\Local\Temp\cciWMwmp.s:181: Error: offset out of range
       [cc] c:/program files (x86)/gnu tools arm embedded/4.7 2013q1/bin/../lib/gcc/arm-none-eabi/4.7.3/../../../../arm-none-eabi/bin/ld.exe: lto-wrapper failed
       [cc] lto-wrapper: C:\Program Files (x86)\GNU Tools ARM Embedded\4.7 2013q1\bin\arm-none-eabi-gcc returned 1 exit status
       [cc] collect2.exe: error: ld returned 1 exit status

Your toolchain, i.e. the compiler in this case, might have been build without LTO support.
Try removing the "-flto" flag.

Posted: 6/11/2013 6:32 PM
j0hn
  Posts : 15

which path should i follow to remove  "-flto" flag.?

Posted: 6/11/2013 6:34 PM
j0hn
  Posts : 15
which tool chain should i use to assemble the programe ?

Edited: 6/11/2013 7:02 PM
clive1
  Posts : 8797
which tool chain should i use to assemble the programe ?

I'm using Keil, but have reasonably good experiences with Rowley, and IAR. If you're proficient with GNU/GCC something like Yagarto might be workable for you, I've built some flat projects with it.

In terms of supported tools, ST has provided a Template Project, you'd want to be comfortable manipulating that into a new project, and copying in the code I've supplied. The code is sufficiently complete to drop into an existing project, building a project from scratch requires some experience/familiarity with the chosen tools.
Posted: 6/13/2013 12:41 PM
j0hn
  Posts : 15
hello ..this programe is working.now i wana get this data simultaneously on serial monitor..which command should i follow?
Posted: 6/13/2013 1:40 PM
fm
  Posts : 1013
Just add some code to initialise  the UART and associated pins, and the send functionality.

You will find plenty of examples around in the web, google is your friend (well, except if you insist on privacy ...).

Coocox should maintain a collection of examples, and the StdPeripheralLibrary, as part of the F4 discovery firmware, is available from the ST website. The latter contains examples for all peripherals, including UART:

Edited: 6/13/2013 2:16 PM
j0hn
  Posts : 15

this is my code for usart .and i am  facing again one error which i found last time ..please suggest me how to remove it .....code is here
#include <stm32f4xx_usart.h>

#include "stm32f4xx_adc.h"

#include "stm32f4xx_gpio.h"

#include "stm32f4xx_rcc.h"

#include "stm32f4xx.h"

void init_usart(void){

 GPIO_InitTypeDef GPIO_InitStructure;
 USART_InitTypeDef USART_InitStructure;

 /* enable peripheral clock for USART2 */
 RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);


 /* GPIOA clock enable */
 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

 /* GPIOA Configuration:  USART2 TX on PA2 */
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
 GPIO_Init(GPIOA, &GPIO_InitStructure);

 /* Connect USART2 pins to AF2 */
 // TX = PA2
 GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2);

 USART_InitStructure.USART_BaudRate = 9600;
 USART_InitStructure.USART_WordLength = USART_WordLength_8b;
 USART_InitStructure.USART_StopBits = USART_StopBits_1;
 USART_InitStructure.USART_Parity = USART_Parity_No;
 USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
 USART_InitStructure.USART_Mode = USART_Mode_Tx;
 USART_Init(USART2, &USART_InitStructure);

 USART_Cmd(USART2, ENABLE); // enable USART2

}

void Delay(__IO uint32_t nCount)
{
  while(nCount--)
  {
  }
}

int main(void){

 init_usart();

 uart_puts("Init complete!");

 while(1){
  USART_SendData(USART2, 'v'); // defined in stm32f4xx_usart.h
  Delay(0x3FFFFF);
 }

}

.ERROR IS HERE
GCC HOME: C:\Program Files (x86)\GNU Tools ARM Embedded\4.7 2013q1\bin
compile:
    [mkdir] Created dir: C:\CooCox\CoIDE\workspace\usart\usart\Debug\bin
    [mkdir] Created dir: C:\CooCox\CoIDE\workspace\usart\usart\Debug\obj
       [cc] 18 total files to be compiled.
       [cc] arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -Wall -ffunction-sections -g -O0 -flto -fno-builtin -c -DSTM32F407VG -DSTM32F4XX -DUSE_STDPERIPH_DRIVER -D__ASSEMBLY__ -IC:\CooCox\CoIDE\workspace\usart\cmsis_lib -IC:\CooCox\CoIDE\workspace\usart\cmsis_boot -IC:\CooCox\CoIDE\workspace -IC:\CooCox\CoIDE\workspace\usart\cmsis_lib\include -IC:\CooCox\CoIDE\workspace\usart -IC:\CooCox\CoIDE\workspace\usart\cmsis -IC:\CooCox\CoIDE\workspace\usart\STM32F4-Discovery C:\CooCox\CoIDE\workspace\usart\cmsis_lib\source\stm32f4xx_syscfg.c C:\CooCox\CoIDE\workspace\usart\STM32F4-Discovery\stm32f4_discovery_audio_codec.c C:\CooCox\CoIDE\workspace\usart\cmsis_lib\source\stm32f4xx_usart.c C:\CooCox\CoIDE\workspace\usart\cmsis_lib\source\stm32f4xx_dac.c C:\CooCox\CoIDE\workspace\usart\cmsis_boot\startup\startup_stm32f4xx.c C:\CooCox\CoIDE\workspace\usart\STM32F4-Discovery\stm32f4_discovery.c C:\CooCox\CoIDE\workspace\usart\main.c C:\CooCox\CoIDE\workspace\usart\cmsis_lib\source\stm32f4xx_rcc.c C:\CooCox\CoIDE\workspace\usart\cmsis_lib\source\stm32f4xx_adc.c C:\CooCox\CoIDE\workspace\usart\cmsis_lib\source\stm32f4xx_gpio.c C:\CooCox\CoIDE\workspace\usart\cmsis_boot\system_stm32f4xx.c C:\CooCox\CoIDE\workspace\usart\cmsis_lib\source\stm32f4xx_dma.c C:\CooCox\CoIDE\workspace\usart\stm32f4_discovery_callbacks.c C:\CooCox\CoIDE\workspace\usart\cmsis_lib\source\stm32f4xx_spi.c C:\CooCox\CoIDE\workspace\usart\cmsis_lib\source\stm32f4xx_i2c.c C:\CooCox\CoIDE\workspace\usart\cmsis_lib\source\stm32f4xx_exti.c C:\CooCox\CoIDE\workspace\usart\cmsis_lib\source\misc.c C:\CooCox\CoIDE\workspace\usart\STM32F4-Discovery\stm32f4_discovery_lis302dl.c
       [cc] C:\CooCox\CoIDE\workspace\usart\main.c: In function 'main':
       [cc] C:\CooCox\CoIDE\workspace\usart\main.c:59:2: warning: implicit declaration of function 'uart_puts' [-Wimplicit-function-declaration]
       [cc] Starting link
       [cc] arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -g -nostartfiles -flto -Wl,-Map=usart.map -O0 -Wl,--gc-sections -Wl,--entry=main -LC:\CooCox\CoIDE\configuration\ProgramData\usart -Wl,-TC:\CooCox\CoIDE\configuration\ProgramData\usart/arm-gcc-link.ld -g -o usart.elf ..\obj\stm32f4xx_syscfg.o ..\obj\stm32f4_discovery_audio_codec.o ..\obj\stm32f4xx_usart.o ..\obj\stm32f4xx_dac.o ..\obj\startup_stm32f4xx.o ..\obj\stm32f4_discovery.o ..\obj\main.o ..\obj\stm32f4xx_rcc.o ..\obj\stm32f4xx_adc.o ..\obj\stm32f4xx_gpio.o ..\obj\system_stm32f4xx.o ..\obj\stm32f4xx_dma.o ..\obj\stm32f4_discovery_callbacks.o ..\obj\stm32f4xx_spi.o ..\obj\stm32f4xx_i2c.o ..\obj\stm32f4xx_exti.o ..\obj\misc.o ..\obj\stm32f4_discovery_lis302dl.o -L..\..\..\STM32F4-Discovery -lpdmfilter_gcc
       [cc] C:\Users\AKG\AppData\Local\Temp\ccT4as9i.ltrans0.ltrans.o: In function `main':
       [cc] C:\CooCox\CoIDE\workspace\usart/main.c:59: undefined reference to `uart_puts'
       [cc] collect2.exe: error: ld returned 1 exit status



From: fm
Posted: Thursday, June 13, 2013 1:40 PM
Subject: stm32 adc multi channel

Just add some code to initialise  the UART and associated pins, and the send functionality.

You will find plenty of examples around in the web, google is your friend (well, except if you insist on privacy ...).

Coocox should maintain a collection of examples, and the StdPeripheralLibrary, as part of the F4 discovery firmware, is available from the ST website. The latter contains examples for all peripherals, including UART:


From: sharma.vaibhav
Posted: Thursday, June 13, 2013 12:41 PM
Subject: stm32 adc multi channel

hello ..this programe is working.now i wana get this data simultaneously on serial monitor..which command should i follow?

From: clive1
Posted: Tuesday, June 11, 2013 7:02 PM
Subject: stm32 adc multi channel

which tool chain should i use to assemble the programe ?

I'm using Keil, but have reasonably good experiences with Rowley, and IAR. If you're proficient with GNU/GCC something like Yagarto might be workable for you, I've built some flat projects with it.

In terms of supported tools, ST has provided a Template Project, you'd want to be comfortable manipulating that into a new project, and copying in the code I've supplied. The code is sufficiently complete to drop into an existing project, building a project from scratch requires some experience/familiarity with the chosen tools.
Posted: 6/13/2013 2:23 PM
j0hn
  Posts : 15


Posted: 6/13/2013 2:25 PM
j0hn
  Posts : 15


Posted: 6/13/2013 2:30 PM
j0hn
  Posts : 15
hello .now i am interfacing pressure sensor (mpx415a) on stm32 discovery board .do u have any sample code in which we can see pressure sensor's data ,

Posted: 6/13/2013 2:52 PM
fm
  Posts : 1013
  [cc] C:\CooCox\CoIDE\workspace\usart/main.c:59: undefined reference to `uart_puts'

You call a function that nowhere exists in the project space.
Either your toolchain/library supports routing printf()-like functions to UART, or you write it yourself. This forum contains several threads on how to do this with Keil. Not sure what your (undisclosed / gcc-based) toolchain provides.
Writing it yourself can offer significant code space savings.

Posted: 6/13/2013 3:03 PM
fm
  Posts : 1013
If you mean a MPX4105A/4115A, this devices have an analog output, and require a +5V supply.
You will need a buffer amplifier to interface the sensor output with the ADC, to reduce the impedance and to convert the 0..5V sensor output span to 0..3.3V of the ADC.

Posted: 6/13/2013 3:19 PM
clive1
  Posts : 8797
void uart_puts(char *s)
{
  while(*s)
  {
    while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
 
    USART_SendData(USART2, *s++);
  }
}
Posted: 6/13/2013 3:20 PM
baird.hal.001
  Posts : 411
Minor correction - the F4 Discovery ADC range is 0 to 3V.

This is a simple exercize for the student.

Cheers, Hal

Posted: 6/14/2013 10:42 AM
j0hn
  Posts : 15

hello .do u have sample code in which pressure sensor working with stm32f4discovery
Posted: 6/14/2013 1:35 PM
clive1
  Posts : 8797
No
Posted: 6/14/2013 1:57 PM
fm
  Posts : 1013
I would suggest to seek some local guidance or mentor, as it seems you are not really upt to the task you picked / were assigned to.

There will be no specific example - such a sensor just delivers an analog signal you can measure with the ADC. It is up to you to design and implement the relation between measurement parameter and it's internal representation.

Browse Private Forums

NOTE: these forums are exclusive for users of this Extranet!)