Author: acassis

Tips: SD Card Detection on NuttX

Today I got SDCard over SPI working on NuttX and already submitted the patch to mainline: https://bitbucket.org/nuttx/nuttx/commits/adb32e31a0123a16095f53de0c2b493b7db11281

Now you also can test SDCard using the STM32F103-Minimum board.

This post is to explain how NuttX’s SDCard driver does to ignore the Card Detect pin on modules that doesn’t have it. Yes, my module doesn’t have CD pin, see:

Initially I was getting this warning message:

WARNING: No card present

And when I tried to mount the SDCard it reported error -19. Well, error -19 is “ENODEV”, that means: “No such device”.

Then analyzing the source code of the driver (at nuttx/drivers/mmcsd/mmcsd_spi.c) I found this:

  /* Check if there is a card present in the slot.  This is normally a matter is
   * of GPIO sensing and does not really involve SPI, but by putting this
   * functionality in the SPI interface, we encapsulate the SPI MMC/SD
   * interface
   */

  if ((SPI_STATUS(spi, SPIDEV_MMCSD) & SPI_STATUS_PRESENT) == 0)
    {
      fwarn("WARNING: No card present\n");
      slot->state |= MMCSD_SLOTSTATUS_NODISK;
      return -ENODEV;
    }

Hmm, interesting! NuttX can use the return of spi_status() function to inform that card is present. Interesting, I was going to mess with the card detection thread/callback, saved by the bell!

Then all I did was to include:

#ifdef CONFIG_MMCSD_SPI
  if (devid == SPIDEV_MMCSD)
    {
       status |= SPI_STATUS_PRESENT;
    }
#endif

inside the stm32_spi1status() at nuttx/configs/stm32f103-minimum/src/stm32_spi.c!

This is a simple and clever solution, like everything else in the NuttX!

Compiling the Circuit Simulator kTechLab

I was searching for a circuit simulator for Linux and found kTechLab.

There is not a built package for Ubuntu (I’m using Ubuntu 16.04) then I compiled it from source code:

$ git clone https://github.com/ktechlab/ktechlab
$ cd ktechlab/
$ sudo apt-get install libqt4-dev
$ sudo apt-get install kdelibs5-dev
$ mkdir build
$ cd build
$ cmake ..
$ make
$ sudo make install

Then I just execute:

$ ktechlab

And kTechLab starts in all its glory!

How to get the machine origin with LINUXCNC

Today I tested the LinuxCNC controlling all 3 stepper motors (one for each axis) connected on TB6560-4V3 board.

Everything worked as expected, but zeroing the HOME axes manually is very boring. Then I decided to search how to do it automatically.

I found this nice post exampling the process:

http://o3ozono.com/en/como-conseguir-el-origen-maquina-con-linuxcnc/

I will need to connect the switches limiters (end-stoppers) to my CNC first to get it working. BTW I decided to post about it with the link to original post because it could be useful for other people.

CNC: Wire Limit Switches

I’m finishing my CNC building and now I need to wire the Limit Switches (End-stops).

My CNC initially will be controlled by TB6560-4V3 board, then searching for more information about how to connect the end-stops I found this nice tutorial:

http://www.hobbycncaustralia.com/Instructions/iI19wirelimit.htm

Their TB6560 board is a little-bit different from mine (they are using older model), but almost all (if not all) information could be applied to my board as well.

So, let me go ahead and stops these motors at its end!

NuttX 10 Years!

Tomorrow 07 Feb 2017 NuttX RTOS will complete 10 years as an Open Source project. The projects was published in the SourceForge on 07 Feb 2007.

From 2007 to 20017 NuttX evolved a lot. Maybe you don’t know, but NuttX is used by many companies. If you have a Moto Z Phone and got a Snap cover that Snap run NuttX!

Other example is Sony (that company that inspired Steve Jobs to create great products) is also using NuttX and even did a publish presentation about the benefits of using NuttX: http://events.linuxfoundation.org/sites/events/files/slides/DevelopingAudioProductsWithCortexM3NuttXC%2B%2B11_LFELC_OpenIoT_ishikawa_20161209_0.pdf

I discovered about NuttX in 2010. My friend Marcelo Barros pointed about an article in the Linux Jornal. Since then I have used NuttX in many projects as you can find on my old posts.

Also I created a YouTube channel dedicated to NuttX, called NuttX Channel:

NuttX is evolving fast and will be a Linux companion on “Embedded Arena”.

There is no other RTOS good like NuttX, you can spend your time searching. There are more than 200 available: https://en.wikipedia.org/wiki/Comparison_of_real-time_operating_systems

Thank Greg Nutt for this incredible RTOS called NuttX.

More here: http://www.nuttx.org