element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Smart Security and Surveillance
  • Challenges & Projects
  • Design Challenges
  • Smart Security and Surveillance
  • More
  • Cancel
Smart Security and Surveillance
Forum Sentinel Box - Part II - back to C
  • News
  • Projects
  • Forum
  • DC
  • Leaderboard
  • Files
  • Members
  • More
  • Cancel
  • New
Join Smart Security and Surveillance to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 4 replies
  • Subscribers 46 subscribers
  • Views 121 views
  • Users 0 members are here
  • security-challenge
  • rust
  • bmi160
  • MAX32630FTHR#
Related

Sentinel Box - Part II - back to C

saramic
saramic 11 days ago

I had fun with my Rust Crab experiment but it was time to get back to C  and LPSDK (Low Power ARM Micro SDK) if I was going to get anything complete for this challenge.

Recap

The idea is to build a smart lock box for digital devices to help control digital addiction, more on the idea can be found in part I

  • Sentinel Box - Part I - the plan

Rust for Hermetic builds

As I was not super happy in having to depend on EOL (End-of-life) software stacks like Mbed or LPSDK, I thought, how hard can it be writing a HAL (Hardware Abstraction Layer) from scratch in Rust. I had some initial wins getting the LED flashing, so I continued. In Part I I even started implementing some commands against the MAX14690 PMIC (Power Management Integrated Circuit) - I was actually going above and beyond and looking at the schematic of the dev board to see how it hangs together. This should have turned me OFF the idea of rust, but it gave me some false hope and I continued.

part of the MAX32630FTHR diagram highlighting the BMi160 accelerometer chip
The BMi160 accelerometer chip highlighted on the block diagram of the MAX32630FTHR

Next on the diagram there was an Accelerometer and Gyroscope using the BMi160 6-Axis Inertial Motion Sensor. With a bit of AI I soon enough had a driver to get X, Y, Z accelerations and using the MAX7219 I built a simple “attitude meter” which would show you which way to move the board to correct it being right way round. At this point I started to notice that some of the timing was out, my LED refresh rate was out by anywhere from 4x to 20x - that should have turned me OFF the idea of rust but with false hopes I continued.

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

The video above shows the attitude meter Airplane small️ that displays on the LED matrix the direction to turn the device to flatten the chip.

These were all distractions from the core of the Smart Security Challenge, so it was time to use a finger print reader. This would need UART (Universal Asynchronous Receiver-Transmitter) surely that cannot be hard? Well this is where the speed changes of 4X – 20X really started to bite. You see if you don’t know how fast your clock speed is going, you are not going to be able to transmit or receive at a given Baud. I tried a bunch of things. As I don’t have a logic analyzer nor oscilloscope on hand, I ended up hooking up an ESP32 to measure the duration of pulses. I didn’t know there was a function to measure pulse length pulseIn

unsigned long width = pulseIn(RX2_PIN, LOW, 5000000UL); // 5 s timeout
if (width == 0) {
  Serial.println("timeout — no signal on RX pin");
  return;
}
// Filter noise: allow 1200–115200 baud = 8–833 µs.
if (width < 8 || width > 833) {
  Serial.printf("noise/glitch: %lu µs (ignored)\n", width);
  return;
}
unsigned long estimated_baud = 1000000UL / width;
  // Square-wave formula: CPU MHz = N / width_µs, where N is the delay_cycles count.
  // Firmware step 1 uses N=4800. Steps double: 4800, 9600, 19200, 38400, 76800.
  // Read the first group of pulses (smallest width) and use N=4800.
Serial.printf(
  "LOW pulse: %lu µs | sq-wave asm::delay(4800)~9600 cycles: CPU ~%lu MHz\n",
  width,
  9600UL / width); // asm::delay(N) ≈ 2N cycles → CPU MHz = 9600 / width_µs

The above code also made me realise that \n does not cut it and my serial monitor only displayed the output when I had \r\n - need that Carriage return.

