Using GSM Modem on NuttX with DNS support

I already demonstrated how to use NuttX with GSM modem. But I realized that it wasn’t with DNS support enabled. Then I decided to enable DNS and test it again:

 ATE1
 OK
 chat: OK AT+CGDCONT=1,"IP","tim.br"
 AT+QACCM=0,0
 OK
 chat: OK ATD99**1#
 AT+CGDCONT=1,"IP","tim.br"
 OK
 chat: CONNECT 
 ATD99**1#
 CONNECT
 IP: 192.168.254.254 
 IP: 100.86.71.207 IP: 100.86.71.207 
nsh> mount -t procfs /proc
nsh> ifconfig
ppp0    Link encap:TUN at UP
        inet addr:100.86.71.207 DRaddr:192.168.254.254 Mask:0.0.0.0
nsh> ?
help usage:  help [-v] []
[         cp        exec      hexdump   mh        set       umount    
  ?         cmp       exit      ifconfig  mount     sh        unset     
  addroute  date      false     kill      mw        sleep     usleep    
  break     dd        free      ls        nslookup  test      xd        
  cat       echo      help      mb        ps        true      
Builtin Apps:
  ping        testlogbuf  leds        pppd        
nsh> nslookup google.com
Host: google.com  IPv4 Addr: 172.217.29.110
nsh> ping google.com
PING 172.217.29.110 56 bytes of data
56 bytes from 172.217.29.110: icmp_seq=0 time=420 ms
56 bytes from 172.217.29.110: icmp_seq=1 time=490 ms
56 bytes from 172.217.29.110: icmp_seq=2 time=530 ms
56 bytes from 172.217.29.110: icmp_seq=3 time=840 ms
56 bytes from 172.217.29.110: icmp_seq=4 time=410 ms
56 bytes from 172.217.29.110: icmp_seq=5 time=500 ms
56 bytes from 172.217.29.110: icmp_seq=6 time=540 ms
56 bytes from 172.217.29.110: icmp_seq=7 time=590 ms
56 bytes from 172.217.29.110: icmp_seq=8 time=640 ms
56 bytes from 172.217.29.110: icmp_seq=9 time=680 ms
10 packets transmitted, 10 received, 0% packet loss, time 10100 ms
nsh> 

I just followed the video tutorial #044:

Ping on NuttX returning EALREADY

After the GSM modem connection I’m trying to “ping 8.8.8.8” and it is returning an error:

 ATZ
 OK
 chat: cmd 1, arg ON
 chat: cmd 4, arg 30
 chat:  ATE1
 chat: OK AT+QACCM=0,0
 ATE1
 OK
 chat: OK AT+CGDCONT=1,"IP","tim.br"
 AT+QACCM=0,0
 OK
 chat: OK ATD99**1#
 AT+CGDCONT=1,"IP","tim.br"
 OK
 chat: CONNECT 
 ATD99**1#
 CONNECT
 IP: 192.168.254.254 
 IP: 100.74.7.202 
 IP: 100.74.7.202 
 nsh> ifconfig
 nsh: ifconfig: opendir failed: 20
 nsh> mount -t procfs /proc
 nsh> free
              total       used       free    largest
 Umem:        24416      15016       9400       9400
 nsh> ifconfig
 ppp0    Link encap:TUN at UP
         inet addr:100.74.7.202 DRaddr:192.168.254.254 Mask:0.0.0.0
 nsh> ping 8.8.8.8
 PING 8.8.8.8 56 bytes of data
 No response from 8.8.8.8: icmp_seq=0 time=1000 ms
 No response from 8.8.8.8: icmp_seq=1 time=1000 ms
 No response from 8.8.8.8: icmp_seq=2 time=1000 ms
 No response from 8.8.8.8: icmp_seq=3 time=1000 ms
 No response from 8.8.8.8: icmp_seq=4 time=1000 ms
 No response from 8.8.8.8: icmp_seq=5 time=1000 ms
 No response from 8.8.8.8: icmp_seq=6 time=1000 ms
 ERROR: sendto failed at seqno 7: 114
 7 packets transmitted, 0 received, 100% packet loss, time 7070 ms
 nsh>

I suspect the issue is in the Mobile Operator TIM

UPDATE: I was using a bad antenna. Using a better GSM antenna everything worked fine:

Blender VSE using animation on Transform effect

Blender is a very powerful 3D software, but it also has internally a good Video Editor (VSE – Video Sequence Editor).

If you want to learn it, there is a good video tutorial playlist here:

The Blender VSE has a very power effect feature called Transform, you just select the your video strip and Add -> Effect Strip -> Transform. Then you can offset, zoom in/out, rotate, etc.

But it is also possible to use Keyframe with Transform, but it is a little bit tricker because it doesn’t follow the traditional Blender way. You need to edit the Transform strip Properties (press N case it is not visible) and edit the values, for each edited value press ENTER to confirm and then type I to Insert keyframe.

If it worked you will see the Property field changing its color to yellow:

ffmpeg conversion error: Could not find tag for codec pcm_s16be

I was trying to convert a big footage to h264 format using ffmpeg command:

$ ffmpeg -i C0005.MP4 -c:v libx264 -c:a copy C0005_H264.mp4

But it was returning this error:

Could not find tag for codec pcm_s16be in stream #1, codec not currently supported in container
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Error initializing output stream 0:0 --

After some searching I found some hints here:

https://ffmpeg.org/pipermail/libav-user/2016-January/008756.html

Oh yeah, we PCM 16-bit is not support by MP4 see: https://en.wikipedia.org/wiki/Comparison_of_video_container_formats, but it is strange because the original video as on MP4 container and I was just instructing ffmpeg to copy the audio. Too Lazy I will not search for it, but I think it is ffmpeg fault. If you find further info, please comment here.

I decided to use the AAC audio format instead copying the PCM format that was embedded in the video:

$ ffmpeg -i C0005.MP4 -c:v libx264 -c:a aac -strict experimental C0005_H264.mp4

And it worked fine!

Running NuttX on Arduino M0

NuttX has support to SAMD21 MCU and this is the MCU used on Arduino M0. Then I decided to add board support to Arduino M0 on NuttX mainline.

I used the Wemos SAMD21 M0 (a compatible Arduino M0 board), but you can use the original Arduino M0 or even the RobotDyn SAMD21 M0 board.

Enter inside NuttX directory, clear it and configure to use the arduino-m0:

$ cd nuttx
$ make distclean 
$ ./tools/configure.sh arduino-m0:nsh
Detected arm Architecture
Detected samd2l2 Chip
Copy files
Refreshing…

Compile it:

$ make

After compilation, confirm the binary was generated:

$ ls -l nuttx.bin 
-rwxr-xr-x 1 alan alan 43436 set 22 13:13 nuttx.bin

Connect J-Link to SWD (EDBG) pin header and run and flash the firmware:

$ sudo JLinkExe -device ATSAML21G18 -if SWD

SEGGER J-Link Commander V6.46h (Compiled Jun 28 2019 17:19:57)
DLL version V6.46h, compiled Jun 28 2019 17:19:50
Connecting to J-Link via USB…O.K.
Firmware: J-Link ARM V8 compiled Nov 28 2014 13:44:46
Hardware version: V8.00
S/N: 26800XXXX
License(s): FlashBP, GDB
OEM: SEGGER-EDU

VTref=3.306V
Type "connect" to establish a target connection, '?' for help
J-Link>connect
Specify target interface speed [kHz]. : 4000 kHz
Speed>4000

Device "ATSAML21G18" selected.
Connecting to target via SWD
InitTarget()
Found SW-DP with ID 0x0BC11477

Scanning AP map to find all available APs
AP[1]: Stopped AP scan as end of AP map has been reached
AP[0]: AHB-AP (IDR: 0x04770031)
Iterating through AP map to find AHB-AP to use
AP[0]: Core found
AP[0]: AHB-AP ROM base: 0x41003000
CPUID register: 0x410CC601. Implementer code: 0x41 (ARM)
Found Cortex-M0 r0p1, Little endian.
FPUnit: 4 code (BP) slots and 0 literal slots
CoreSight components:
ROMTbl[0] @ 41003000
ROMTbl[0][0]: E00FF000, CID: B105100D, PID: 000BB4C0 ROM Table
ROMTbl[1] @ E00FF000
ROMTbl[1][0]: E000E000, CID: B105E00D, PID: 000BB008 SCS
ROMTbl[1][1]: E0001000, CID: B105E00D, PID: 000BB00A DWT
ROMTbl[1][2]: E0002000, CID: B105E00D, PID: 000BB00B FPB
ROMTbl[0][1]: 41006000, CID: B105900D, PID: 001BB932 MTB-M0+
Cortex-M0 identified.
J-Link>loadbin nuttx.bin 0

Now use a USB/Serial and connect the RXD to RXD pad of the board and TXD to TXD pad. Configure the minicom to use 115200 8n1 and after reseting the board you should get:

NuttShell (NSH)
nsh>

Using DS1307 RTC Module with NuttX

Kids, always read the datasheet before starting wiring your module. I always said it to other people, but sometimes I’m anxious to get things working and fail to follow my own advice.

It happened again with DS1307 Module that I got from Aliexpress:

I connected it to STM32F4Discovery board this way:

----------------------------------
STM32F4Discovery |  DS1307 Module
-----------------+----------------
GND              |   GND
3V               |   VCC
SDA              |   PB9
SCL              |   PB7
-----------------+----------------

But when NuttX was starting it was failing to communicate with the module, returning error -6 (= ENXIO = “No such device or address”) :

ABCDF
 stm32_ds1307_init: Initialize I2C1
 stm32_ds1307_init: Bind the DS1307 RTC driver to I2C1
 up_rtc_getdatetime: ERROR: I2C_TRANSFER failed: -6

I used the Logic Analyzer and saw that the address was sent correctly, but the board wasn’t responding. After some time I decided to look the datasheet to confirm that it could work with 3V (I assumed it because the module uses a 3V battery) and to my surprise it only works from 4.5V to 5V.

Then connecting the VCC from the module to 5V worked:

ABCDF
stm32_ds1307_init: Initialize I2C1
stm32_ds1307_init: Bind the DS1307 RTC driver to I2C1
rtc_dumptime: Returning:
rtc_dumptime: tm_sec: 00000026
rtc_dumptime: tm_min: 00000024
rtc_dumptime: tm_hour: 00000004
rtc_dumptime: tm_mday: 00000019
rtc_dumptime: tm_mon: 00000009
rtc_dumptime: tm_year: 00000068
nsh> date
Oct 25 04:36:56 2004

nsh> date -s "Sep 22 08:04:00 2019"
up_rtc_settime: Setting time tp=(1569139440,0)
rtc_dumptime: New time:
rtc_dumptime: tm_sec: 00000000
rtc_dumptime: tm_min: 00000004
rtc_dumptime: tm_hour: 00000008
rtc_dumptime: tm_mday: 00000016
rtc_dumptime: tm_mon: 00000008
rtc_dumptime: tm_year: 00000077
nsh>

I turned the board OFF and let it alone some minutes and when I connected it again the time was correct:

NuttShell (NSH)
nsh> date
Sep 22 08:23:41 2019
nsh>

These are the main options I enabled on NuttX to get it working:

 STM32_I2C1
 STM32_I2C
 RTC
 RTC_DATETIME
 RTC_DS1307
 RTC_DSXXXX
 RTC_EXTERNAL