public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] stm3210e eval board adc question
@ 2011-04-12 15:27 jayant biswas
  2011-04-12 16:22 ` Christophe Coutand
  0 siblings, 1 reply; 13+ messages in thread
From: jayant biswas @ 2011-04-12 15:27 UTC (permalink / raw)
  To: ecos-discuss

Hello everyone!

I am new to this list and to ecos and the stm32 and am looking for
some help in reading from ADC inputs.

Here is the test program I have used to see if I can read the inputs.
I am able to read the normal input from the user key on the board, but
I am not able to read the analog input. pot_val is always 0. I test my
program by holding on to the user key and changing the potentiometer
position and then hitting reset. Do you have any ideas?

/* this is a simple hello world program */
#include <stdio.h>
#include <cyg/hal/hal_io.h>

#define CYGHWR_POT 	CYGHWR_HAL_STM32_GPIO(C, 4, IN, ANALOG)
#define CYGHWR_BUT 	CYGHWR_HAL_STM32_GPIO(G, 8, IN, FLOATING)

int cyg_user_start(void)
{
  cyg_int32 pot_val = 10;
  cyg_int32 but_val = 10;

  printf("Hello, eCos world!\n");
  CYGHWR_HAL_STM32_GPIO_SET(CYGHWR_POT);
  CYGHWR_HAL_STM32_GPIO_SET(CYGHWR_BUT);

  CYGHWR_HAL_STM32_GPIO_IN(CYGHWR_POT, &pot_val);
  CYGHWR_HAL_STM32_GPIO_IN(CYGHWR_BUT, &but_val);

  printf("Potentiometer value is %d, button value is %d\n", pot_val, but_val);
  while(1);
  return 0;
}

I wasn't able to enable the cdl component CYGPKG_IO_ADC_DEVICES in my
ecos config as it wasn't available.

I have an STM3210E Eval board and am using it with an Amontec JTAG
key. I used the default stm3210e template and changed the target to
ROM. I load the program directly to the ROM so I am not using anything
like Redboot.

Thank you in advance for your help!

Jayant

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 13+ messages in thread

* RE: [ECOS] stm3210e eval board adc question
  2011-04-12 15:27 [ECOS] stm3210e eval board adc question jayant biswas
@ 2011-04-12 16:22 ` Christophe Coutand
  2011-04-13  8:48   ` jayant biswas
  0 siblings, 1 reply; 13+ messages in thread
From: Christophe Coutand @ 2011-04-12 16:22 UTC (permalink / raw)
  To: jayant biswas, ecos-discuss

Hi Jayant,

Have you added the ADC IO package (CYGPKG_IO_ADC) ? 

CYGHWR_HAL_STM32_GPIO_IN is only relevant for digital IOs. To read ADC
channels, you must use cyg_io_lookup / cyg_io_read. Have a look at some
of the ADC test applications for AT91 or LPC24xx.

Hope this helps.

Christophe


-----Original Message-----
From: ecos-discuss-owner@ecos.sourceware.org
[mailto:ecos-discuss-owner@ecos.sourceware.org] On Behalf Of jayant
biswas
Sent: 12. april 2011 17:27
To: ecos-discuss@ecos.sourceware.org
Subject: [ECOS] stm3210e eval board adc question

Hello everyone!

I am new to this list and to ecos and the stm32 and am looking for
some help in reading from ADC inputs.

Here is the test program I have used to see if I can read the inputs.
I am able to read the normal input from the user key on the board, but
I am not able to read the analog input. pot_val is always 0. I test my
program by holding on to the user key and changing the potentiometer
position and then hitting reset. Do you have any ideas?

/* this is a simple hello world program */
#include <stdio.h>
#include <cyg/hal/hal_io.h>

#define CYGHWR_POT 	CYGHWR_HAL_STM32_GPIO(C, 4, IN, ANALOG)
#define CYGHWR_BUT 	CYGHWR_HAL_STM32_GPIO(G, 8, IN, FLOATING)

int cyg_user_start(void)
{
  cyg_int32 pot_val = 10;
  cyg_int32 but_val = 10;

  printf("Hello, eCos world!\n");
  CYGHWR_HAL_STM32_GPIO_SET(CYGHWR_POT);
  CYGHWR_HAL_STM32_GPIO_SET(CYGHWR_BUT);

  CYGHWR_HAL_STM32_GPIO_IN(CYGHWR_POT, &pot_val);
  CYGHWR_HAL_STM32_GPIO_IN(CYGHWR_BUT, &but_val);

  printf("Potentiometer value is %d, button value is %d\n", pot_val,
but_val);
  while(1);
  return 0;
}

I wasn't able to enable the cdl component CYGPKG_IO_ADC_DEVICES in my
ecos config as it wasn't available.

I have an STM3210E Eval board and am using it with an Amontec JTAG
key. I used the default stm3210e template and changed the target to
ROM. I load the program directly to the ROM so I am not using anything
like Redboot.

Thank you in advance for your help!

Jayant

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [ECOS] stm3210e eval board adc question
  2011-04-12 16:22 ` Christophe Coutand
@ 2011-04-13  8:48   ` jayant biswas
       [not found]     ` <D6050C555CC56940A7AF3265228302761394EC@mail2.STMIRV01.COM>
  0 siblings, 1 reply; 13+ messages in thread
From: jayant biswas @ 2011-04-13  8:48 UTC (permalink / raw)
  To: Christophe Coutand; +Cc: ecos-discuss

Thank you Christophe for your reply.

So I added the ADC IO package as per your suggestion and I enabled the
CYGPKG_IO_ADC_DEVICES option. Then I have modified my program as
follows:

  int res = 0;
  cyg_io_handle_t handle;

  res = cyg_io_lookup("/dev/adc00", &handle);
  if(res != ENOERR) {
	  printf("Error in cyg_io_lookup %d\n", res);
  }

  cyg_int32 sample = 0;
  cyg_uint32 len = sizeof(sample);

  res = cyg_io_read(handle, &sample, &len);
  if(res != ENOERR) {
	  printf("Error in cyg_io_read %x\n", res);
  }

  printf("ADC value: 0x%x\n", sample);

But cyg_io_lookup returns an error of -2. I am not sure if I need to
add the packages mentioned here
http://www.mail-archive.com/ecos-patches@ecos.sourceware.org/msg01672.html
. But I am not able to find these packages among the available ones.

Please let me know if I am missing something.

Best regards,
Jayant


On Tue, Apr 12, 2011 at 18:19, Christophe Coutand <ccoutand@stmi.com> wrote:
> Hi Jayant,
>
> Have you added the ADC IO package (CYGPKG_IO_ADC) ?
>
> CYGHWR_HAL_STM32_GPIO_IN is only relevant for digital IOs. To read ADC
> channels, you must use cyg_io_lookup / cyg_io_read. Have a look at some
> of the ADC test applications for AT91 or LPC24xx.
>
> Hope this helps.
>
> Christophe
>
>
> -----Original Message-----
> From: ecos-discuss-owner@ecos.sourceware.org
> [mailto:ecos-discuss-owner@ecos.sourceware.org] On Behalf Of jayant
> biswas
> Sent: 12. april 2011 17:27
> To: ecos-discuss@ecos.sourceware.org
> Subject: [ECOS] stm3210e eval board adc question
>
> Hello everyone!
>
> I am new to this list and to ecos and the stm32 and am looking for
> some help in reading from ADC inputs.
>
> Here is the test program I have used to see if I can read the inputs.
> I am able to read the normal input from the user key on the board, but
> I am not able to read the analog input. pot_val is always 0. I test my
> program by holding on to the user key and changing the potentiometer
> position and then hitting reset. Do you have any ideas?
>
> /* this is a simple hello world program */
> #include <stdio.h>
> #include <cyg/hal/hal_io.h>
>
> #define CYGHWR_POT      CYGHWR_HAL_STM32_GPIO(C, 4, IN, ANALOG)
> #define CYGHWR_BUT      CYGHWR_HAL_STM32_GPIO(G, 8, IN, FLOATING)
>
> int cyg_user_start(void)
> {
>  cyg_int32 pot_val = 10;
>  cyg_int32 but_val = 10;
>
>  printf("Hello, eCos world!\n");
>  CYGHWR_HAL_STM32_GPIO_SET(CYGHWR_POT);
>  CYGHWR_HAL_STM32_GPIO_SET(CYGHWR_BUT);
>
>  CYGHWR_HAL_STM32_GPIO_IN(CYGHWR_POT, &pot_val);
>  CYGHWR_HAL_STM32_GPIO_IN(CYGHWR_BUT, &but_val);
>
>  printf("Potentiometer value is %d, button value is %d\n", pot_val,
> but_val);
>  while(1);
>  return 0;
> }
>
> I wasn't able to enable the cdl component CYGPKG_IO_ADC_DEVICES in my
> ecos config as it wasn't available.
>
> I have an STM3210E Eval board and am using it with an Amontec JTAG
> key. I used the default stm3210e template and changed the target to
> ROM. I load the program directly to the ROM so I am not using anything
> like Redboot.
>
> Thank you in advance for your help!
>
> Jayant
>
> --
> Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
> and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
>
>

--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [ECOS] stm3210e eval board adc question
       [not found]     ` <D6050C555CC56940A7AF3265228302761394EC@mail2.STMIRV01.COM>
@ 2011-04-13 12:38       ` jayant biswas
  2011-04-13 18:11         ` [ECOS] " John Dallaway
  0 siblings, 1 reply; 13+ messages in thread
From: jayant biswas @ 2011-04-13 12:38 UTC (permalink / raw)
  To: Christophe Coutand; +Cc: ecos-discuss

Hi again!

Thanks Christophe for taking the time to help me. Unfortunately I do
not see the packages you mention in my configuration. I can also not
add them by going in to Build -> Packages in the configtool. I tried
to create a new config for the stm3210e board with the 'all' template
instead of default and I still don't see those packages. I have tried
to search for the relevant files on the internet to see if I can maybe
add them manually, but this hasn't been fruitful either. Any ideas how
I may have access to these packages?

I installed ecos as indicated here
http://ecos.sourceware.org/getstart.html . I did notice that I have
libstdc++6.0.14. Could that be the problem? I would imagine not as I
can still use the configtool and build programs and run them on the
board.

Regards,
Jayant

On Wed, Apr 13, 2011 at 11:31, Christophe Coutand <ccoutand@stmi.com> wrote:
> Hi Jayant,
> You require the ADC package for
> the STM32 HAL (CYGPKG_DEVS_ADC_CORTEXM_STM32) to be present which I beleive
> must be included by default.
>
> To have access to /dev/adc00, you must enable
> CYGHWR_DEVS_ADC_CORTEXM_STM32_ADC1 as well as the channel 0 of this ADC.
>
> Christophe
> ________________________________
> From: jayant biswas [mailto:biswasj@gmail.com]
> Sent: Wed 4/13/2011 1:48 AM
> To: Christophe Coutand
> Cc: ecos-discuss@ecos.sourceware.org
> Subject: Re: [ECOS] stm3210e eval board adc question
>
> Thank you Christophe for your reply.
>
> So I added the ADC IO package as per your suggestion and I enabled the
> CYGPKG_IO_ADC_DEVICES option. Then I have modified my program as
> follows:
>
>   int res = 0;
>   cyg_io_handle_t handle;
>
>   res = cyg_io_lookup("/dev/adc00", &handle);
>   if(res != ENOERR) {
>           printf("Error in cyg_io_lookup %d\n", res);
>   }
>
>   cyg_int32 sample = 0;
>   cyg_uint32 len = sizeof(sample);
>
>   res = cyg_io_read(handle, &sample, &len);
>   if(res != ENOERR) {
>           printf("Error in cyg_io_read %x\n", res);
>   }
>
>   printf("ADC value: 0x%x\n", sample);
>
> But cyg_io_lookup returns an error of -2. I am not sure if I need to
> add the packages mentioned here
> http://www.mail-archive.com/ecos-patches@ecos.sourceware.org/msg01672.html
> . But I am not able to find these packages among the available ones.
>
> Please let me know if I am missing something.
>
> Best regards,
> Jayant
>
>
> On Tue, Apr 12, 2011 at 18:19, Christophe Coutand <ccoutand@stmi.com> wrote:
>> Hi Jayant,
>>
>> Have you added the ADC IO package (CYGPKG_IO_ADC) ?
>>
>> CYGHWR_HAL_STM32_GPIO_IN is only relevant for digital IOs. To read ADC
>> channels, you must use cyg_io_lookup / cyg_io_read. Have a look at some
>> of the ADC test applications for AT91 or LPC24xx.
>>
>> Hope this helps.
>>
>> Christophe
>>
>>
>> -----Original Message-----
>> From: ecos-discuss-owner@ecos.sourceware.org
>> [mailto:ecos-discuss-owner@ecos.sourceware.org] On Behalf Of jayant
>> biswas
>> Sent: 12. april 2011 17:27
>> To: ecos-discuss@ecos.sourceware.org
>> Subject: [ECOS] stm3210e eval board adc question
>>
>> Hello everyone!
>>
>> I am new to this list and to ecos and the stm32 and am looking for
>> some help in reading from ADC inputs.
>>
>> Here is the test program I have used to see if I can read the inputs.
>> I am able to read the normal input from the user key on the board, but
>> I am not able to read the analog input. pot_val is always 0. I test my
>> program by holding on to the user key and changing the potentiometer
>> position and then hitting reset. Do you have any ideas?
>>
>> /* this is a simple hello world program */
>> #include <stdio.h>
>> #include <cyg/hal/hal_io.h>
>>
>> #define CYGHWR_POT      CYGHWR_HAL_STM32_GPIO(C, 4, IN, ANALOG)
>> #define CYGHWR_BUT      CYGHWR_HAL_STM32_GPIO(G, 8, IN, FLOATING)
>>
>> int cyg_user_start(void)
>> {
>>  cyg_int32 pot_val = 10;
>>  cyg_int32 but_val = 10;
>>
>>  printf("Hello, eCos world!\n");
>>  CYGHWR_HAL_STM32_GPIO_SET(CYGHWR_POT);
>>  CYGHWR_HAL_STM32_GPIO_SET(CYGHWR_BUT);
>>
>>  CYGHWR_HAL_STM32_GPIO_IN(CYGHWR_POT, &pot_val);
>>  CYGHWR_HAL_STM32_GPIO_IN(CYGHWR_BUT, &but_val);
>>
>>  printf("Potentiometer value is %d, button value is %d\n", pot_val,
>> but_val);
>>  while(1);
>>  return 0;
>> }
>>
>> I wasn't able to enable the cdl component CYGPKG_IO_ADC_DEVICES in my
>> ecos config as it wasn't available.
>>
>> I have an STM3210E Eval board and am using it with an Amontec JTAG
>> key. I used the default stm3210e template and changed the target to
>> ROM. I load the program directly to the ROM so I am not using anything
>> like Redboot.
>>
>> Thank you in advance for your help!
>>
>> Jayant
>>
>> --
>> Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
>> and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
>>
>>
>

--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [ECOS] Re: stm3210e eval board adc question
  2011-04-13 12:38       ` jayant biswas
@ 2011-04-13 18:11         ` John Dallaway
  2011-04-18  8:48           ` jayant biswas
  0 siblings, 1 reply; 13+ messages in thread
From: John Dallaway @ 2011-04-13 18:11 UTC (permalink / raw)
  To: jayant biswas; +Cc: ecos-discuss

Hi Jayant

jayant biswas wrote:

> I installed ecos as indicated here
> http://ecos.sourceware.org/getstart.html .

... so you have the eCos 3.0 release repository.

The STM32 ADC driver is not present in eCos 3.0. You will have to
checkout the eCos CVS repository in order to gain access to
CYGPKG_DEVS_ADC_CORTEXM_STM32. Ref:

  http://ecos.sourceware.org/anoncvs.html

I hope this helps...

John Dallaway
eCos maintainer
http://www.dallaway.org.uk/john

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [ECOS] Re: stm3210e eval board adc question
  2011-04-13 18:11         ` [ECOS] " John Dallaway
@ 2011-04-18  8:48           ` jayant biswas
  2011-04-18  9:49             ` [ECOS] " Christophe Coutand
  0 siblings, 1 reply; 13+ messages in thread
From: jayant biswas @ 2011-04-18  8:48 UTC (permalink / raw)
  To: John Dallaway, Christophe Coutand; +Cc: ecos-discuss

Thank you Christophe and John for your replies.

I did checkout the cvs repository and was able to get the right folder
i.e. packages\devs\adc\cortexm\stm32

However, this hasn't solved my problem. I am still getting the same
output as before when calling cyg_io_lookup and cyg_io_read.

To integrate the new packages from the cvs. I copied  the entire
repository over my ecos-3.0 folder. Then I regenerated the ecos.ecc
file for stm3210e. I noticed here that the
CYGPKG_DEVS_ADC_CORTEXM_STM32 checkboxes were grayed out. I then
recompiled my application with the newly generated libraries.

Please let me know if I am missing some steps. I am sure I am. Is
there a guide that I can follow that shows how to integrate the ecos
cvs packages?

Best regards,
Jayant

On Wed, Apr 13, 2011 at 20:11, John Dallaway <john@dallaway.org.uk> wrote:
> Hi Jayant
>
> jayant biswas wrote:
>
>> I installed ecos as indicated here
>> http://ecos.sourceware.org/getstart.html .
>
> ... so you have the eCos 3.0 release repository.
>
> The STM32 ADC driver is not present in eCos 3.0. You will have to
> checkout the eCos CVS repository in order to gain access to
> CYGPKG_DEVS_ADC_CORTEXM_STM32. Ref:
>
>  http://ecos.sourceware.org/anoncvs.html
>
> I hope this helps...
>
> John Dallaway
> eCos maintainer
> http://www.dallaway.org.uk/john
>

--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [ECOS] RE: stm3210e eval board adc question
  2011-04-18  8:48           ` jayant biswas
@ 2011-04-18  9:49             ` Christophe Coutand
  2011-04-18 14:49               ` [ECOS] " jayant biswas
  0 siblings, 1 reply; 13+ messages in thread
From: Christophe Coutand @ 2011-04-18  9:49 UTC (permalink / raw)
  To: jayant biswas, John Dallaway; +Cc: ecos-discuss

Hi Jayant,

You are using ecos-3.0 with the additional STM32 ADC package from CVS? It is usually not recommended to mix source code as it make it more difficult to get support from the mailing list. 

It is not enough to copy the directory packages\devs\adc\cortexm\stm32 in your repository, you must also include the package entry in the database (i.e. ecos.db):

package CYGPKG_DEVS_ADC_CORTEXM_STM32 {
    alias         { "STM32 ADC driver" adc_stm32 }
    hardware
    directory     devs/adc/cortexm/stm32
    script        adc_stm32.cdl
    description "
    This package provides a driver for the ADC interfaces found on the
    ST STM32 microcontroller family."
}

To build the STM32 HAL with ADC support from CVS repository, I do:
$ ecosconfig.exe new stm3210e default
$ ecosconfig.exe add io_adc

You can configure the ADC from the GUI:
$ configtool.exe ecos.ecc

Example:

http://dl.dropbox.com/u/21589565/misc/stm32_adc.JPG

Regards,
Christophe

-----Original Message-----
From: jayant biswas [mailto:biswasj@gmail.com] 
Sent: 18. april 2011 10:47
To: John Dallaway; Christophe Coutand
Cc: ecos-discuss@ecos.sourceware.org
Subject: Re: stm3210e eval board adc question

Thank you Christophe and John for your replies.

I did checkout the cvs repository and was able to get the right folder
i.e. packages\devs\adc\cortexm\stm32

However, this hasn't solved my problem. I am still getting the same
output as before when calling cyg_io_lookup and cyg_io_read.

To integrate the new packages from the cvs. I copied  the entire
repository over my ecos-3.0 folder. Then I regenerated the ecos.ecc
file for stm3210e. I noticed here that the
CYGPKG_DEVS_ADC_CORTEXM_STM32 checkboxes were grayed out. I then
recompiled my application with the newly generated libraries.

Please let me know if I am missing some steps. I am sure I am. Is
there a guide that I can follow that shows how to integrate the ecos
cvs packages?

Best regards,
Jayant

On Wed, Apr 13, 2011 at 20:11, John Dallaway <john@dallaway.org.uk> wrote:
> Hi Jayant
>
> jayant biswas wrote:
>
>> I installed ecos as indicated here
>> http://ecos.sourceware.org/getstart.html .
>
> ... so you have the eCos 3.0 release repository.
>
> The STM32 ADC driver is not present in eCos 3.0. You will have to
> checkout the eCos CVS repository in order to gain access to
> CYGPKG_DEVS_ADC_CORTEXM_STM32. Ref:
>
>  http://ecos.sourceware.org/anoncvs.html
>
> I hope this helps...
>
> John Dallaway
> eCos maintainer
> http://www.dallaway.org.uk/john
>

--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [ECOS] Re: stm3210e eval board adc question
  2011-04-18  9:49             ` [ECOS] " Christophe Coutand
@ 2011-04-18 14:49               ` jayant biswas
  2011-04-19  7:27                 ` [ECOS] " Christophe Coutand
  0 siblings, 1 reply; 13+ messages in thread
From: jayant biswas @ 2011-04-18 14:49 UTC (permalink / raw)
  To: Christophe Coutand; +Cc: ecos-discuss

Dear Christophe!

Thanks for your support. I have a feeling I am getting closer, but not
quite there yet. So I appreciate your time in helping me out. Now I
have been able to add the adc io, as in the screenshot you sent using
only the cvs code. So I am not mixing anymore ecos-3.0 and the cvs.
But when I run the tests on my stm3210e eval board I do not get the
desired output. The output of adc2 test is shown below. It shows that
no samples have been read. I am also not sure what to make of the
\0x09 stuff before the '=' signs.

My goal is to be able to read the value from the potentiometer on the
board (http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DATA_BRIEF/CD00278458.pdf
as shown on page 2/3) and eventually also from the 3 bnc connectors.
First of all, how can I know which input (BNC or Potentiometer) is
connected to which device on which channel? And secondly why when I
try to display values from all channels on both devices I receive
nothing. One of these channels must be connected to the potentiometer
no? The BNC connectors are currently left open.

Hope I can make this work.

Regards,
Jayant

\0x00INFO:<ADC performance test>
INFO:<Opening available ADC channel
s>
Opened 32 ADC channels
INFO:<Preparing ADC channels for test>
INFO:<Starting measurement>


/dev/adc00          \0x09= 0
/dev/adc01          \0x09= 0
/dev/adc02
          \0x09= 0
/dev/adc03          \0x09= 0
.
.
.
/dev/adc113         \0x09= 0
/dev/adc114         \0x09= 0
/dev/adc115         \0x09= 0
INFO:<Finished measurement>


----------------------------------------
Samples expected after 10210 milliseconds: 10210
Samples read (per channel):
/dev/adc00          \0x09= 0
.
.
.

On Mon, Apr 18, 2011 at 11:47, Christophe Coutand <ccoutand@stmi.com> wrote:
> Hi Jayant,
>
> You are using ecos-3.0 with the additional STM32 ADC package from CVS? It is usually not recommended to mix source code as it make it more difficult to get support from the mailing list.
>
> It is not enough to copy the directory packages\devs\adc\cortexm\stm32 in your repository, you must also include the package entry in the database (i.e. ecos.db):
>
> package CYGPKG_DEVS_ADC_CORTEXM_STM32 {
>    alias         { "STM32 ADC driver" adc_stm32 }
>    hardware
>    directory     devs/adc/cortexm/stm32
>    script        adc_stm32.cdl
>    description "
>    This package provides a driver for the ADC interfaces found on the
>    ST STM32 microcontroller family."
> }
>
> To build the STM32 HAL with ADC support from CVS repository, I do:
> $ ecosconfig.exe new stm3210e default
> $ ecosconfig.exe add io_adc
>
> You can configure the ADC from the GUI:
> $ configtool.exe ecos.ecc
>
> Example:
>
> http://dl.dropbox.com/u/21589565/misc/stm32_adc.JPG
>
> Regards,
> Christophe
>
> -----Original Message-----
> From: jayant biswas [mailto:biswasj@gmail.com]
> Sent: 18. april 2011 10:47
> To: John Dallaway; Christophe Coutand
> Cc: ecos-discuss@ecos.sourceware.org
> Subject: Re: stm3210e eval board adc question
>
> Thank you Christophe and John for your replies.
>
> I did checkout the cvs repository and was able to get the right folder
> i.e. packages\devs\adc\cortexm\stm32
>
> However, this hasn't solved my problem. I am still getting the same
> output as before when calling cyg_io_lookup and cyg_io_read.
>
> To integrate the new packages from the cvs. I copied  the entire
> repository over my ecos-3.0 folder. Then I regenerated the ecos.ecc
> file for stm3210e. I noticed here that the
> CYGPKG_DEVS_ADC_CORTEXM_STM32 checkboxes were grayed out. I then
> recompiled my application with the newly generated libraries.
>
> Please let me know if I am missing some steps. I am sure I am. Is
> there a guide that I can follow that shows how to integrate the ecos
> cvs packages?
>
> Best regards,
> Jayant
>
> On Wed, Apr 13, 2011 at 20:11, John Dallaway <john@dallaway.org.uk> wrote:
>> Hi Jayant
>>
>> jayant biswas wrote:
>>
>>> I installed ecos as indicated here
>>> http://ecos.sourceware.org/getstart.html .
>>
>> ... so you have the eCos 3.0 release repository.
>>
>> The STM32 ADC driver is not present in eCos 3.0. You will have to
>> checkout the eCos CVS repository in order to gain access to
>> CYGPKG_DEVS_ADC_CORTEXM_STM32. Ref:
>>
>>  http://ecos.sourceware.org/anoncvs.html
>>
>> I hope this helps...
>>
>> John Dallaway
>> eCos maintainer
>> http://www.dallaway.org.uk/john
>>
>

--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [ECOS] RE: stm3210e eval board adc question
  2011-04-18 14:49               ` [ECOS] " jayant biswas
@ 2011-04-19  7:27                 ` Christophe Coutand
  2011-04-19 12:43                   ` [ECOS] " jayant biswas
  0 siblings, 1 reply; 13+ messages in thread
From: Christophe Coutand @ 2011-04-19  7:27 UTC (permalink / raw)
  To: jayant biswas; +Cc: ecos-discuss

Hi Jayant,

From this documentation: http://www.st.com/stonline/books/pdf/docs/14220.pdf, the potentiometer is connected to PC4.

Looking at the IOs definition in: packages\hal\cortexm\stm32\var\current\include\var_io.h, you can sample PC4 using ADC1/14.

#define CYGHWR_HAL_STM32_ADC12_IN14             CYGHWR_HAL_STM32_GPIO( C, 4,  IN, ANALOG )
#define CYGHWR_HAL_STM32_ADC1_IN14              CYGHWR_HAL_STM32_ADC12_IN14

The adc2 test does not log any sampling results. It is used to check that the sampling rate is correct over a period of 10 seconds. The output of your test does not look good. The \0x09 is a tabulation that your terminal is not interpreting (which terminal do you use)? But the result is 0 for all channels, meaning that no samples are read. 

----------------------------------------
Samples expected after 10210 milliseconds: 10210
Samples read (per channel):
/dev/adc00          \0x09= 0

Do you have a way to step into the code? I don't clearly see how the test can complete without reading samples. Line 181 is a loop waiting for samples:

 // Read & count samples
 do {
    cyg_uint32 len = sizeof(sample);
    res = cyg_io_read(chan->handle, &sample, &len);
    if (res == ENOERR)
       chan->count++;
 } while (res == ENOERR);

You can also try the adc1 test which shall read and display the sampled data. I don't own a STM3210e boards therefore can't give it a try.

Regards,
Christophe

-----Original Message-----
From: jayant biswas [mailto:biswasj@gmail.com] 
Sent: 18. april 2011 16:49
To: Christophe Coutand
Cc: ecos-discuss@ecos.sourceware.org
Subject: Re: stm3210e eval board adc question

Dear Christophe!

Thanks for your support. I have a feeling I am getting closer, but not
quite there yet. So I appreciate your time in helping me out. Now I
have been able to add the adc io, as in the screenshot you sent using
only the cvs code. So I am not mixing anymore ecos-3.0 and the cvs.
But when I run the tests on my stm3210e eval board I do not get the
desired output. The output of adc2 test is shown below. It shows that
no samples have been read. I am also not sure what to make of the
\0x09 stuff before the '=' signs.

My goal is to be able to read the value from the potentiometer on the
board (http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DATA_BRIEF/CD00278458.pdf
as shown on page 2/3) and eventually also from the 3 bnc connectors.
First of all, how can I know which input (BNC or Potentiometer) is
connected to which device on which channel? And secondly why when I
try to display values from all channels on both devices I receive
nothing. One of these channels must be connected to the potentiometer
no? The BNC connectors are currently left open.

Hope I can make this work.

Regards,
Jayant

\0x00INFO:<ADC performance test>
INFO:<Opening available ADC channel
s>
Opened 32 ADC channels
INFO:<Preparing ADC channels for test>
INFO:<Starting measurement>


/dev/adc00          \0x09= 0
/dev/adc01          \0x09= 0
/dev/adc02
          \0x09= 0
/dev/adc03          \0x09= 0
.
.
.
/dev/adc113         \0x09= 0
/dev/adc114         \0x09= 0
/dev/adc115         \0x09= 0
INFO:<Finished measurement>


----------------------------------------
Samples expected after 10210 milliseconds: 10210
Samples read (per channel):
/dev/adc00          \0x09= 0
.
.
.

On Mon, Apr 18, 2011 at 11:47, Christophe Coutand <ccoutand@stmi.com> wrote:
> Hi Jayant,
>
> You are using ecos-3.0 with the additional STM32 ADC package from CVS? It is usually not recommended to mix source code as it make it more difficult to get support from the mailing list.
>
> It is not enough to copy the directory packages\devs\adc\cortexm\stm32 in your repository, you must also include the package entry in the database (i.e. ecos.db):
>
> package CYGPKG_DEVS_ADC_CORTEXM_STM32 {
>    alias         { "STM32 ADC driver" adc_stm32 }
>    hardware
>    directory     devs/adc/cortexm/stm32
>    script        adc_stm32.cdl
>    description "
>    This package provides a driver for the ADC interfaces found on the
>    ST STM32 microcontroller family."
> }
>
> To build the STM32 HAL with ADC support from CVS repository, I do:
> $ ecosconfig.exe new stm3210e default
> $ ecosconfig.exe add io_adc
>
> You can configure the ADC from the GUI:
> $ configtool.exe ecos.ecc
>
> Example:
>
> http://dl.dropbox.com/u/21589565/misc/stm32_adc.JPG
>
> Regards,
> Christophe
>
> -----Original Message-----
> From: jayant biswas [mailto:biswasj@gmail.com]
> Sent: 18. april 2011 10:47
> To: John Dallaway; Christophe Coutand
> Cc: ecos-discuss@ecos.sourceware.org
> Subject: Re: stm3210e eval board adc question
>
> Thank you Christophe and John for your replies.
>
> I did checkout the cvs repository and was able to get the right folder
> i.e. packages\devs\adc\cortexm\stm32
>
> However, this hasn't solved my problem. I am still getting the same
> output as before when calling cyg_io_lookup and cyg_io_read.
>
> To integrate the new packages from the cvs. I copied  the entire
> repository over my ecos-3.0 folder. Then I regenerated the ecos.ecc
> file for stm3210e. I noticed here that the
> CYGPKG_DEVS_ADC_CORTEXM_STM32 checkboxes were grayed out. I then
> recompiled my application with the newly generated libraries.
>
> Please let me know if I am missing some steps. I am sure I am. Is
> there a guide that I can follow that shows how to integrate the ecos
> cvs packages?
>
> Best regards,
> Jayant
>
> On Wed, Apr 13, 2011 at 20:11, John Dallaway <john@dallaway.org.uk> wrote:
>> Hi Jayant
>>
>> jayant biswas wrote:
>>
>>> I installed ecos as indicated here
>>> http://ecos.sourceware.org/getstart.html .
>>
>> ... so you have the eCos 3.0 release repository.
>>
>> The STM32 ADC driver is not present in eCos 3.0. You will have to
>> checkout the eCos CVS repository in order to gain access to
>> CYGPKG_DEVS_ADC_CORTEXM_STM32. Ref:
>>
>>  http://ecos.sourceware.org/anoncvs.html
>>
>> I hope this helps...
>>
>> John Dallaway
>> eCos maintainer
>> http://www.dallaway.org.uk/john
>>
>

--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [ECOS] Re: stm3210e eval board adc question
  2011-04-19  7:27                 ` [ECOS] " Christophe Coutand
@ 2011-04-19 12:43                   ` jayant biswas
  2011-05-02 10:16                     ` jayant biswas
  0 siblings, 1 reply; 13+ messages in thread
From: jayant biswas @ 2011-04-19 12:43 UTC (permalink / raw)
  To: Christophe Coutand; +Cc: ecos-discuss

Hi Christophe.

Thanks for the info about how to find out which channel corresponds to
which input. This will be useful for me.

As for the terminal I am using cutecom on ubuntu. 38400,8,1, parity
none, no handshake, open for reading and writing.

I tried running the adc1 test and that only runs this far:
\0x00INFO:<ADC test>
Testing ADC channel '/dev/adc00'

when I force stop the program it says the following
(gdb) continue
Continuing.
^C
Program received signal SIGINT, Interrupt.
0x08003832 in Cyg_Mutex::lock (this=0x6800001c)
    at /home/jayant/ecos/adc/ecos_install/include/cyg/kernel/sched.inl:99
99	    if( __lock == 0 ) unlock_inner(0);
Current language:  auto; currently c++

Stepping through adc2 in gdb with a breakpoint on line 181 as you
mentioned i get this
(gdb) break adc2.c:181
Breakpoint 1 at 0x800027e: file adc2.c, line 181.
(gdb) continue
Continuing.
Note: automatically using hardware breakpoints for read-only addresses.

Breakpoint 1, adc_thread (data=<value optimized out>) at adc2.c:181
181	                cyg_uint32 len = sizeof(sample);
(gdb) info frame
Stack level 0, frame at 0x68004668:
 pc = 0x800027e in adc_thread (adc2.c:181); saved pc 0x8002b4e
 called by frame at 0x68004670
 source language c.
 Arglist at 0x68004628, args: data=<value optimized out>
 Locals at 0x68004628, Previous frame's sp is 0x68004668
 Saved registers:
  r4 at 0x68004644, r5 at 0x68004648, r6 at 0x6800464c, r7 at
0x68004650, r8 at 0x68004654,
  r9 at 0x68004658, r10 at 0x6800465c, r11 at 0x68004660, lr at 0x68004664
(gdb) print len
$1 = <value optimized out>
(gdb) print sample
$2 = 26624
(gdb) s
cortex_m3 interrupt mask on
176	        for (i = 0; i < num; i++) {
cortex_m3 interrupt mask off
(gdb) print len
$3 = 2
(gdb) print sample
$4 = 26624
(gdb) s
cortex_m3 interrupt mask on
177	            chan = &test_channels[i];
cortex_m3 interrupt mask off
(gdb) s
cortex_m3 interrupt mask on
182	                res = cyg_io_read(chan->handle, &sample, &len);
cortex_m3 interrupt mask off
(gdb) s
cortex_m3 interrupt mask on
181	                cyg_uint32 len = sizeof(sample);
cortex_m3 interrupt mask off
(gdb) print len
$5 = 0
(gdb) print sample
$6 = 26624
(gdb)

Not sure what I should be looking for here. Can you please suggest how
I may proceed to find the problem?

Thanks again
Jayant

On Tue, Apr 19, 2011 at 09:25, Christophe Coutand <ccoutand@stmi.com> wrote:
> Hi Jayant,
>
> From this documentation: http://www.st.com/stonline/books/pdf/docs/14220.pdf, the potentiometer is connected to PC4.
>
> Looking at the IOs definition in: packages\hal\cortexm\stm32\var\current\include\var_io.h, you can sample PC4 using ADC1/14.
>
> #define CYGHWR_HAL_STM32_ADC12_IN14             CYGHWR_HAL_STM32_GPIO( C, 4,  IN, ANALOG )
> #define CYGHWR_HAL_STM32_ADC1_IN14              CYGHWR_HAL_STM32_ADC12_IN14
>
> The adc2 test does not log any sampling results. It is used to check that the sampling rate is correct over a period of 10 seconds. The output of your test does not look good. The \0x09 is a tabulation that your terminal is not interpreting (which terminal do you use)? But the result is 0 for all channels, meaning that no samples are read.
>
> ----------------------------------------
> Samples expected after 10210 milliseconds: 10210
> Samples read (per channel):
> /dev/adc00          \0x09= 0
>
> Do you have a way to step into the code? I don't clearly see how the test can complete without reading samples. Line 181 is a loop waiting for samples:
>
>  // Read & count samples
>  do {
>    cyg_uint32 len = sizeof(sample);
>    res = cyg_io_read(chan->handle, &sample, &len);
>    if (res == ENOERR)
>       chan->count++;
>  } while (res == ENOERR);
>
> You can also try the adc1 test which shall read and display the sampled data. I don't own a STM3210e boards therefore can't give it a try.
>
> Regards,
> Christophe
>
> -----Original Message-----
> From: jayant biswas [mailto:biswasj@gmail.com]
> Sent: 18. april 2011 16:49
> To: Christophe Coutand
> Cc: ecos-discuss@ecos.sourceware.org
> Subject: Re: stm3210e eval board adc question
>
> Dear Christophe!
>
> Thanks for your support. I have a feeling I am getting closer, but not
> quite there yet. So I appreciate your time in helping me out. Now I
> have been able to add the adc io, as in the screenshot you sent using
> only the cvs code. So I am not mixing anymore ecos-3.0 and the cvs.
> But when I run the tests on my stm3210e eval board I do not get the
> desired output. The output of adc2 test is shown below. It shows that
> no samples have been read. I am also not sure what to make of the
> \0x09 stuff before the '=' signs.
>
> My goal is to be able to read the value from the potentiometer on the
> board (http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DATA_BRIEF/CD00278458.pdf
> as shown on page 2/3) and eventually also from the 3 bnc connectors.
> First of all, how can I know which input (BNC or Potentiometer) is
> connected to which device on which channel? And secondly why when I
> try to display values from all channels on both devices I receive
> nothing. One of these channels must be connected to the potentiometer
> no? The BNC connectors are currently left open.
>
> Hope I can make this work.
>
> Regards,
> Jayant
>
> \0x00INFO:<ADC performance test>
> INFO:<Opening available ADC channel
> s>
> Opened 32 ADC channels
> INFO:<Preparing ADC channels for test>
> INFO:<Starting measurement>
>
>
> /dev/adc00          \0x09= 0
> /dev/adc01          \0x09= 0
> /dev/adc02
>          \0x09= 0
> /dev/adc03          \0x09= 0
> .
> .
> .
> /dev/adc113         \0x09= 0
> /dev/adc114         \0x09= 0
> /dev/adc115         \0x09= 0
> INFO:<Finished measurement>
>
>
> ----------------------------------------
> Samples expected after 10210 milliseconds: 10210
> Samples read (per channel):
> /dev/adc00          \0x09= 0
> .
> .
> .
>
> On Mon, Apr 18, 2011 at 11:47, Christophe Coutand <ccoutand@stmi.com> wrote:
>> Hi Jayant,
>>
>> You are using ecos-3.0 with the additional STM32 ADC package from CVS? It is usually not recommended to mix source code as it make it more difficult to get support from the mailing list.
>>
>> It is not enough to copy the directory packages\devs\adc\cortexm\stm32 in your repository, you must also include the package entry in the database (i.e. ecos.db):
>>
>> package CYGPKG_DEVS_ADC_CORTEXM_STM32 {
>>    alias         { "STM32 ADC driver" adc_stm32 }
>>    hardware
>>    directory     devs/adc/cortexm/stm32
>>    script        adc_stm32.cdl
>>    description "
>>    This package provides a driver for the ADC interfaces found on the
>>    ST STM32 microcontroller family."
>> }
>>
>> To build the STM32 HAL with ADC support from CVS repository, I do:
>> $ ecosconfig.exe new stm3210e default
>> $ ecosconfig.exe add io_adc
>>
>> You can configure the ADC from the GUI:
>> $ configtool.exe ecos.ecc
>>
>> Example:
>>
>> http://dl.dropbox.com/u/21589565/misc/stm32_adc.JPG
>>
>> Regards,
>> Christophe
>>
>> -----Original Message-----
>> From: jayant biswas [mailto:biswasj@gmail.com]
>> Sent: 18. april 2011 10:47
>> To: John Dallaway; Christophe Coutand
>> Cc: ecos-discuss@ecos.sourceware.org
>> Subject: Re: stm3210e eval board adc question
>>
>> Thank you Christophe and John for your replies.
>>
>> I did checkout the cvs repository and was able to get the right folder
>> i.e. packages\devs\adc\cortexm\stm32
>>
>> However, this hasn't solved my problem. I am still getting the same
>> output as before when calling cyg_io_lookup and cyg_io_read.
>>
>> To integrate the new packages from the cvs. I copied  the entire
>> repository over my ecos-3.0 folder. Then I regenerated the ecos.ecc
>> file for stm3210e. I noticed here that the
>> CYGPKG_DEVS_ADC_CORTEXM_STM32 checkboxes were grayed out. I then
>> recompiled my application with the newly generated libraries.
>>
>> Please let me know if I am missing some steps. I am sure I am. Is
>> there a guide that I can follow that shows how to integrate the ecos
>> cvs packages?
>>
>> Best regards,
>> Jayant
>>
>> On Wed, Apr 13, 2011 at 20:11, John Dallaway <john@dallaway.org.uk> wrote:
>>> Hi Jayant
>>>
>>> jayant biswas wrote:
>>>
>>>> I installed ecos as indicated here
>>>> http://ecos.sourceware.org/getstart.html .
>>>
>>> ... so you have the eCos 3.0 release repository.
>>>
>>> The STM32 ADC driver is not present in eCos 3.0. You will have to
>>> checkout the eCos CVS repository in order to gain access to
>>> CYGPKG_DEVS_ADC_CORTEXM_STM32. Ref:
>>>
>>>  http://ecos.sourceware.org/anoncvs.html
>>>
>>> I hope this helps...
>>>
>>> John Dallaway
>>> eCos maintainer
>>> http://www.dallaway.org.uk/john
>>>
>>
>

--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [ECOS] Re: stm3210e eval board adc question
  2011-04-19 12:43                   ` [ECOS] " jayant biswas
@ 2011-05-02 10:16                     ` jayant biswas
  2011-05-02 21:45                       ` [ECOS] " Christophe Coutand
  0 siblings, 1 reply; 13+ messages in thread
From: jayant biswas @ 2011-05-02 10:16 UTC (permalink / raw)
  To: Christophe Coutand; +Cc: ecos-discuss

Hello again!

I have tried stepping through the code for adc1.c. Stepping from line
124 in adc1.c, I notice that when trying to read from the channels it
is always waiting for data to be available on /dev/adc014. This means
that in packages/io/adc/current/src/adc.c it never reaches line 131
(// A sample is available, transfer it to the buffer).

Do you have an idea why the data is never available from the
potentiometer on the  STM3210E-eval board? Let me know if I can
provide more information about my tests.

Thank you,
Jayant

On Tue, Apr 19, 2011 at 14:42, jayant biswas <biswasj@gmail.com> wrote:
> Hi Christophe.
>
> Thanks for the info about how to find out which channel corresponds to
> which input. This will be useful for me.
>
> As for the terminal I am using cutecom on ubuntu. 38400,8,1, parity
> none, no handshake, open for reading and writing.
>
> I tried running the adc1 test and that only runs this far:
> \0x00INFO:<ADC test>
> Testing ADC channel '/dev/adc00'
>
> when I force stop the program it says the following
> (gdb) continue
> Continuing.
> ^C
> Program received signal SIGINT, Interrupt.
> 0x08003832 in Cyg_Mutex::lock (this=0x6800001c)
>    at /home/jayant/ecos/adc/ecos_install/include/cyg/kernel/sched.inl:99
> 99          if( __lock == 0 ) unlock_inner(0);
> Current language:  auto; currently c++
>
> Stepping through adc2 in gdb with a breakpoint on line 181 as you
> mentioned i get this
> (gdb) break adc2.c:181
> Breakpoint 1 at 0x800027e: file adc2.c, line 181.
> (gdb) continue
> Continuing.
> Note: automatically using hardware breakpoints for read-only addresses.
>
> Breakpoint 1, adc_thread (data=<value optimized out>) at adc2.c:181
> 181                     cyg_uint32 len = sizeof(sample);
> (gdb) info frame
> Stack level 0, frame at 0x68004668:
>  pc = 0x800027e in adc_thread (adc2.c:181); saved pc 0x8002b4e
>  called by frame at 0x68004670
>  source language c.
>  Arglist at 0x68004628, args: data=<value optimized out>
>  Locals at 0x68004628, Previous frame's sp is 0x68004668
>  Saved registers:
>  r4 at 0x68004644, r5 at 0x68004648, r6 at 0x6800464c, r7 at
> 0x68004650, r8 at 0x68004654,
>  r9 at 0x68004658, r10 at 0x6800465c, r11 at 0x68004660, lr at 0x68004664
> (gdb) print len
> $1 = <value optimized out>
> (gdb) print sample
> $2 = 26624
> (gdb) s
> cortex_m3 interrupt mask on
> 176             for (i = 0; i < num; i++) {
> cortex_m3 interrupt mask off
> (gdb) print len
> $3 = 2
> (gdb) print sample
> $4 = 26624
> (gdb) s
> cortex_m3 interrupt mask on
> 177                 chan = &test_channels[i];
> cortex_m3 interrupt mask off
> (gdb) s
> cortex_m3 interrupt mask on
> 182                     res = cyg_io_read(chan->handle, &sample, &len);
> cortex_m3 interrupt mask off
> (gdb) s
> cortex_m3 interrupt mask on
> 181                     cyg_uint32 len = sizeof(sample);
> cortex_m3 interrupt mask off
> (gdb) print len
> $5 = 0
> (gdb) print sample
> $6 = 26624
> (gdb)
>
> Not sure what I should be looking for here. Can you please suggest how
> I may proceed to find the problem?
>
> Thanks again
> Jayant
>
> On Tue, Apr 19, 2011 at 09:25, Christophe Coutand <ccoutand@stmi.com> wrote:
>> Hi Jayant,
>>
>> From this documentation: http://www.st.com/stonline/books/pdf/docs/14220.pdf, the potentiometer is connected to PC4.
>>
>> Looking at the IOs definition in: packages\hal\cortexm\stm32\var\current\include\var_io.h, you can sample PC4 using ADC1/14.
>>
>> #define CYGHWR_HAL_STM32_ADC12_IN14             CYGHWR_HAL_STM32_GPIO( C, 4,  IN, ANALOG )
>> #define CYGHWR_HAL_STM32_ADC1_IN14              CYGHWR_HAL_STM32_ADC12_IN14
>>
>> The adc2 test does not log any sampling results. It is used to check that the sampling rate is correct over a period of 10 seconds. The output of your test does not look good. The \0x09 is a tabulation that your terminal is not interpreting (which terminal do you use)? But the result is 0 for all channels, meaning that no samples are read.
>>
>> ----------------------------------------
>> Samples expected after 10210 milliseconds: 10210
>> Samples read (per channel):
>> /dev/adc00          \0x09= 0
>>
>> Do you have a way to step into the code? I don't clearly see how the test can complete without reading samples. Line 181 is a loop waiting for samples:
>>
>>  // Read & count samples
>>  do {
>>    cyg_uint32 len = sizeof(sample);
>>    res = cyg_io_read(chan->handle, &sample, &len);
>>    if (res == ENOERR)
>>       chan->count++;
>>  } while (res == ENOERR);
>>
>> You can also try the adc1 test which shall read and display the sampled data. I don't own a STM3210e boards therefore can't give it a try.
>>
>> Regards,
>> Christophe
>>
>> -----Original Message-----
>> From: jayant biswas [mailto:biswasj@gmail.com]
>> Sent: 18. april 2011 16:49
>> To: Christophe Coutand
>> Cc: ecos-discuss@ecos.sourceware.org
>> Subject: Re: stm3210e eval board adc question
>>
>> Dear Christophe!
>>
>> Thanks for your support. I have a feeling I am getting closer, but not
>> quite there yet. So I appreciate your time in helping me out. Now I
>> have been able to add the adc io, as in the screenshot you sent using
>> only the cvs code. So I am not mixing anymore ecos-3.0 and the cvs.
>> But when I run the tests on my stm3210e eval board I do not get the
>> desired output. The output of adc2 test is shown below. It shows that
>> no samples have been read. I am also not sure what to make of the
>> \0x09 stuff before the '=' signs.
>>
>> My goal is to be able to read the value from the potentiometer on the
>> board (http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DATA_BRIEF/CD00278458.pdf
>> as shown on page 2/3) and eventually also from the 3 bnc connectors.
>> First of all, how can I know which input (BNC or Potentiometer) is
>> connected to which device on which channel? And secondly why when I
>> try to display values from all channels on both devices I receive
>> nothing. One of these channels must be connected to the potentiometer
>> no? The BNC connectors are currently left open.
>>
>> Hope I can make this work.
>>
>> Regards,
>> Jayant
>>
>> \0x00INFO:<ADC performance test>
>> INFO:<Opening available ADC channel
>> s>
>> Opened 32 ADC channels
>> INFO:<Preparing ADC channels for test>
>> INFO:<Starting measurement>
>>
>>
>> /dev/adc00          \0x09= 0
>> /dev/adc01          \0x09= 0
>> /dev/adc02
>>          \0x09= 0
>> /dev/adc03          \0x09= 0
>> .
>> .
>> .
>> /dev/adc113         \0x09= 0
>> /dev/adc114         \0x09= 0
>> /dev/adc115         \0x09= 0
>> INFO:<Finished measurement>
>>
>>
>> ----------------------------------------
>> Samples expected after 10210 milliseconds: 10210
>> Samples read (per channel):
>> /dev/adc00          \0x09= 0
>> .
>> .
>> .
>>
>> On Mon, Apr 18, 2011 at 11:47, Christophe Coutand <ccoutand@stmi.com> wrote:
>>> Hi Jayant,
>>>
>>> You are using ecos-3.0 with the additional STM32 ADC package from CVS? It is usually not recommended to mix source code as it make it more difficult to get support from the mailing list.
>>>
>>> It is not enough to copy the directory packages\devs\adc\cortexm\stm32 in your repository, you must also include the package entry in the database (i.e. ecos.db):
>>>
>>> package CYGPKG_DEVS_ADC_CORTEXM_STM32 {
>>>    alias         { "STM32 ADC driver" adc_stm32 }
>>>    hardware
>>>    directory     devs/adc/cortexm/stm32
>>>    script        adc_stm32.cdl
>>>    description "
>>>    This package provides a driver for the ADC interfaces found on the
>>>    ST STM32 microcontroller family."
>>> }
>>>
>>> To build the STM32 HAL with ADC support from CVS repository, I do:
>>> $ ecosconfig.exe new stm3210e default
>>> $ ecosconfig.exe add io_adc
>>>
>>> You can configure the ADC from the GUI:
>>> $ configtool.exe ecos.ecc
>>>
>>> Example:
>>>
>>> http://dl.dropbox.com/u/21589565/misc/stm32_adc.JPG
>>>
>>> Regards,
>>> Christophe
>>>
>>> -----Original Message-----
>>> From: jayant biswas [mailto:biswasj@gmail.com]
>>> Sent: 18. april 2011 10:47
>>> To: John Dallaway; Christophe Coutand
>>> Cc: ecos-discuss@ecos.sourceware.org
>>> Subject: Re: stm3210e eval board adc question
>>>
>>> Thank you Christophe and John for your replies.
>>>
>>> I did checkout the cvs repository and was able to get the right folder
>>> i.e. packages\devs\adc\cortexm\stm32
>>>
>>> However, this hasn't solved my problem. I am still getting the same
>>> output as before when calling cyg_io_lookup and cyg_io_read.
>>>
>>> To integrate the new packages from the cvs. I copied  the entire
>>> repository over my ecos-3.0 folder. Then I regenerated the ecos.ecc
>>> file for stm3210e. I noticed here that the
>>> CYGPKG_DEVS_ADC_CORTEXM_STM32 checkboxes were grayed out. I then
>>> recompiled my application with the newly generated libraries.
>>>
>>> Please let me know if I am missing some steps. I am sure I am. Is
>>> there a guide that I can follow that shows how to integrate the ecos
>>> cvs packages?
>>>
>>> Best regards,
>>> Jayant
>>>
>>> On Wed, Apr 13, 2011 at 20:11, John Dallaway <john@dallaway.org.uk> wrote:
>>>> Hi Jayant
>>>>
>>>> jayant biswas wrote:
>>>>
>>>>> I installed ecos as indicated here
>>>>> http://ecos.sourceware.org/getstart.html .
>>>>
>>>> ... so you have the eCos 3.0 release repository.
>>>>
>>>> The STM32 ADC driver is not present in eCos 3.0. You will have to
>>>> checkout the eCos CVS repository in order to gain access to
>>>> CYGPKG_DEVS_ADC_CORTEXM_STM32. Ref:
>>>>
>>>>  http://ecos.sourceware.org/anoncvs.html
>>>>
>>>> I hope this helps...
>>>>
>>>> John Dallaway
>>>> eCos maintainer
>>>> http://www.dallaway.org.uk/john
>>>>
>>>
>>
>

--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [ECOS] RE: stm3210e eval board adc question
  2011-05-02 10:16                     ` jayant biswas
@ 2011-05-02 21:45                       ` Christophe Coutand
  2011-05-03  7:58                         ` [ECOS] " jayant biswas
  0 siblings, 1 reply; 13+ messages in thread
From: Christophe Coutand @ 2011-05-02 21:45 UTC (permalink / raw)
  To: jayant biswas; +Cc: ecos-discuss

[-- Attachment #1: Type: text/plain, Size: 10278 bytes --]

Hi Jayant,

While reviewing the code I found few issues in the ADC driver. Please try with the attached code and let me know if it works for you.

Christophe


-----Original Message-----
From: jayant biswas [mailto:biswasj@gmail.com] 
Sent: 2. mai 2011 12:16
To: Christophe Coutand
Cc: ecos-discuss@ecos.sourceware.org
Subject: Re: stm3210e eval board adc question

Hello again!

I have tried stepping through the code for adc1.c. Stepping from line
124 in adc1.c, I notice that when trying to read from the channels it
is always waiting for data to be available on /dev/adc014. This means
that in packages/io/adc/current/src/adc.c it never reaches line 131
(// A sample is available, transfer it to the buffer).

Do you have an idea why the data is never available from the
potentiometer on the  STM3210E-eval board? Let me know if I can
provide more information about my tests.

Thank you,
Jayant

On Tue, Apr 19, 2011 at 14:42, jayant biswas <biswasj@gmail.com> wrote:
> Hi Christophe.
>
> Thanks for the info about how to find out which channel corresponds to
> which input. This will be useful for me.
>
> As for the terminal I am using cutecom on ubuntu. 38400,8,1, parity
> none, no handshake, open for reading and writing.
>
> I tried running the adc1 test and that only runs this far:
> \0x00INFO:<ADC test>
> Testing ADC channel '/dev/adc00'
>
> when I force stop the program it says the following
> (gdb) continue
> Continuing.
> ^C
> Program received signal SIGINT, Interrupt.
> 0x08003832 in Cyg_Mutex::lock (this=0x6800001c)
>    at /home/jayant/ecos/adc/ecos_install/include/cyg/kernel/sched.inl:99
> 99          if( __lock == 0 ) unlock_inner(0);
> Current language:  auto; currently c++
>
> Stepping through adc2 in gdb with a breakpoint on line 181 as you
> mentioned i get this
> (gdb) break adc2.c:181
> Breakpoint 1 at 0x800027e: file adc2.c, line 181.
> (gdb) continue
> Continuing.
> Note: automatically using hardware breakpoints for read-only addresses.
>
> Breakpoint 1, adc_thread (data=<value optimized out>) at adc2.c:181
> 181                     cyg_uint32 len = sizeof(sample);
> (gdb) info frame
> Stack level 0, frame at 0x68004668:
>  pc = 0x800027e in adc_thread (adc2.c:181); saved pc 0x8002b4e
>  called by frame at 0x68004670
>  source language c.
>  Arglist at 0x68004628, args: data=<value optimized out>
>  Locals at 0x68004628, Previous frame's sp is 0x68004668
>  Saved registers:
>  r4 at 0x68004644, r5 at 0x68004648, r6 at 0x6800464c, r7 at
> 0x68004650, r8 at 0x68004654,
>  r9 at 0x68004658, r10 at 0x6800465c, r11 at 0x68004660, lr at 0x68004664
> (gdb) print len
> $1 = <value optimized out>
> (gdb) print sample
> $2 = 26624
> (gdb) s
> cortex_m3 interrupt mask on
> 176             for (i = 0; i < num; i++) {
> cortex_m3 interrupt mask off
> (gdb) print len
> $3 = 2
> (gdb) print sample
> $4 = 26624
> (gdb) s
> cortex_m3 interrupt mask on
> 177                 chan = &test_channels[i];
> cortex_m3 interrupt mask off
> (gdb) s
> cortex_m3 interrupt mask on
> 182                     res = cyg_io_read(chan->handle, &sample, &len);
> cortex_m3 interrupt mask off
> (gdb) s
> cortex_m3 interrupt mask on
> 181                     cyg_uint32 len = sizeof(sample);
> cortex_m3 interrupt mask off
> (gdb) print len
> $5 = 0
> (gdb) print sample
> $6 = 26624
> (gdb)
>
> Not sure what I should be looking for here. Can you please suggest how
> I may proceed to find the problem?
>
> Thanks again
> Jayant
>
> On Tue, Apr 19, 2011 at 09:25, Christophe Coutand <ccoutand@stmi.com> wrote:
>> Hi Jayant,
>>
>> From this documentation: http://www.st.com/stonline/books/pdf/docs/14220.pdf, the potentiometer is connected to PC4.
>>
>> Looking at the IOs definition in: packages\hal\cortexm\stm32\var\current\include\var_io.h, you can sample PC4 using ADC1/14.
>>
>> #define CYGHWR_HAL_STM32_ADC12_IN14             CYGHWR_HAL_STM32_GPIO( C, 4,  IN, ANALOG )
>> #define CYGHWR_HAL_STM32_ADC1_IN14              CYGHWR_HAL_STM32_ADC12_IN14
>>
>> The adc2 test does not log any sampling results. It is used to check that the sampling rate is correct over a period of 10 seconds. The output of your test does not look good. The \0x09 is a tabulation that your terminal is not interpreting (which terminal do you use)? But the result is 0 for all channels, meaning that no samples are read.
>>
>> ----------------------------------------
>> Samples expected after 10210 milliseconds: 10210
>> Samples read (per channel):
>> /dev/adc00          \0x09= 0
>>
>> Do you have a way to step into the code? I don't clearly see how the test can complete without reading samples. Line 181 is a loop waiting for samples:
>>
>>  // Read & count samples
>>  do {
>>    cyg_uint32 len = sizeof(sample);
>>    res = cyg_io_read(chan->handle, &sample, &len);
>>    if (res == ENOERR)
>>       chan->count++;
>>  } while (res == ENOERR);
>>
>> You can also try the adc1 test which shall read and display the sampled data. I don't own a STM3210e boards therefore can't give it a try.
>>
>> Regards,
>> Christophe
>>
>> -----Original Message-----
>> From: jayant biswas [mailto:biswasj@gmail.com]
>> Sent: 18. april 2011 16:49
>> To: Christophe Coutand
>> Cc: ecos-discuss@ecos.sourceware.org
>> Subject: Re: stm3210e eval board adc question
>>
>> Dear Christophe!
>>
>> Thanks for your support. I have a feeling I am getting closer, but not
>> quite there yet. So I appreciate your time in helping me out. Now I
>> have been able to add the adc io, as in the screenshot you sent using
>> only the cvs code. So I am not mixing anymore ecos-3.0 and the cvs.
>> But when I run the tests on my stm3210e eval board I do not get the
>> desired output. The output of adc2 test is shown below. It shows that
>> no samples have been read. I am also not sure what to make of the
>> \0x09 stuff before the '=' signs.
>>
>> My goal is to be able to read the value from the potentiometer on the
>> board (http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DATA_BRIEF/CD00278458.pdf
>> as shown on page 2/3) and eventually also from the 3 bnc connectors.
>> First of all, how can I know which input (BNC or Potentiometer) is
>> connected to which device on which channel? And secondly why when I
>> try to display values from all channels on both devices I receive
>> nothing. One of these channels must be connected to the potentiometer
>> no? The BNC connectors are currently left open.
>>
>> Hope I can make this work.
>>
>> Regards,
>> Jayant
>>
>> \0x00INFO:<ADC performance test>
>> INFO:<Opening available ADC channel
>> s>
>> Opened 32 ADC channels
>> INFO:<Preparing ADC channels for test>
>> INFO:<Starting measurement>
>>
>>
>> /dev/adc00          \0x09= 0
>> /dev/adc01          \0x09= 0
>> /dev/adc02
>>          \0x09= 0
>> /dev/adc03          \0x09= 0
>> .
>> .
>> .
>> /dev/adc113         \0x09= 0
>> /dev/adc114         \0x09= 0
>> /dev/adc115         \0x09= 0
>> INFO:<Finished measurement>
>>
>>
>> ----------------------------------------
>> Samples expected after 10210 milliseconds: 10210
>> Samples read (per channel):
>> /dev/adc00          \0x09= 0
>> .
>> .
>> .
>>
>> On Mon, Apr 18, 2011 at 11:47, Christophe Coutand <ccoutand@stmi.com> wrote:
>>> Hi Jayant,
>>>
>>> You are using ecos-3.0 with the additional STM32 ADC package from CVS? It is usually not recommended to mix source code as it make it more difficult to get support from the mailing list.
>>>
>>> It is not enough to copy the directory packages\devs\adc\cortexm\stm32 in your repository, you must also include the package entry in the database (i.e. ecos.db):
>>>
>>> package CYGPKG_DEVS_ADC_CORTEXM_STM32 {
>>>    alias         { "STM32 ADC driver" adc_stm32 }
>>>    hardware
>>>    directory     devs/adc/cortexm/stm32
>>>    script        adc_stm32.cdl
>>>    description "
>>>    This package provides a driver for the ADC interfaces found on the
>>>    ST STM32 microcontroller family."
>>> }
>>>
>>> To build the STM32 HAL with ADC support from CVS repository, I do:
>>> $ ecosconfig.exe new stm3210e default
>>> $ ecosconfig.exe add io_adc
>>>
>>> You can configure the ADC from the GUI:
>>> $ configtool.exe ecos.ecc
>>>
>>> Example:
>>>
>>> http://dl.dropbox.com/u/21589565/misc/stm32_adc.JPG
>>>
>>> Regards,
>>> Christophe
>>>
>>> -----Original Message-----
>>> From: jayant biswas [mailto:biswasj@gmail.com]
>>> Sent: 18. april 2011 10:47
>>> To: John Dallaway; Christophe Coutand
>>> Cc: ecos-discuss@ecos.sourceware.org
>>> Subject: Re: stm3210e eval board adc question
>>>
>>> Thank you Christophe and John for your replies.
>>>
>>> I did checkout the cvs repository and was able to get the right folder
>>> i.e. packages\devs\adc\cortexm\stm32
>>>
>>> However, this hasn't solved my problem. I am still getting the same
>>> output as before when calling cyg_io_lookup and cyg_io_read.
>>>
>>> To integrate the new packages from the cvs. I copied  the entire
>>> repository over my ecos-3.0 folder. Then I regenerated the ecos.ecc
>>> file for stm3210e. I noticed here that the
>>> CYGPKG_DEVS_ADC_CORTEXM_STM32 checkboxes were grayed out. I then
>>> recompiled my application with the newly generated libraries.
>>>
>>> Please let me know if I am missing some steps. I am sure I am. Is
>>> there a guide that I can follow that shows how to integrate the ecos
>>> cvs packages?
>>>
>>> Best regards,
>>> Jayant
>>>
>>> On Wed, Apr 13, 2011 at 20:11, John Dallaway <john@dallaway.org.uk> wrote:
>>>> Hi Jayant
>>>>
>>>> jayant biswas wrote:
>>>>
>>>>> I installed ecos as indicated here
>>>>> http://ecos.sourceware.org/getstart.html .
>>>>
>>>> ... so you have the eCos 3.0 release repository.
>>>>
>>>> The STM32 ADC driver is not present in eCos 3.0. You will have to
>>>> checkout the eCos CVS repository in order to gain access to
>>>> CYGPKG_DEVS_ADC_CORTEXM_STM32. Ref:
>>>>
>>>>  http://ecos.sourceware.org/anoncvs.html
>>>>
>>>> I hope this helps...
>>>>
>>>> John Dallaway
>>>> eCos maintainer
>>>> http://www.dallaway.org.uk/john
>>>>
>>>
>>
>

[-- Attachment #2: adc_stm32.c --]
[-- Type: application/octet-stream, Size: 24322 bytes --]

//==========================================================================
//
//      adc_stm32.c
//
//      ADC driver for STM32 on chip ADC
//
//==========================================================================
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
// -------------------------------------------                              
// This file is part of eCos, the Embedded Configurable Operating System.   
// Copyright (C) 2009 Free Software Foundation, Inc.                        
//
// eCos is free software; you can redistribute it and/or modify it under    
// the terms of the GNU General Public License as published by the Free     
// Software Foundation; either version 2 or (at your option) any later      
// version.                                                                 
//
// eCos is distributed in the hope that it will be useful, but WITHOUT      
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
// for more details.                                                        
//
// You should have received a copy of the GNU General Public License        
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
//
// As a special exception, if other files instantiate templates or use      
// macros or inline functions from this file, or you compile this file      
// and link it with other works to produce a work based on this file,       
// this file does not by itself cause the resulting work to be covered by   
// the GNU General Public License. However the source code for this file    
// must still be made available in accordance with section (3) of the GNU   
// General Public License v2.                                               
//
// This exception does not invalidate any other reasons why a work based    
// on this file might be covered by the GNU General Public License.         
// -------------------------------------------                              
// ####ECOSGPLCOPYRIGHTEND####                                              
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s):    Simon Kallweit <simon.kallweit@intefo.ch>
// Contributors:
// Date:         2009-02-24
// Purpose:
// Description:
//
//####DESCRIPTIONEND####
//
//==========================================================================

#include <pkgconf/system.h>
#include <pkgconf/devs_adc_cortexm_stm32.h>

#include <cyg/infra/cyg_type.h>
#include <cyg/infra/cyg_ass.h>
#include <cyg/io/adc.h>
#include <cyg/hal/hal_arch.h>
#include <cyg/hal/hal_io.h>
#include <cyg/hal/hal_intr.h>
#include <cyg/hal/drv_api.h>

//-----------------------------------------------------------------------------
// Diagnostic support
// Switch the #if to 1 to generate some diagnostic messages.

#if 0
#include <cyg/infra/diag.h>
#define adc_diag( __fmt, ... ) diag_printf("ADC: %30s[%4d]: " __fmt, __FUNCTION__, __LINE__, ## __VA_ARGS__ );
#else
#define adc_diag( __fmt, ... ) 
#endif


//-----------------------------------------------------------------------------
// STM32 ADC device setup

typedef struct stm32_adc_setup {
    CYG_ADDRESS         adc_base;       // ADC registers base address
    CYG_ADDRESS         dma_base;       // DMA registers base address
    cyg_vector_t        dma_int_vector; // DMA interrupt vector
    cyg_priority_t      dma_int_pri;    // DMA interrupt priority
    cyg_uint8           dma_channel;    // DMA channel to use
    CYG_ADDRESS         tim_base;       // Timer registers base address
    const cyg_uint32    *pins;          // ADC associated GPIO pins
    cyg_uint8           extsel;         // ADC EXTSEL value (timer event)
    cyg_uint32          sample_time;    // ADC sampling time in us
} stm32_adc_setup;

//-----------------------------------------------------------------------------
// STM32 ADC device

typedef struct stm32_adc_info {
    const stm32_adc_setup   *setup;         // ADC setup
    cyg_handle_t            dma_int_handle; // DMA interrupt handle
    cyg_interrupt           dma_int_data;   // DMA interrupt data
    cyg_uint16              *dma_buf;       // DMA buffer
    cyg_adc_channel         *chan[18];      // Channel references by channel no
    cyg_uint32              chan_mask;      // Channel mask
} stm32_adc_info;

//-----------------------------------------------------------------------------
// API function call forward references

static bool stm32_adc_init(struct cyg_devtab_entry *tab);
static Cyg_ErrNo stm32_adc_lookup(struct cyg_devtab_entry **tab,
                                  struct cyg_devtab_entry *sub_tab,
                                  const char *name);

static void stm32_adc_enable(cyg_adc_channel *chan);
static void stm32_adc_disable(cyg_adc_channel *chan);
static void stm32_adc_set_rate(cyg_adc_channel *chan, cyg_uint32 rate);

static cyg_uint32 stm32_dma_isr(cyg_vector_t vector, cyg_addrword_t data);
static void stm32_dma_dsr(cyg_vector_t vector, cyg_ucount32 count,
                          cyg_addrword_t data);

static void stm32_adc_init_clock(void);
static void stm32_adc_init_device(cyg_adc_device *device);
static void stm32_adc_update_sequence(cyg_adc_device *device);

CYG_ADC_FUNCTIONS(stm32_adc_funs,
                  stm32_adc_enable,
                  stm32_adc_disable,
                  stm32_adc_set_rate);

//-----------------------------------------------------------------------------
// STM32 ADC channel instance macro

#define STM32_ADC_CHANNEL(_device_, _chan_)                                 \
CYG_ADC_CHANNEL(                                                            \
    stm32_adc##_device_##_channel##_chan_,                                  \
    _chan_,                                                                 \
    CYGDAT_DEVS_ADC_CORTEXM_STM32_ADC##_device_##_CHANNEL##_chan_##_BUFSIZE,\
    &stm32_adc_device##_device_                                             \
);                                                                          \
DEVTAB_ENTRY(                                                               \
    stm32_adc##_device_##_channel##_chan_##_device,                         \
    CYGDAT_DEVS_ADC_CORTEXM_STM32_ADC##_device_##_CHANNEL##_chan_##_NAME,   \
    0,                                                                      \
    &cyg_io_adc_devio,                                                      \
    stm32_adc_init,                                                         \
    stm32_adc_lookup,                                                       \
    &stm32_adc##_device_##_channel##_chan_                                  \
);

//-----------------------------------------------------------------------------
// STM32 ADC device instances

#ifdef CYGHWR_DEVS_ADC_CORTEXM_STM32_ADC1
#include "adc1.inl"
#endif

#ifdef CYGHWR_DEVS_ADC_CORTEXM_STM32_ADC3
#include "adc3.inl"
#endif

static cyg_bool initialized;
static cyg_uint32 adc_clock;

__externC cyg_uint32 hal_stm32_pclk1;
__externC cyg_uint32 hal_stm32_pclk2;

//-----------------------------------------------------------------------------
// This function is called from the device IO infrastructure to initialize the
// device. It should perform any work needed to start up the device, short of
// actually starting the generation of samples. This function will be called
// for each channel, so if there is initialization that only needs to be done
// once, such as creating and interrupt object, then care should be taken to do
// this. This function should also call cyg_adc_device_init() to initialize the
// generic parts of the driver.

static bool
stm32_adc_init(struct cyg_devtab_entry *tab)
{
    cyg_adc_channel *chan = (cyg_adc_channel *) tab->priv;
    cyg_adc_device *device = chan->device;
    stm32_adc_info *info = device->dev_priv;
    
    adc_diag("Initializing device\n");
    
    // Initialize ADC clock
    if (!initialized) {
        stm32_adc_init_clock();
        initialized = true;
    }
    
    // Keep reference to channel
    info->chan[chan->channel] = chan;

    if (!info->dma_int_handle) {
        // Initialize ADC device
        stm32_adc_init_device(device);
        
        // Set default rate
        stm32_adc_set_rate(chan, chan->device->config.rate);
        
        // Initialize DMA interrupt
        cyg_drv_interrupt_create(info->setup->dma_int_vector,
                                 info->setup->dma_int_pri,
                                (cyg_addrword_t) device,
                                &stm32_dma_isr,
                                &stm32_dma_dsr,
                                &info->dma_int_handle,
                                &info->dma_int_data);
        cyg_drv_interrupt_attach(info->dma_int_handle);
        cyg_drv_interrupt_unmask(info->setup->dma_int_vector);
    }
    
    // Initialize generic parts of ADC device
    cyg_adc_device_init(device);
    
    return true;
}

//-----------------------------------------------------------------------------
// This function is called when a client looks up or opens a channel. It should
// call cyg_adc_channel_init() to initialize the generic part of the channel.
// It should also perform any operations needed to start the channel generating
// samples.

static Cyg_ErrNo
stm32_adc_lookup(struct cyg_devtab_entry **tab,
                 struct cyg_devtab_entry *sub_tab,
                 const char *name)
{
    cyg_adc_channel *chan = (cyg_adc_channel *) (*tab)->priv;
    stm32_adc_info *info = chan->device->dev_priv;
    cyg_uint32 cr;

    adc_diag("Opening device\n");
    
    // Configure the input pin, if available
    if (info->setup->pins[chan->channel] != CYGHWR_HAL_STM32_GPIO_NONE)
        CYGHWR_HAL_STM32_GPIO_SET(info->setup->pins[chan->channel]);
    
    // Activate temperature and VREF if necessary
    if (chan->channel >= 16) {
        HAL_READ_UINT32(info->setup->adc_base + CYGHWR_HAL_STM32_ADC_CR2, cr);
        cr |= CYGHWR_HAL_STM32_ADC_CR2_TSVREFE;
        HAL_WRITE_UINT32(info->setup->adc_base + CYGHWR_HAL_STM32_ADC_CR2, cr);
    }

    // Initialize generic parts of the channel
    cyg_adc_channel_init(chan);

    // The generic ADC manual says: When a channel is first looked up or 
    // opened, then it is automatically enabled and samples start to
    // accumulate - so we start the channel now
    chan->enabled = true;
    stm32_adc_enable(chan);

    return ENOERR;
}

//-----------------------------------------------------------------------------
// This function is called from the generic ADC package to enable the channel
// in response to a CYG_IO_SET_CONFIG_ADC_ENABLE config operation. It should
// take any steps needed to start the channel generating samples

static void
stm32_adc_enable(cyg_adc_channel *chan)
{
    stm32_adc_info *info = chan->device->dev_priv;
    cyg_uint32 cr;
    cyg_bool start;
    
    adc_diag("Enabling channel\n");

    start = !info->chan_mask;

    // Update the scanning sequence
    info->chan_mask |= (1 << chan->channel);
    stm32_adc_update_sequence(chan->device);
    
    // Start scanning when first channel was activated
    if (start) {
        // Enable timer
        adc_diag("Starting scanning\n");
        HAL_READ_UINT32(info->setup->tim_base + CYGHWR_HAL_STM32_TIM_CR1, cr);
        cr |= CYGHWR_HAL_STM32_TIM_CR1_CEN;
        HAL_WRITE_UINT32(info->setup->tim_base + CYGHWR_HAL_STM32_TIM_CR1, cr);
    }
}

//-----------------------------------------------------------------------------
// This function is called from the generic ADC package to enable the channel
// in response to a CYG_IO_SET_CONFIG_ADC_DISABLE config operation. It should
// take any steps needed to stop the channel generating samples.

static void
stm32_adc_disable(cyg_adc_channel *chan)
{
    stm32_adc_info *info = chan->device->dev_priv;
    cyg_uint32 cr;
    
    adc_diag("Disabling channel\n");
    
    // Update scanning sequence
    info->chan_mask &= ~(1 << chan->channel);
    stm32_adc_update_sequence(chan->device);
    
    // Stop scanning when no channel is active
    if (!info->chan_mask) {
        // Disable timer
        adc_diag("Stopping scanning\n");
        HAL_READ_UINT32(info->setup->tim_base + CYGHWR_HAL_STM32_TIM_CR1, cr);
        cr &= ~CYGHWR_HAL_STM32_TIM_CR1_CEN;
        HAL_WRITE_UINT32(info->setup->tim_base + CYGHWR_HAL_STM32_TIM_CR1, cr);
    }
}

//-----------------------------------------------------------------------------
// This function is called from the generic ADC package to enable the channel
// in response to a CYG_IO_SET_CONFIG_ADC_RATE config operation. It should take
// any steps needed to change the sample rate of the channel, or of the entire
// device. We use a timer channel to generate the interrupts for sampling the
// analog channels

static void
stm32_adc_set_rate( cyg_adc_channel *chan, cyg_uint32 rate)
{
    cyg_adc_device *device = chan->device;
    stm32_adc_info *info = device->dev_priv;
    cyg_uint32 clock;
    cyg_uint32 period, prescaler;
    cyg_uint32 cr;
    
    adc_diag("Setting rate to %d\n", rate);

    device->config.rate = rate;
    
    clock = hal_stm32_timer_clock(info->setup->tim_base);
    
    period = clock / rate;
    prescaler = (period / 0x10000) + 1;
    period = period / prescaler;
    
    HAL_WRITE_UINT32(info->setup->tim_base + CYGHWR_HAL_STM32_TIM_PSC,
                     prescaler - 1);
    HAL_WRITE_UINT32(info->setup->tim_base + CYGHWR_HAL_STM32_TIM_ARR,
                     period - 1);
    
    // Reinitialize timer
    cr = CYGHWR_HAL_STM32_TIM_EGR_UG;
    HAL_WRITE_UINT32(info->setup->tim_base + CYGHWR_HAL_STM32_TIM_EGR, cr);
}

//-----------------------------------------------------------------------------
// This function is the ISR attached to the ADC device's DMA channel interrupt
// vector. It is responsible for reading samples from the DMA buffer and
// passing them on to the generic layer.

static cyg_uint32
stm32_dma_isr(cyg_vector_t vector, cyg_addrword_t data)
{
    cyg_adc_device *device = (cyg_adc_device *) data;
    stm32_adc_info *info = (stm32_adc_info *) device->dev_priv;
    cyg_uint32 chan_active = info->chan_mask;
    cyg_uint16 *sample = info->dma_buf;
    cyg_adc_channel **chan = info->chan;
    cyg_uint32 isr;
    cyg_uint32 res = CYG_ISR_HANDLED;
    
    HAL_READ_UINT32(info->setup->dma_base + CYGHWR_HAL_STM32_DMA_ISR, isr);
    if (!(isr & CYGHWR_HAL_STM32_DMA_ISR_MASK(info->setup->dma_channel)))
        return 0;
    
    while (chan_active) {
        if (chan_active & 0x1)
            res |= cyg_adc_receive_sample(*chan, *sample++ & 0xfff);
        chan_active >>= 1;
        chan++;
    }

    HAL_WRITE_UINT32(info->setup->dma_base + CYGHWR_HAL_STM32_DMA_IFCR,
                     CYGHWR_HAL_STM32_DMA_IFCR_MASK(info->setup->dma_channel));
    
    cyg_drv_interrupt_acknowledge(vector);
    
    return res;
}

//-----------------------------------------------------------------------------
// This function is the DSR attached to the ADC device's DMA channel interrupt
// vector. It is called by the kernel if the ISR return value contains the
// CYG_ISR_CALL_DSR bit. It needs to call cyg_adc_wakeup() for each channel
// that has its wakeup field set.

static void
stm32_dma_dsr(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data)
{
    cyg_adc_device *device = (cyg_adc_device *) data;
    stm32_adc_info *info = (stm32_adc_info *) device->dev_priv;
    cyg_uint32 chan_active = info->chan_mask;
    cyg_adc_channel **chan = info->chan;
    
    while (chan_active) {
        if (chan_active & 0x1)
            if ((*chan)->wakeup)
                cyg_adc_wakeup(*chan);
        chan_active >>= 1;
        chan++;
    }
}

//-----------------------------------------------------------------------------
// Initializes the ADC system clock.

static void
stm32_adc_init_clock(void)
{
    CYG_ADDRESS rcc = CYGHWR_HAL_STM32_RCC;
    cyg_uint32 cfgr;
    
    adc_diag("Initializing ADC system clock\n");
    
    HAL_READ_UINT32(rcc + CYGHWR_HAL_STM32_RCC_CFGR, cfgr);
    cfgr &= ~CYGHWR_HAL_STM32_RCC_CFGR_ADCPRE_XXX;

#if CYGNUM_DEVS_ADC_CORTEXM_STM32_CLOCK_DIV == 2
    cfgr |= CYGHWR_HAL_STM32_RCC_CFGR_ADCPRE_2;
    adc_clock = hal_stm32_pclk2 / 2;
#elif CYGNUM_DEVS_ADC_CORTEXM_STM32_CLOCK_DIV == 4
    cfgr |= CYGHWR_HAL_STM32_RCC_CFGR_ADCPRE_4;
    adc_clock = hal_stm32_pclk2 / 4;
#elif CYGNUM_DEVS_ADC_CORTEXM_STM32_CLOCK_DIV == 6
    cfgr |= CYGHWR_HAL_STM32_RCC_CFGR_ADCPRE_6;
    adc_clock = hal_stm32_pclk2 / 6;
#elif CYGNUM_DEVS_ADC_CORTEXM_STM32_CLOCK_DIV == 8
    cfgr |= CYGHWR_HAL_STM32_RCC_CFGR_ADCPRE_8;
    adc_clock = hal_stm32_pclk2 / 8;
#endif

    HAL_WRITE_UINT32(rcc + CYGHWR_HAL_STM32_RCC_CFGR, cfgr);
}

//-----------------------------------------------------------------------------
// Initializes an ADC device.

static void
stm32_adc_init_device(cyg_adc_device *device)
{
    stm32_adc_info *info = device->dev_priv;
    cyg_uint32 cr;
    cyg_uint64 tmp;
    cyg_uint32 cycles;
    cyg_uint32 smpr;
    cyg_uint32 rcc_base = CYGHWR_HAL_STM32_RCC;
    cyg_uint32 reg_data;
    int i;
    
    static const cyg_uint32 cycles_table[] = 
        { 15, 75, 135, 285, 415, 555, 715, 2395 };
    
    // Make sure ADC is powered on
    cr = CYGHWR_HAL_STM32_ADC_CR2_ADON;
    HAL_WRITE_UINT32(info->setup->adc_base + CYGHWR_HAL_STM32_ADC_CR2, cr);
    
    // Reset calibration
    cr |= CYGHWR_HAL_STM32_ADC_CR2_RSTCAL;
    HAL_WRITE_UINT32(info->setup->adc_base + CYGHWR_HAL_STM32_ADC_CR2, cr);
    do {
        HAL_READ_UINT32(info->setup->adc_base + CYGHWR_HAL_STM32_ADC_CR2, cr);
    } while (cr & CYGHWR_HAL_STM32_ADC_CR2_RSTCAL);
    
    // Do calibration
    cr |= CYGHWR_HAL_STM32_ADC_CR2_CAL;
    HAL_WRITE_UINT32(info->setup->adc_base + CYGHWR_HAL_STM32_ADC_CR2, cr);
    do {
        HAL_READ_UINT32(info->setup->adc_base + CYGHWR_HAL_STM32_ADC_CR2, cr);
    } while (cr & CYGHWR_HAL_STM32_ADC_CR2_CAL);
    
    // Power off ADC 
    cr &= ~CYGHWR_HAL_STM32_ADC_CR2_ADON;
    HAL_WRITE_UINT32(info->setup->adc_base + CYGHWR_HAL_STM32_ADC_CR2, cr);
    
    // Enable external triggering and DMA
    cr |= CYGHWR_HAL_STM32_ADC_CR2_DMA |
          CYGHWR_HAL_STM32_ADC_CR2_EXTTRIG |
          CYGHWR_HAL_STM32_ADC_CR2_EXTSEL(info->setup->extsel);
    HAL_WRITE_UINT32(info->setup->adc_base + CYGHWR_HAL_STM32_ADC_CR2, cr);
    
    // Enable scanning
    cr = CYGHWR_HAL_STM32_ADC_CR1_SCAN;
    HAL_WRITE_UINT32(info->setup->adc_base + CYGHWR_HAL_STM32_ADC_CR1, cr);


    // Set timer direction = down, clock divider = 1
    cr = CYGHWR_HAL_STM32_TIM_CR1_DIR | CYGHWR_HAL_STM32_TIM_CR1_CKD_1;
    HAL_WRITE_UINT32(info->setup->tim_base + CYGHWR_HAL_STM32_TIM_CR1, cr);

    // Enable generation of TRGO event
    cr = CYGHWR_HAL_STM32_TIM_CR2_MMS_UPDATE;
    HAL_WRITE_UINT32(info->setup->tim_base + CYGHWR_HAL_STM32_TIM_CR2, cr);
    

    // Setup DMA channel
    // Ensure that the DMA clocks are enabled.
    HAL_READ_UINT32 (rcc_base + CYGHWR_HAL_STM32_RCC_AHBENR, reg_data);
    if (info->setup->dma_base == CYGHWR_HAL_STM32_DMA1)
      reg_data |= CYGHWR_HAL_STM32_RCC_AHBENR_DMA1;
    else
      reg_data |= CYGHWR_HAL_STM32_RCC_AHBENR_DMA2;
    HAL_WRITE_UINT32 (rcc_base + CYGHWR_HAL_STM32_RCC_AHBENR, reg_data);

    HAL_WRITE_UINT32(info->setup->dma_base + 
                     CYGHWR_HAL_STM32_DMA_CPAR(info->setup->dma_channel),
                     info->setup->adc_base + CYGHWR_HAL_STM32_ADC_DR);
    HAL_WRITE_UINT32(info->setup->dma_base +
                     CYGHWR_HAL_STM32_DMA_CMAR(info->setup->dma_channel),
                     (CYG_ADDRESS) info->dma_buf);
    HAL_WRITE_UINT32(info->setup->dma_base +
                     CYGHWR_HAL_STM32_DMA_CNDTR(info->setup->dma_channel),
                     0);
    HAL_WRITE_UINT32(info->setup->dma_base +
                     CYGHWR_HAL_STM32_DMA_CCR(info->setup->dma_channel),
                     CYGHWR_HAL_STM32_DMA_CCR_TCIE |
                     CYGHWR_HAL_STM32_DMA_CCR_TEIE |
                     CYGHWR_HAL_STM32_DMA_CCR_CIRC |
                     CYGHWR_HAL_STM32_DMA_CCR_MINC |
                     CYGHWR_HAL_STM32_DMA_CCR_PSIZE16 |
                     CYGHWR_HAL_STM32_DMA_CCR_MSIZE16);

    // Compute duration of a single cycle in pico-seconds
    tmp = 1000000000000LL / adc_clock;
    // Compute tenths of cycles for target sample time
    tmp = (info->setup->sample_time * 1000000 * 10) / tmp;
    cycles = tmp;
    
    adc_diag("Setting ADC sample time to %d us (%d.%d cycles)\n",
             info->setup->sample_time, cycles / 10, cycles % 10);
    
    // Find best matching SMPR value
    if (cycles > cycles_table[7]) {
        adc_diag("ADC sample time too long\n");
        smpr = 7;
    } else {
        for (smpr = 7; smpr > 0; smpr--)
            if (cycles > cycles_table[smpr])
                break;
    }
    
    // Expand SMPR value to all channels
    for (i = 0; i < 10; i++)
        smpr |= smpr << 3;
    
    // Set sampling time
    HAL_WRITE_UINT32(info->setup->adc_base + CYGHWR_HAL_STM32_ADC_SMPR1, smpr);
    HAL_WRITE_UINT32(info->setup->adc_base + CYGHWR_HAL_STM32_ADC_SMPR2, smpr);
}

//-----------------------------------------------------------------------------
// Updates the sequence for the regular group. ADC and DMA are disabled during
// the update. The sequence registers and DMA count registers are rewritten.
// Note: As the regular group consists of 16 channels max, we cannot activate
// the theoretical maximum of 18 channels (analog ins + temperature/VREF).

static void
stm32_adc_update_sequence(cyg_adc_device *device)
{
    stm32_adc_info *info = device->dev_priv;
    int i;
    int count = 0;
    cyg_uint32 cr;
    cyg_uint32 sqr1 = 0;
    cyg_uint32 sqr2 = 0;
    cyg_uint32 sqr3 = 0;
    
    adc_diag("Updating regular group\n");
    
    // Disable ADC
    HAL_READ_UINT32(info->setup->adc_base + CYGHWR_HAL_STM32_ADC_CR2, cr);
    cr &= ~CYGHWR_HAL_STM32_ADC_CR2_ADON;
    HAL_WRITE_UINT32(info->setup->adc_base + CYGHWR_HAL_STM32_ADC_CR2, cr);

    // Disable DMA
    HAL_READ_UINT32(info->setup->dma_base +
                    CYGHWR_HAL_STM32_DMA_CCR(info->setup->dma_channel), cr);
    cr &= ~CYGHWR_HAL_STM32_DMA_CCR_EN;
    HAL_WRITE_UINT32(info->setup->dma_base +
                     CYGHWR_HAL_STM32_DMA_CCR(info->setup->dma_channel), cr);

    // Initialize scanning sequence (regular group)
    for (i = 0; i < 18; i++) {
        if (!(info->chan_mask & (1 << i)))
            continue;
        
        if (count < 6) {
            sqr3 |= CYGHWR_HAL_STM32_ADC_SQRx_SQ(count, i);
        } else if (count < 12) {
            sqr2 |= CYGHWR_HAL_STM32_ADC_SQRx_SQ(count - 6, i);
        } else if (count < 16) {
            sqr1 |= CYGHWR_HAL_STM32_ADC_SQRx_SQ(count - 12, i);
        } else {
            CYG_FAIL("Too many active channels\n");
        }
        count++;
    }
    
    sqr1 |= CYGHWR_HAL_STM32_ADC_SQR1_L(count - 1);
    
    adc_diag("sqr1: %p sqr2: %p sqr3: %p\n",
             (void *) sqr1, (void *) sqr2, (void *) sqr3);
    
    // Write sequence registers
    HAL_WRITE_UINT32(info->setup->adc_base + CYGHWR_HAL_STM32_ADC_SQR1, sqr1);
    HAL_WRITE_UINT32(info->setup->adc_base + CYGHWR_HAL_STM32_ADC_SQR2, sqr2);
    HAL_WRITE_UINT32(info->setup->adc_base + CYGHWR_HAL_STM32_ADC_SQR3, sqr3);
    
    // Update DMA
    HAL_WRITE_UINT32(info->setup->dma_base +
                     CYGHWR_HAL_STM32_DMA_CNDTR(info->setup->dma_channel),
                     count);
    
    // Enable DMA
    HAL_READ_UINT32(info->setup->dma_base +
                    CYGHWR_HAL_STM32_DMA_CCR(info->setup->dma_channel), cr);
    cr |= CYGHWR_HAL_STM32_DMA_CCR_EN;
    HAL_WRITE_UINT32(info->setup->dma_base +
                     CYGHWR_HAL_STM32_DMA_CCR(info->setup->dma_channel), cr);
    
    // Enable ADC
    HAL_READ_UINT32(info->setup->adc_base + CYGHWR_HAL_STM32_ADC_CR2, cr);
    cr |= CYGHWR_HAL_STM32_ADC_CR2_ADON;
    HAL_WRITE_UINT32(info->setup->adc_base + CYGHWR_HAL_STM32_ADC_CR2, cr);
}

//-----------------------------------------------------------------------------
// End of adc_stm32.c

[-- Attachment #3: Type: text/plain, Size: 148 bytes --]

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [ECOS] Re: stm3210e eval board adc question
  2011-05-02 21:45                       ` [ECOS] " Christophe Coutand
@ 2011-05-03  7:58                         ` jayant biswas
  0 siblings, 0 replies; 13+ messages in thread
From: jayant biswas @ 2011-05-03  7:58 UTC (permalink / raw)
  To: Christophe Coutand; +Cc: ecos-discuss

Thanks Christophe for the patch... you are a bit of a legend!

It seems to work now, both adc1 and adc2 tests are running. I am able
to read the values from the potentiometer on the board. And I get some
random values for the BNC inputs (which are currently not connected to
anything). I still have to fix my own program so I can produce similar
results, but I think I can follow the code of the two tests to make my
code work.

I will post again if I have more questions

Thanks again!

Jayant

On Mon, May 2, 2011 at 23:42, Christophe Coutand <ccoutand@stmi.com> wrote:
> Hi Jayant,
>
> While reviewing the code I found few issues in the ADC driver. Please try with the attached code and let me know if it works for you.
>
> Christophe
>
>
> -----Original Message-----
> From: jayant biswas [mailto:biswasj@gmail.com]
> Sent: 2. mai 2011 12:16
> To: Christophe Coutand
> Cc: ecos-discuss@ecos.sourceware.org
> Subject: Re: stm3210e eval board adc question
>
> Hello again!
>
> I have tried stepping through the code for adc1.c. Stepping from line
> 124 in adc1.c, I notice that when trying to read from the channels it
> is always waiting for data to be available on /dev/adc014. This means
> that in packages/io/adc/current/src/adc.c it never reaches line 131
> (// A sample is available, transfer it to the buffer).
>
> Do you have an idea why the data is never available from the
> potentiometer on the  STM3210E-eval board? Let me know if I can
> provide more information about my tests.
>
> Thank you,
> Jayant
>
> On Tue, Apr 19, 2011 at 14:42, jayant biswas <biswasj@gmail.com> wrote:
>> Hi Christophe.
>>
>> Thanks for the info about how to find out which channel corresponds to
>> which input. This will be useful for me.
>>
>> As for the terminal I am using cutecom on ubuntu. 38400,8,1, parity
>> none, no handshake, open for reading and writing.
>>
>> I tried running the adc1 test and that only runs this far:
>> \0x00INFO:<ADC test>
>> Testing ADC channel '/dev/adc00'
>>
>> when I force stop the program it says the following
>> (gdb) continue
>> Continuing.
>> ^C
>> Program received signal SIGINT, Interrupt.
>> 0x08003832 in Cyg_Mutex::lock (this=0x6800001c)
>>    at /home/jayant/ecos/adc/ecos_install/include/cyg/kernel/sched.inl:99
>> 99          if( __lock == 0 ) unlock_inner(0);
>> Current language:  auto; currently c++
>>
>> Stepping through adc2 in gdb with a breakpoint on line 181 as you
>> mentioned i get this
>> (gdb) break adc2.c:181
>> Breakpoint 1 at 0x800027e: file adc2.c, line 181.
>> (gdb) continue
>> Continuing.
>> Note: automatically using hardware breakpoints for read-only addresses.
>>
>> Breakpoint 1, adc_thread (data=<value optimized out>) at adc2.c:181
>> 181                     cyg_uint32 len = sizeof(sample);
>> (gdb) info frame
>> Stack level 0, frame at 0x68004668:
>>  pc = 0x800027e in adc_thread (adc2.c:181); saved pc 0x8002b4e
>>  called by frame at 0x68004670
>>  source language c.
>>  Arglist at 0x68004628, args: data=<value optimized out>
>>  Locals at 0x68004628, Previous frame's sp is 0x68004668
>>  Saved registers:
>>  r4 at 0x68004644, r5 at 0x68004648, r6 at 0x6800464c, r7 at
>> 0x68004650, r8 at 0x68004654,
>>  r9 at 0x68004658, r10 at 0x6800465c, r11 at 0x68004660, lr at 0x68004664
>> (gdb) print len
>> $1 = <value optimized out>
>> (gdb) print sample
>> $2 = 26624
>> (gdb) s
>> cortex_m3 interrupt mask on
>> 176             for (i = 0; i < num; i++) {
>> cortex_m3 interrupt mask off
>> (gdb) print len
>> $3 = 2
>> (gdb) print sample
>> $4 = 26624
>> (gdb) s
>> cortex_m3 interrupt mask on
>> 177                 chan = &test_channels[i];
>> cortex_m3 interrupt mask off
>> (gdb) s
>> cortex_m3 interrupt mask on
>> 182                     res = cyg_io_read(chan->handle, &sample, &len);
>> cortex_m3 interrupt mask off
>> (gdb) s
>> cortex_m3 interrupt mask on
>> 181                     cyg_uint32 len = sizeof(sample);
>> cortex_m3 interrupt mask off
>> (gdb) print len
>> $5 = 0
>> (gdb) print sample
>> $6 = 26624
>> (gdb)
>>
>> Not sure what I should be looking for here. Can you please suggest how
>> I may proceed to find the problem?
>>
>> Thanks again
>> Jayant
>>
>> On Tue, Apr 19, 2011 at 09:25, Christophe Coutand <ccoutand@stmi.com> wrote:
>>> Hi Jayant,
>>>
>>> From this documentation: http://www.st.com/stonline/books/pdf/docs/14220.pdf, the potentiometer is connected to PC4.
>>>
>>> Looking at the IOs definition in: packages\hal\cortexm\stm32\var\current\include\var_io.h, you can sample PC4 using ADC1/14.
>>>
>>> #define CYGHWR_HAL_STM32_ADC12_IN14             CYGHWR_HAL_STM32_GPIO( C, 4,  IN, ANALOG )
>>> #define CYGHWR_HAL_STM32_ADC1_IN14              CYGHWR_HAL_STM32_ADC12_IN14
>>>
>>> The adc2 test does not log any sampling results. It is used to check that the sampling rate is correct over a period of 10 seconds. The output of your test does not look good. The \0x09 is a tabulation that your terminal is not interpreting (which terminal do you use)? But the result is 0 for all channels, meaning that no samples are read.
>>>
>>> ----------------------------------------
>>> Samples expected after 10210 milliseconds: 10210
>>> Samples read (per channel):
>>> /dev/adc00          \0x09= 0
>>>
>>> Do you have a way to step into the code? I don't clearly see how the test can complete without reading samples. Line 181 is a loop waiting for samples:
>>>
>>>  // Read & count samples
>>>  do {
>>>    cyg_uint32 len = sizeof(sample);
>>>    res = cyg_io_read(chan->handle, &sample, &len);
>>>    if (res == ENOERR)
>>>       chan->count++;
>>>  } while (res == ENOERR);
>>>
>>> You can also try the adc1 test which shall read and display the sampled data. I don't own a STM3210e boards therefore can't give it a try.
>>>
>>> Regards,
>>> Christophe
>>>
>>> -----Original Message-----
>>> From: jayant biswas [mailto:biswasj@gmail.com]
>>> Sent: 18. april 2011 16:49
>>> To: Christophe Coutand
>>> Cc: ecos-discuss@ecos.sourceware.org
>>> Subject: Re: stm3210e eval board adc question
>>>
>>> Dear Christophe!
>>>
>>> Thanks for your support. I have a feeling I am getting closer, but not
>>> quite there yet. So I appreciate your time in helping me out. Now I
>>> have been able to add the adc io, as in the screenshot you sent using
>>> only the cvs code. So I am not mixing anymore ecos-3.0 and the cvs.
>>> But when I run the tests on my stm3210e eval board I do not get the
>>> desired output. The output of adc2 test is shown below. It shows that
>>> no samples have been read. I am also not sure what to make of the
>>> \0x09 stuff before the '=' signs.
>>>
>>> My goal is to be able to read the value from the potentiometer on the
>>> board (http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DATA_BRIEF/CD00278458.pdf
>>> as shown on page 2/3) and eventually also from the 3 bnc connectors.
>>> First of all, how can I know which input (BNC or Potentiometer) is
>>> connected to which device on which channel? And secondly why when I
>>> try to display values from all channels on both devices I receive
>>> nothing. One of these channels must be connected to the potentiometer
>>> no? The BNC connectors are currently left open.
>>>
>>> Hope I can make this work.
>>>
>>> Regards,
>>> Jayant
>>>
>>> \0x00INFO:<ADC performance test>
>>> INFO:<Opening available ADC channel
>>> s>
>>> Opened 32 ADC channels
>>> INFO:<Preparing ADC channels for test>
>>> INFO:<Starting measurement>
>>>
>>>
>>> /dev/adc00          \0x09= 0
>>> /dev/adc01          \0x09= 0
>>> /dev/adc02
>>>          \0x09= 0
>>> /dev/adc03          \0x09= 0
>>> .
>>> .
>>> .
>>> /dev/adc113         \0x09= 0
>>> /dev/adc114         \0x09= 0
>>> /dev/adc115         \0x09= 0
>>> INFO:<Finished measurement>
>>>
>>>
>>> ----------------------------------------
>>> Samples expected after 10210 milliseconds: 10210
>>> Samples read (per channel):
>>> /dev/adc00          \0x09= 0
>>> .
>>> .
>>> .
>>>
>>> On Mon, Apr 18, 2011 at 11:47, Christophe Coutand <ccoutand@stmi.com> wrote:
>>>> Hi Jayant,
>>>>
>>>> You are using ecos-3.0 with the additional STM32 ADC package from CVS? It is usually not recommended to mix source code as it make it more difficult to get support from the mailing list.
>>>>
>>>> It is not enough to copy the directory packages\devs\adc\cortexm\stm32 in your repository, you must also include the package entry in the database (i.e. ecos.db):
>>>>
>>>> package CYGPKG_DEVS_ADC_CORTEXM_STM32 {
>>>>    alias         { "STM32 ADC driver" adc_stm32 }
>>>>    hardware
>>>>    directory     devs/adc/cortexm/stm32
>>>>    script        adc_stm32.cdl
>>>>    description "
>>>>    This package provides a driver for the ADC interfaces found on the
>>>>    ST STM32 microcontroller family."
>>>> }
>>>>
>>>> To build the STM32 HAL with ADC support from CVS repository, I do:
>>>> $ ecosconfig.exe new stm3210e default
>>>> $ ecosconfig.exe add io_adc
>>>>
>>>> You can configure the ADC from the GUI:
>>>> $ configtool.exe ecos.ecc
>>>>
>>>> Example:
>>>>
>>>> http://dl.dropbox.com/u/21589565/misc/stm32_adc.JPG
>>>>
>>>> Regards,
>>>> Christophe
>>>>
>>>> -----Original Message-----
>>>> From: jayant biswas [mailto:biswasj@gmail.com]
>>>> Sent: 18. april 2011 10:47
>>>> To: John Dallaway; Christophe Coutand
>>>> Cc: ecos-discuss@ecos.sourceware.org
>>>> Subject: Re: stm3210e eval board adc question
>>>>
>>>> Thank you Christophe and John for your replies.
>>>>
>>>> I did checkout the cvs repository and was able to get the right folder
>>>> i.e. packages\devs\adc\cortexm\stm32
>>>>
>>>> However, this hasn't solved my problem. I am still getting the same
>>>> output as before when calling cyg_io_lookup and cyg_io_read.
>>>>
>>>> To integrate the new packages from the cvs. I copied  the entire
>>>> repository over my ecos-3.0 folder. Then I regenerated the ecos.ecc
>>>> file for stm3210e. I noticed here that the
>>>> CYGPKG_DEVS_ADC_CORTEXM_STM32 checkboxes were grayed out. I then
>>>> recompiled my application with the newly generated libraries.
>>>>
>>>> Please let me know if I am missing some steps. I am sure I am. Is
>>>> there a guide that I can follow that shows how to integrate the ecos
>>>> cvs packages?
>>>>
>>>> Best regards,
>>>> Jayant
>>>>
>>>> On Wed, Apr 13, 2011 at 20:11, John Dallaway <john@dallaway.org.uk> wrote:
>>>>> Hi Jayant
>>>>>
>>>>> jayant biswas wrote:
>>>>>
>>>>>> I installed ecos as indicated here
>>>>>> http://ecos.sourceware.org/getstart.html .
>>>>>
>>>>> ... so you have the eCos 3.0 release repository.
>>>>>
>>>>> The STM32 ADC driver is not present in eCos 3.0. You will have to
>>>>> checkout the eCos CVS repository in order to gain access to
>>>>> CYGPKG_DEVS_ADC_CORTEXM_STM32. Ref:
>>>>>
>>>>>  http://ecos.sourceware.org/anoncvs.html
>>>>>
>>>>> I hope this helps...
>>>>>
>>>>> John Dallaway
>>>>> eCos maintainer
>>>>> http://www.dallaway.org.uk/john
>>>>>
>>>>
>>>
>>
>

--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2011-05-03  7:58 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-12 15:27 [ECOS] stm3210e eval board adc question jayant biswas
2011-04-12 16:22 ` Christophe Coutand
2011-04-13  8:48   ` jayant biswas
     [not found]     ` <D6050C555CC56940A7AF3265228302761394EC@mail2.STMIRV01.COM>
2011-04-13 12:38       ` jayant biswas
2011-04-13 18:11         ` [ECOS] " John Dallaway
2011-04-18  8:48           ` jayant biswas
2011-04-18  9:49             ` [ECOS] " Christophe Coutand
2011-04-18 14:49               ` [ECOS] " jayant biswas
2011-04-19  7:27                 ` [ECOS] " Christophe Coutand
2011-04-19 12:43                   ` [ECOS] " jayant biswas
2011-05-02 10:16                     ` jayant biswas
2011-05-02 21:45                       ` [ECOS] " Christophe Coutand
2011-05-03  7:58                         ` [ECOS] " jayant biswas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).