Discussion:
Re: Olimex-STM32-E407 problem running I2C (Maybe a problem with semaphore)
(too old to reply)
spudarnia@yahoo.com [nuttx]
2018-02-01 13:05:22 UTC
Permalink
I can't think of anything that could cause this except for a memory corruption problem.
Alan Carvalho de Assis acassis@gmail.com [nuttx]
2018-02-01 12:06:25 UTC
Permalink
Hi Juan,

Your modification steps are correct. I think the issue is because the
driver is called too early, before the system initialization.

https://acassis.wordpress.com/2015/07/01/nuttx-board-initialization-where-can-i-put-my-code-to-be-execute/

Did you enable CONFIG_BOARD_INITIALIZE in the menuconfig ? Press "/"
and type BOARD_INITIALIZE to find out where is it defined.

BR,

Alan
Hi!
I'm triying to develop a NuttX App which use a barometer (BMP180), but I'm
having some issues to make it run so I need your expert help.
I'm using Olimex-STM32-E407 board and the sensor is BMP180 which connects
through I2c and the driver are already developed, so the path that I follow
I use the configuration olimex-stm32-e407/nsh and in the menuconfig I
System Type -> STM32 Peripheral Support-> I2C1
Device Drivers->I2C Driver Support(Checked)->Nothing inside checked
Device Drivers->Sensor Device Support(Checked)->Bosch BMP180 Barometer
sensor support(Checked)
Then I copied smt32_lm75.c from nuttx/configs/stm32f03-minimum/src to
nuttx/configs/olimex-stm32-e407/src and I changed the name for
stm32_bmp180.c
Then I modify the file adapting to the characteristics of the bmp180 driver
and board. I attached the file with the modifications.
Now I go to makefile inside olimex-stm32-e407/src and I add this line just
"CSRCS += stm32_bmp180.c"
int stm32_bmp180initialize(FAR const char *devpath);
The last modification that I've done is in the file stm32_boot.c in which I
ret = stm32_bmp180initialize("/dev/temp");
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: stm32_b180initialize() failed: %d\n", ret);
}
Inside the function void stm32_boardinitialize(void)
Finally the compilation and uploading to the board goes great(Also I checked
that the stm32_bmp180initialize function is in the system.map ), but when I
up_dumpstate: sp: 20000d58
up_dumpstate: stactk base: 080001c1
up_dumpstate: stack size: 08000189
up_dumpstate: ERROR: Stack pointer is not within the allocated stack.
I would appreciate your help, because I've block with this for several
days.
Thank you in advance.
Juan.
spudarnia@yahoo.com [nuttx]
2018-02-01 13:30:01 UTC
Permalink
Here is another reference: http://www.nuttx.org/doku.php?id=wiki:nxinternal:initsequence&#more_about_board_initialize

There is an assertion that often occurs in sem_wait() if you try to initialize using board_initialize(). That assertion occurs because when sem_wait() attempts to wait, it discovers it is on the IDLE thread which cannot wait.

But the assertion at line 131 is different. It implies that data in the TCB has been corrupted, perhaps due to a stack overflow or a bad pointer.
jfloresmu92@yahoo.com [nuttx]
2018-02-01 15:27:35 UTC
Permalink
Hi!!

Thank you for the fast response.
I finally figure out what produces this problem, and the reason is because I added to the driver a printf to now if the driver have any issue during the registration. I deleted it, and the console start-up properly.
But I still have a problem, and it's despite I don't get any error during compilation or run time, when I type
"ls /dev" the device it doesn't appear.

I initialize with this function at the stm32_boot.c file:

void stm32_boardinitialize(void)
{
#if defined(CONFIG_STM32_OTGFS) || defined(CONFIG_STM32_OTGHS)
/* Initialize USB if the 1) OTG FS controller is in the configuration and 2)
* disabled, and 3) the weak function stm32_usbinitialize() has been brought
* into the build. Presumeably either CONFIG_USBDEV is also selected.
*/

if (stm32_usbinitialize)
{
stm32_usbinitialize();
}
#endif

#ifdef CONFIG_ARCH_LEDS
/* Configure on-board LEDs if LED support has been selected. */

board_autoled_initialize();
#endif

#ifdef CONFIG_ARCH_BUTTONS
/* Configure on-board BUTTONs if BUTTON support has been selected. */

board_button_initialize();
#endif
stm32_bmp180initialize("dev/temp0/");
}

Is this correct?
Also when I type I2C bus(using I2C tool) it show that there aren't any bus available .
Alan Carvalho de Assis acassis@gmail.com [nuttx]
2018-02-01 16:11:22 UTC
Permalink
Hi Juan,

Please open the file System.map and verify if the bmp180 driver
functions are there.

If it is not there, it means that some requirement is missing.

Also you can enable the Sensor Debug Features to get more info to know
what is failing, case the driver functions are included in the final
binary.

BR,

Alan
Post by ***@yahoo.com [nuttx]
Hi!!
Thank you for the fast response.
I finally figure out what produces this problem, and the reason is because I
added to the driver a printf to now if the driver have any issue during the
registration. I deleted it, and the console start-up properly.
But I still have a problem, and it's despite I don't get any error during
compilation or run time, when I type
"ls /dev" the device it doesn't appear.
void stm32_boardinitialize(void)
{
#if defined(CONFIG_STM32_OTGFS) || defined(CONFIG_STM32_OTGHS)
/* Initialize USB if the 1) OTG FS controller is in the configuration and 2)
* disabled, and 3) the weak function stm32_usbinitialize() has been brought
* into the build. Presumeably either CONFIG_USBDEV is also selected.
*/
if (stm32_usbinitialize)
{
stm32_usbinitialize();
}
#endif
#ifdef CONFIG_ARCH_LEDS
/* Configure on-board LEDs if LED support has been selected. */
board_autoled_initialize();
#endif
#ifdef CONFIG_ARCH_BUTTONS
/* Configure on-board BUTTONs if BUTTON support has been selected. */
board_button_initialize();
#endif
stm32_bmp180initialize("dev/temp0/");
}
Is this correct?
Also when I type I2C bus(using I2C tool) it show that there aren't any bus available .
spudarnia@yahoo.com [nuttx]
2018-02-01 16:32:57 UTC
Permalink
Alan is correct. The most common cause for missing drivers is that they were never initialized. There must be logic in your board's bring-up logic to register all drivers needed by the build.


And if you do not register the driver, it will not be included in the build and, hence, will not appear in the System.map.
jfloresmu92@yahoo.com [nuttx]
2018-02-02 09:22:52 UTC
Permalink
Hi,

I've checked the System.map and all the functions of bmp180 are include, also the I2C functions.
I was debugging with GDB triying to follow who the system initializes and I think that I found the problem but I don't know how to solve it.
In the function bmp180_register in the file bmp180.c(nuttx/drivers/sensors) I found that it returns an error at his point:

ret = bmp180_checkid(priv);

if (ret < 0)
{
snerr("ERROR: Failed to register driver: %d\n", ret);
kmm_free(priv);
return ret;
}

The initialization of the bus doesn't return any error, but when it arrive at this point ret is <0 so the driver not initializes.
But also there is one weird thing, and it's despite of I don't have any error during the initialization of the I2C Bus 1 (with the function stm32_i2cbus_initialize(1)), when I type i2c bus in the nuttx console it doesn't appear any bus available.

Thank you so much for the help that are providing me and for the fast response.

Juan


---In ***@yahoogroups.com, <***@...> wrote :

Alan is correct. The most common cause for missing drivers is that they were never initialized. There must be logic in your board's bring-up logic to register all drivers needed by the build.


And if you do not register the driver, it will not be included in the build and, hence, will not appear in the System.map.
Alan Carvalho de Assis acassis@gmail.com [nuttx]
2018-02-02 11:27:24 UTC
Permalink
Hi Juan,

Did you enable the sensor debug outputs (warn, info and error) ?

This function should print the read device id:

sninfo("devid: 0x%02x\n", devid);

If DEVID is different from 0x55 then your I2C is failing to
communicate with the sensor.

BR,

Alan
Post by ***@yahoo.com [nuttx]
Hi,
I've checked the System.map and all the functions of bmp180 are include,
also the I2C functions.
I was debugging with GDB triying to follow who the system initializes and I
think that I found the problem but I don't know how to solve it.
In the function bmp180_register in the file bmp180.c(nuttx/drivers/sensors)
ret = bmp180_checkid(priv);
if (ret < 0)
{
snerr("ERROR: Failed to register driver: %d\n", ret);
kmm_free(priv);
return ret;
}
The initialization of the bus doesn't return any error, but when it arrive
at this point ret is <0 so the driver not initializes.
But also there is one weird thing, and it's despite of I don't have any
error during the initialization of the I2C Bus 1 (with the function
stm32_i2cbus_initialize(1)), when I type i2c bus in the nuttx console it
doesn't appear any bus available.
Thank you so much for the help that are providing me and for the fast response.
Juan
Alan is correct. The most common cause for missing drivers is that they
were never initialized. There must be logic in your board's bring-up logic
to register all drivers needed by the build.
And if you do not register the driver, it will not be included in the build
and, hence, will not appear in the System.map.
Alan Carvalho de Assis acassis@gmail.com [nuttx]
2018-02-04 17:57:59 UTC
Permalink
Hi Juan,

I created a video tutorial demonstrating how to use the BMP180 on
BluePill (stm32f103-minimum) board:



Did you get it working?

BR,

Alan
Post by ***@yahoo.com [nuttx]
Hi,
I've checked the System.map and all the functions of bmp180 are include,
also the I2C functions.
I was debugging with GDB triying to follow who the system initializes and I
think that I found the problem but I don't know how to solve it.
In the function bmp180_register in the file bmp180.c(nuttx/drivers/sensors)
ret = bmp180_checkid(priv);
if (ret < 0)
{
snerr("ERROR: Failed to register driver: %d\n", ret);
kmm_free(priv);
return ret;
}
The initialization of the bus doesn't return any error, but when it arrive
at this point ret is <0 so the driver not initializes.
But also there is one weird thing, and it's despite of I don't have any
error during the initialization of the I2C Bus 1 (with the function
stm32_i2cbus_initialize(1)), when I type i2c bus in the nuttx console it
doesn't appear any bus available.
Thank you so much for the help that are providing me and for the fast response.
Juan
Alan is correct. The most common cause for missing drivers is that they
were never initialized. There must be logic in your board's bring-up logic
to register all drivers needed by the build.
And if you do not register the driver, it will not be included in the build
and, hence, will not appear in the System.map.
jfloresmu92@yahoo.com [nuttx]
2018-02-05 17:34:08 UTC
Permalink
Hi Alan,

First I would like to say, that you're videos are awesome and very clear to understand, I've been watching it for the last weeks.

At the moment I'm not be able to make it run (This sensor or any I2C sensor). For this case, I used the same configuration as in the video but I was following with GDB how It's working the code and when it try to execute the function "bmp180_checkid()" it returns an error.

It's look like the I2C it's not fully implemented on this board(Olimex-STM32-E407) but following the initialization of the system with GDB, I saw that it call to the I2Cregister functions and the functions are in the system.map after the compilation.

Do you know any way to check if the I2C is working? I've already tried with I2CTool, but when I type I2C Bus, appear all the buses with No.

Thank you so much for the help!
Alan Carvalho de Assis acassis@gmail.com [nuttx]
2018-02-05 17:53:25 UTC
Permalink
Hi Juan,

Yes, NuttX has very many debug options, you can enable the I2C debug
and see how it is initializing the hardware.

Did you see in the list that other people are discovering issues in
the I2C driver on STM32F4xx ? Maybe it could has some relation with
the issue you are facing.

Other way you can test it is using an external logic analyzer. I use
this low cost (less than U$10) model from aliexpress:

https://acassis.wordpress.com/2015/07/19/sigrok-and-a-cheap-saleae-clone-can-save-your-life-i-meant-your-time/

This way you could to confirm if the MCU hardware is generating the I2C signal.

BR,

Alan
Post by ***@yahoo.com [nuttx]
Hi Alan,
First I would like to say, that you're videos are awesome and very clear to
understand, I've been watching it for the last weeks.
At the moment I'm not be able to make it run (This sensor or any I2C
sensor). For this case, I used the same configuration as in the video but I
was following with GDB how It's working the code and when it try to execute
the function "bmp180_checkid()" it returns an error.
It's look like the I2C it's not fully implemented on this
board(Olimex-STM32-E407) but following the initialization of the system with
GDB, I saw that it call to the I2Cregister functions and the functions are
in the system.map after the compilation.
Do you know any way to check if the I2C is working? I've already tried with
I2CTool, but when I type I2C Bus, appear all the buses with No.
Thank you so much for the help!
jfloresmu92@yahoo.com [nuttx]
2018-02-07 00:25:10 UTC
Permalink
Hi Alan,

I've connected my logic analyzer to the I2C pin, but I don't receive any signal.
Now with I2C debugger I received this messages through the terminal:



With invalid address I don't if it's the address of the I2C inside the board, or the addres of the device. The last I double checked that is correct.
Alan Carvalho de Assis acassis@gmail.com [nuttx]
2018-02-07 10:59:35 UTC
Permalink
Hi Juan,

Did you post the debugger message here? I can't see it in your email.

Please post the message again, use plain text instead HTML (case you
are using it).

BR,

Alan
Post by ***@yahoo.com [nuttx]
Hi Alan,
I've connected my logic analyzer to the I2C pin, but I don't receive any signal.
With invalid address I don't if it's the address of the I2C inside the
board, or the addres of the device. The last I double checked that is
correct.
jfloresmu92@yahoo.com [nuttx]
2018-02-08 12:46:03 UTC
Permalink
Hi Alan,

I posted a image, I thought it was attached.

Finally I was be able to solve it!!
There was a few problems it will try to explain here if I can help to someone with the same problem, but maybe my main problem was my lack of experience.

-The configuration in the menuconfig was correct. The sensor and I2C debugging options are very good allies.
-When you want to know the assigned pin to anything I would recommend you to see the pin map file in the configuration, because I was following the pin assent of the board datasheet and it was different of the pin assignment in the configuration. (For the olimex-stm32-e407 I2C1 is on PB6 and PB7 instead PB8 and PB9)

At the moment, I already the problem of I'm be able to register the device to use with open/close/read/write. I know that It's obligatory use this way to use correctly NuttX but returns me an error at the time of registration of the device.
But at the moment I only want to know if the I2C works, so to have the data that I wanted I do the next things in the hello example and in the BMP180 driver (I repeated it's not correct, but It's just to try and check the I2C, if you can't register the drivers)

In the driver, I comment theses lines:
ret = register_driver(devpath, &g_bmp180fops, 0666, priv);
if (ret < 0)
{
snerr("ERROR: Failed to register driver: %d\n", ret);
kmm_free(priv);
}

To avoid the fail registration and also I added this at the botton of the registration function:
sninfo("BMP180 driver loaded successfully!\n");
while(1){
bmp180_getpressure(priv);
usleep(500000);
}

To check every 0.5s the pressure and the temperature.

Then in the example hello example I add this, below the printf:
stm32_bmp180initialize("dev/press");

Thank you so much for the help Alan!

One last question if you let me.
There is any specifically option, that you must check to enable the device registration? Because I can't even register the gpio
Alan Carvalho de Assis acassis@gmail.com [nuttx]
2018-02-08 13:57:59 UTC
Permalink
Hi Juan,

Nice to know you got it working. Now you need to investigate why does
register_driver() is failing?

Maybe because you don't have enough file descriptors available, please
check your configuration.

I think it is really easy to fix. Change the
CONFIG_NFILE_DESCRIPTORS=8 or bigger.

You implemented a workaround to fix a problem that is not related to
I2C, but probably a system configuration.

Case it didn't solve the issue, you need to investigate what it the
error value returned by register_driver().

BR,

Alan
Post by ***@yahoo.com [nuttx]
Hi Alan,
I posted a image, I thought it was attached.
Finally I was be able to solve it!!
There was a few problems it will try to explain here if I can help to
someone with the same problem, but maybe my main problem was my lack of
experience.
-The configuration in the menuconfig was correct. The sensor and I2C
debugging options are very good allies.
-When you want to know the assigned pin to anything I would recommend you to
see the pin map file in the configuration, because I was following the pin
assent of the board datasheet and it was different of the pin assignment in
the configuration. (For the olimex-stm32-e407 I2C1 is on PB6 and PB7 instead
PB8 and PB9)
At the moment, I already the problem of I'm be able to register the device
to use with open/close/read/write. I know that It's obligatory use this way
to use correctly NuttX but returns me an error at the time of registration
of the device.
But at the moment I only want to know if the I2C works, so to have the data
that I wanted I do the next things in the hello example and in the BMP180
driver (I repeated it's not correct, but It's just to try and check the I2C,
if you can't register the drivers)
ret = register_driver(devpath, &g_bmp180fops, 0666, priv);
if (ret < 0)
{
snerr("ERROR: Failed to register driver: %d\n", ret);
kmm_free(priv);
}
To avoid the fail registration and also I added this at the botton of the
sninfo("BMP180 driver loaded successfully!\n");
while(1){
bmp180_getpressure(priv);
usleep(500000);
}
To check every 0.5s the pressure and the temperature.
stm32_bmp180initialize("dev/press");
Thank you so much for the help Alan!
One last question if you let me.
There is any specifically option, that you must check to enable the device
registration? Because I can't even register the gpio
jfloresmu92@yahoo.com [nuttx]
2018-02-09 12:49:11 UTC
Permalink
Hi Alan.

You were right! I've changed :
Maximum number of file descriptors per task to 20
Maximum number of FILE streams to 20

Also there was another issue and it's that if you don't write the first / of the register path, it doesn't allow you to register it so changing from dev/press to /dev/press works.

And it's working perfect with every driver.

Thank you so much for the help!
Alan Carvalho de Assis acassis@gmail.com [nuttx]
2018-02-09 13:04:45 UTC
Permalink
I'm glad to help!

I noticed the missing "/" in your email, but I thought it was a typo.

These are tricks that you learn using NuttX, but it is straightforward
for people with embedded linux background.

You are welcome to the next level! ;-)

BR,

Alan
Post by ***@yahoo.com [nuttx]
Hi Alan.
Maximum number of file descriptors per task to 20
Maximum number of FILE streams to 20
Also there was another issue and it's that if you don't write the first / of
the register path, it doesn't allow you to register it so changing from
dev/press to /dev/press works.
And it's working perfect with every driver.
Thank you so much for the help!
Loading...