Category: BrainDamage

Testing QDBM: Quick Database Manager

The QDBM is a small database manager that could be used for embedded systems (just pay attention on its license: LGPL, so only dynamic linkage if you are using it for commercial applications).

Fortunately the documentation of the project is very good:

The most basic example is demonstrated on project documentation:

#include <depot.h>
#include <stdlib.h>
#include <stdio.h>

#define NAME     "mikio"
#define NUMBER   "000-1234-5678"
#define DBNAME   "book"

int main(int argc, char **argv){
  DEPOT *depot;
  char *val;

  /* open the database */
  if(!(depot = dpopen(DBNAME, DP_OWRITER | DP_OCREAT, -1))){
    fprintf(stderr, "dpopen: %s\n", dperrmsg(dpecode));
    return 1;

  /* store the record */
  if(!dpput(depot, NAME, -1, NUMBER, -1, DP_DOVER)){
    fprintf(stderr, "dpput: %s\n", dperrmsg(dpecode));

  /* retrieve the record */
  if(!(val = dpget(depot, NAME, -1, 0, -1, NULL))){
    fprintf(stderr, "dpget: %s\n", dperrmsg(dpecode));
  } else {
    printf("Name: %s\n", NAME);
    printf("Number: %s\n", val);

  /* close the database */
    fprintf(stderr, "dpclose: %s\n", dperrmsg(dpecode));
    return 1;

  return 0;

To compile this example you need to install the libqdbm:

$ sudo apt install libqdbm-dev

Save the above code as phone.c and compile this way:

$ gcc -std=c99 -o phone phone.c $(pkg-config --cflags --libs qdbm)

You can also install the package qdbm-util:

$ sudo apt install qdbm-util

Now you can create the database using this command:

$ dpmgr create mydata.qdbm

To insert data:

$ dpmgr put mydata.qdbm “Joe” “Student”

$ dpmgr put mydata.qdbm “Mary” “Doctor”

$ dpmgr put mydata.qdbm “Julia” “Actress”

RTL-SDR as FM radio on Linux

Although you don’t need GNUradio, it is a good idea to install it and the rtl_sdr wil be installed as well:

$ sudo apt install gnuradio
$ sudo apt install gr-osmosdr

You will need the audio “play” command, it is on sox package:

$ sudo apt install sox

And finally (105.1MHz is Antena1 in Belo Horizonte)

$ rtl_fm -M wbfm -f 105.1M | play -r 32k -t raw -e s -b 16 -c 1 -V1 -

Using JLink with NXP MK64FX512VLL12

This is the command:

$ sudo JLinkExe -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
License(s): FlashBP, GDB
Type "connect" to establish a target connection, '?' for help
Please specify device / core. : ATSAML21G18
Type '?' for selection dialog
Specify target interface speed [kHz]. : 4000 kHz
Device "MK64FX512XXX12" selected.
Connecting to target via SWD
Protection bytes in flash at addr. 0x400 - 0x40F indicate that readout protection is set.
For debugger connection the device needs to be unsecured.
Note: Unsecuring will trigger a mass erase of the internal flash.
Device will be unsecured now.
Found SW-DP with ID 0x2BA01477
Scanning AP map to find all available APs
AP[2]: Stopped AP scan as end of AP map has been reached
AP[0]: AHB-AP (IDR: 0x24770011)
AP[1]: JTAG-AP (IDR: 0x001C0000)
Iterating through AP map to find AHB-AP to use
AP[0]: Core found
AP[0]: AHB-AP ROM base: 0xE00FF000
CPUID register: 0x410FC241. Implementer code: 0x41 (ARM)
Found Cortex-M4 r0p1, Little endian.
FPUnit: 6 code (BP) slots and 2 literal slots
CoreSight components:
ROMTbl[0] @ E00FF000
ROMTbl[0][0]: E000E000, CID: B105E00D, PID: 000BB00C SCS-M7
ROMTbl[0][1]: E0001000, CID: B105E00D, PID: 003BB002 DWT
ROMTbl[0][2]: E0002000, CID: B105E00D, PID: 002BB003 FPB
ROMTbl[0][3]: E0000000, CID: B105E00D, PID: 003BB001 ITM
ROMTbl[0][4]: E0040000, CID: B105900D, PID: 000BB9A1 TPIU
ROMTbl[0][5]: E0041000, CID: B105900D, PID: 000BB925 ETM
ROMTbl[0][6]: E0042000, CID: B105900D, PID: 003BB907 ETB
ROMTbl[0][7]: E0043000, CID: B105900D, PID: 001BB908 CSTF
Cortex-M4 identified.