And all my Rust results were conclusive on 1 part, I was never getting 96 MHz. After some digging around I found the C file in LPSDK that seems to do the setup of the frequency

Maxim/Firmware/MAX3263X/Libraries/CMSIS/Device/Maxim/MAX3263X/Source/system_max3263x.c

  1. Enable the 32 kHz RTC oscillator — this serves as the stable reference clock for calibration, then wait for it to warm up and settle.
  2. Enable the RO calibration complete interrupt — so the system can signal when calibration is done.
  3. Clear the calibration complete interrupt flag — removing any stale state from a previous run.
  4. Write an initial trim value into the frequency calibration initial condition register — giving the hardware a starting point rather than hunting from scratch.
  5. Load that initial trim into the active frequency trim register — making it live.
  6. Enable the frequency control loop — the hardware mechanism that will drive the RO trim toward the target frequency.
  7. Start calibration in atomic mode — the hardware runs the measurement and adjustment cycle uninterrupted.
  8. Wait for the ro_cal_done flag — polling until the hardware signals completion.
  9. Stop the calibration engine.
  10. Disable the calibration complete interrupt.
  11. Read back the final trim value — the digital code the loop converged on.
  12. Write the final trim to the RO flash trim shadow register — persisting the result across resets.
  13. Restore the RTC to its previous state — since it may have been off before the routine borrowed it.
  14. Disable the frequency control loop.

no can do - I tried and tried again but could not get a consistent 96 MHz set which meant the UART was not going to work and the rust experiment was over for the time being

XCrab

Back to LPSDK

I couldn’t get myself to go to Mbed, a platform that is slated for EOL in July 2026, so it was back to C and the legacy LPSDK stack.

Hitting up my ESP32 setup, proved I had the right frequency set on UART and in no time I was connected to the fingerprint reader. The problem was that now my system would need to be multi modal. I pulled in a rotary encoder and got some runs on the board. First just to read turns to the left and right as well as a button press and display it on the LED MAX7219 matrix display. Then I added in the finger print reader.

Fingerprint reading success and failure

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

Getting the fingerprint, LED Matrix and rotary encoder was the easy bit, but having a state diagram that can save a bunch of fingerprints and identify them was starting to get a bit complicated, as is the setup on my workbench.Encoder and fingerprint state machine flow chart

Next

Now that I have a basic fingerprint reader and a build system that I am confident in, I think I need to get the required piece for a minimal complete build, some kind of actuator working: stepper motor, servo motor or just a motor with a worm drive. This will allow me to create a lock box with multi finger print triggering. If I get time, I may be able to expand on that. Time will tell.

Source

https://github.com/saramic/sentinel-box

  • Sign in to reply
  • Cancel

Top Replies

  • arvindsa
    arvindsa 1 day ago +1
    Good to know i have a fellow developer in LPSDK
  • skruglewicz
    skruglewicz 10 days ago

    Hi saramic 

    Hi saramic,

    I've been following your Sentinel Box project, and while the Rust experiment was fascinating, I really appreciate you sharing the transition back to C and the LPSDK.

    I’m currently trying to learn the ropes with the MAX32630FTHR, but I’ve hit a bit of a wall. I’m quite new to UART coding in general and I’m struggling to get a simple send/receive working between boards.

    If you have a moment, would you be willing to share how you laid out your pin connections and perhaps a snippet of the code you used for the UART setup within the LPSDK stack? I'd love to learn from your implementation as I try to get my own communication working.

    Thanks for the inspiration!

    Best,

    Stephen

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • saramic
    saramic 10 days ago in reply to skruglewicz

    hey - yeah I saw your post Forum #5: Proposed Design — Adaptive Sentinel: Security & Environmental Intelligence Hub and I presume you are trying to communicate between 2 MAX32630FTHR edge nodes to a master UNO Q via UART. I am no expert and have mostly used it to:

    • communicate to a peripheral (like the fingerprint reader) (master/slave give a command and wait for response) OR
    • to read output via a serial monitor on a computer (hence receive only)

    The rule of thumb of UART seems to be

    • RX of one device to TX of other device
    • between 2 devices
    • table top distance < 1m
    • set the same baud rate - probably start with 9600 and move to 57600 if it works
    • Same voltage 1V8 OR 3V3 OR 5V otherwise you may need a level shifter

    Reading https://docs.arduino.cc/tutorials/uno-q/user-manual/

    > WARNING: This interface operates at 1.8 V logic levels and must be used with a compatible USB-to-TTL converter to avoid hardware damage.

    and the MAX32630FTHR is 3V3


    Once you have that sorted, you would need to decide on how you want to communicate, there seem to be 3 approaches:

    1. Request/Response - one device is mater and sends requests and then listens - simple and predictable
    2. Turn-taking with a token/flag byte - decide on a special token (e.g. 0xFF) to decide who should be sending or listening
    3. Asychronous/event-driven - dependent on UART being full-duplex - but you need start/end framing markers and buffering so you can assemble complete messages from the stream

    Maybe you can get away with the UNO Q being master and asking the edge MAX32630FTHR to send back a response?

    The most flexible would be the asynchronous/event-driven approach, so assuming they are hooked up like

    RX on EDGE 1 wire A goes to TX on EDGE 1 wire A
    
    +--------------+        +--------------+
    | MAX32630FTHR |        | MAX32630FTHR |
    |  EDGE 1      |        |  EDGE 2      |
    |              |        |              |
    |  RX P3_0    A|---\/---|B RX P3_0     |
    |  TX P3_1    B|---/\___|A TX P3_1     |
    |  GND         |--------|  GND         |
    +--------------+        +--------------+
    

    but asynchronous means you will need to define a message etc. I tried to get this working with LPSDK, Mbed and ESP32 - LPSDK working code below

    Here we are using STX 0X02 (Start of Text) and ETX 0X03 (End of Text) to signify the start and end of the message


    #define MSG_START   0x02    // ASCII STX
    #define MSG_END     0x03    // ASCII ETX
    #define BUF_SIZE    128
    
    // -------------------------------------------------------------------------
    // Send a framed message over UART2
    // -------------------------------------------------------------------------
    static void send_message(const char *msg)
    {
        uint8_t start = MSG_START;
        uint8_t end   = MSG_END;
        UART_Write(MXC_UART2, &start, 1);
        UART_Write(MXC_UART2, (uint8_t *)msg, strlen(msg));
        UART_Write(MXC_UART2, &end, 1);
    
        debug_print("[TX] --> ");
        debug_print(msg);
        debug_print("\r\n");
    }
    

    in the main loop, I send a PING message every ~1 second

    #define TICK_MS     10      // loop cadence
    #define TICKS_PER_PING  100 // 10ms * 100 = ~1s
    
    int main(void)
    {
        while (1) {
            // TMR_Delay is blocking for TICK_MS but the hardware RX FIFO
            // (32 bytes) holds incoming bytes while we wait.
            TMR_Delay(MXC_TMR0, MSEC(TICK_MS));
    
            if (++tick >= TICKS_PER_PING) {
                tick = 0;
                char msg[32];
                snprintf(msg, sizeof(msg), "PING %lu", ping_count++);
                send_message(msg);
            }
        }
    }

    that's the easy bit - of course I can send any information like this, temperature, accelerometer values, etc

    Then you need to be able to read these messages

    #define MSG_START   0x02    // ASCII STX
    #define MSG_END     0x03    // ASCII ETX
    #define BUF_SIZE    128
    
    // -------------------------------------------------------------------------
    // Non-blocking drain of UART2 RX FIFO — call on every loop tick
    // -------------------------------------------------------------------------
    static void read_incoming(void)
    {
        while (UART_NumReadAvail(MXC_UART2)) {
            uint8_t b;
            int     n = 0;
            UART_Read(MXC_UART2, &b, 1, &n);
            if (n != 1)
                break;
    
            if (b == MSG_START) {
                rx_pos     = 0;
                in_message = 1;
    
            } else if (b == MSG_END) {
                if (in_message && rx_pos > 0)
                    handle_message(rx_buf, rx_pos);
                rx_pos     = 0;
                in_message = 0;
    
            } else if (in_message) {
                if (rx_pos < BUF_SIZE - 1) {
                    rx_buf[rx_pos++] = b;
                } else {
                    debug_print("[WARN] RX overflow, discarding\r\n");
                    rx_pos     = 0;
                    in_message = 0;
                }
            }
        }
    }
    
    int main(void)
    {
        while (1) {
            read_incoming();
        }
    }

    I managed to make this work between an ESP32 and the LPSDK code above running on MAX32630FTHR - in this case the ESP32 was connected to my computer and the output was showing the ESP32 PING to the outside and the incoming PING from the MAX32630FTHR - the output looks like this (ping count dependent on restart)

    [DEBUG] UART bridge ready
    [RX] <-- PING 1931
    [TX] --> PING 1000
    [RX] <-- PING 1932
    [TX] --> PING 2000
    [RX] <-- PING 1933
    [TX] --> PING 3000
    [RX] <-- PING 1934

    so there you have it - I hope the issue is not that you hooked up 1V8 on the UNO Q to the 3V3 on the MAX32630FTHR

    UART is fine for 2 boards on a desk

    Other alternatives are

    • CAN bus
      • 128 (CAN) nodes or unlimited with CAN FD
      • 500m @125kbps or 40m @1Mbps
      • CRC + ACK + error frames
      • 2 wires twisted pair + GND
      • needs MCP2515 or similar chip
      • needs 120Ω termination resistors to prevent reflection corrupting the signal
    • I2C
      • can have up to 127 devices
      • short distances <1m
      • Master/Slave topology fits
      • may need pull-up resistors 4.7kΩ at 100kHz
      • SDA/SCL share bus so needs collision management
    • RS-485
      • can have 32 nodes
      • cheap MAX485 or SP3485 chips
      • still UART underneath
      • 100m+ at 100kbps
      • differential signaling means it is noise immune

    there is also: LIN Bus, Modbus, EtherCAT, 1-Wire, SPI

    All code can be found:

    • github.com/.../src

    Including some Mbed code

    • github.com/.../main-mbed-uart.cpp
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • saramic
    saramic 5 days ago in reply to saramic

    slight correction here - the 1.8V UART seems to be the ONLY the JCTL headers - the 5x2 header near the USB-C connector. This is if you want to connect via UART "JCTL is directly connected to the Qualcomm DragonwingTm QRB2210" – MPU (Microprocessor Unit ie the Linux box) - this would let you see the Linux console etc I presume - so maybe not the most useful for connecting the device to other devices.

    The MPU does not seem to have any GPIO pins connected. They all seem to be connected via the MCU (Microcontroller Unit ie. STM32U585) via JDIGITAL and JANALOG. There is also a JSPI. Keeping to the UART theme - you could communicate with your edge nodes and UART via JDIGITAL pins and the MCU - but you would still need to communicate between the MCU and the MPU if you wanted to display values on the dashboard etc. I am yet to look into this but it sounds like there might be some kind of SPI connection between the MPU's /dev/spidev0.0 and the MCU? the alternative is the RPC (Remote Procedure Call)

    > "A built-in RPC library (i.e., Arduino Bridge) brings together the MPU running Linux and the microcontroller"

    I am sure I will run into working this out soon as I start trying to connect my UNO Q via CAN Bus

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • arvindsa
    arvindsa 1 day ago

    Good to know i have a fellow developer in LPSDK

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube