|
| 1 | +From 691324f0991a45b88cd48eefc5ae8c7e85bddb1e Mon Sep 17 00:00:00 2001 |
| 2 | +From: Josua Mayer <josua@solid-run.com> |
| 3 | +Date: Sun, 12 Oct 2025 15:09:53 +0200 |
| 4 | +Subject: [PATCH] add example app to configure mia-m10q uart interface |
| 5 | + |
| 6 | +Add example app to configure MIA-M10Q on SolidRun i.MX8DXL System on |
| 7 | +Module after (re-)boot. |
| 8 | + |
| 9 | +It should issue soft reset (because the board cannot issue hard reset), |
| 10 | +and update baud-rate from default 38400 to 115200. |
| 11 | + |
| 12 | +This application should be built with UBXLIB_FLAGS: |
| 13 | + - -DU_CFG_APP_GNSS_UART=2 |
| 14 | + - -DU_CFG_APP_UART_PREFIX=/dev/ttyLP |
| 15 | + - -DU_CFG_APP_FILTER=GnssUartSetup" |
| 16 | + |
| 17 | +Signed-off-by: Josua Mayer <josua@solid-run.com> |
| 18 | +--- |
| 19 | + example/gnss/uart_setup.c | 190 ++++++++++++++++++++++++++++++++++++++ |
| 20 | + 1 file changed, 190 insertions(+) |
| 21 | + create mode 100644 example/gnss/uart_setup.c |
| 22 | + |
| 23 | +diff --git a/example/gnss/uart_setup.c b/example/gnss/uart_setup.c |
| 24 | +new file mode 100644 |
| 25 | +index 00000000..8b8a4393 |
| 26 | +--- /dev/null |
| 27 | ++++ b/example/gnss/uart_setup.c |
| 28 | +@@ -0,0 +1,190 @@ |
| 29 | ++/* |
| 30 | ++ * Copyright 2019-2023 u-blox |
| 31 | ++ * Copyright 2023-2025 Josua Mayer <josua@solid-run.com> |
| 32 | ++ * |
| 33 | ++ * Licensed under the Apache License, Version 2.0 (the "License"); |
| 34 | ++ * you may not use this file except in compliance with the License. |
| 35 | ++ * You may obtain a copy of the License at |
| 36 | ++ * |
| 37 | ++ * http://www.apache.org/licenses/LICENSE-2.0 |
| 38 | ++ * |
| 39 | ++ * Unless required by applicable law or agreed to in writing, software |
| 40 | ++ * distributed under the License is distributed on an "AS IS" BASIS, |
| 41 | ++ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 42 | ++ * See the License for the specific language governing permissions and |
| 43 | ++ * limitations under the License. |
| 44 | ++ */ |
| 45 | ++ |
| 46 | ++/** @brief This example configures MIA-M10Q UART baud-rate consistently |
| 47 | ++ * after hot and cold boot for 115200. |
| 48 | ++ */ |
| 49 | ++ |
| 50 | ++// Bring in all of the ubxlib public header files |
| 51 | ++# include "ubxlib.h" |
| 52 | ++ |
| 53 | ++// Bring in the application settings |
| 54 | ++# include "u_cfg_app_platform_specific.h" |
| 55 | ++ |
| 56 | ++# ifndef U_CFG_DISABLE_TEST_AUTOMATION |
| 57 | ++// This purely for internal u-blox testing |
| 58 | ++# include "u_cfg_test_platform_specific.h" |
| 59 | ++# endif |
| 60 | ++ |
| 61 | ++/* ---------------------------------------------------------------- |
| 62 | ++ * COMPILE-TIME MACROS |
| 63 | ++ * -------------------------------------------------------------- */ |
| 64 | ++ |
| 65 | ++// For u-blox internal testing only |
| 66 | ++# ifdef U_PORT_TEST_ASSERT |
| 67 | ++# define EXAMPLE_FINAL_STATE(x) U_PORT_TEST_ASSERT(x); |
| 68 | ++# else |
| 69 | ++# define EXAMPLE_FINAL_STATE(x) |
| 70 | ++# endif |
| 71 | ++ |
| 72 | ++# ifndef U_PORT_TEST_FUNCTION |
| 73 | ++# error if you are not using the unit test framework to run this code you must ensure that the platform clocks/RTOS are set up and either define U_PORT_TEST_FUNCTION yourself or replace it as necessary. |
| 74 | ++# endif |
| 75 | ++ |
| 76 | ++/* ---------------------------------------------------------------- |
| 77 | ++ * TYPES |
| 78 | ++ * -------------------------------------------------------------- */ |
| 79 | ++ |
| 80 | ++/* ---------------------------------------------------------------- |
| 81 | ++ * VARIABLES |
| 82 | ++ * -------------------------------------------------------------- */ |
| 83 | ++ |
| 84 | ++// GNSS configuration. |
| 85 | ++static uDeviceCfg_t gDeviceCfg = { |
| 86 | ++ .deviceType = U_DEVICE_TYPE_GNSS, |
| 87 | ++ .deviceCfg = { |
| 88 | ++ .cfgGnss = { |
| 89 | ++ .moduleType = U_GNSS_MODULE_TYPE_M10, |
| 90 | ++ .pinEnablePower = -1, // not used |
| 91 | ++ .pinDataReady = -1 // Not used |
| 92 | ++ // There is an additional field here: |
| 93 | ++ // "i2cAddress", which we do NOT set, |
| 94 | ++ // we allow the compiler to set it to 0 |
| 95 | ++ // and all will be fine. You may set the |
| 96 | ++ // field to the I2C address of your GNSS |
| 97 | ++ // device if you have modified the I2C |
| 98 | ++ // address of your GNSS device to something |
| 99 | ++ // other than the default value of 0x42, |
| 100 | ++ // for example: |
| 101 | ++ // .i2cAddress = 0x43 |
| 102 | ++ }, |
| 103 | ++ }, |
| 104 | ++ .transportType = U_DEVICE_TRANSPORT_TYPE_UART, |
| 105 | ++ .transportCfg = { |
| 106 | ++ .cfgUart = { |
| 107 | ++ .uart = U_CFG_APP_GNSS_UART, |
| 108 | ++ .baudRate = 38400, |
| 109 | ++ .pinTxd = -1, // not relevant on Linux |
| 110 | ++ .pinRxd = -1, // not relevant on Linux |
| 111 | ++ .pinCts = -1, // not relevant on Linux |
| 112 | ++ .pinRts = -1, // not relevant on Linux |
| 113 | ++ .pPrefix = U_PORT_STRINGIFY_QUOTED(U_CFG_APP_UART_PREFIX) |
| 114 | ++ }, |
| 115 | ++ }, |
| 116 | ++}; |
| 117 | ++ |
| 118 | ++/* ---------------------------------------------------------------- |
| 119 | ++ * STATIC FUNCTIONS |
| 120 | ++ * -------------------------------------------------------------- */ |
| 121 | ++ |
| 122 | ++/* ---------------------------------------------------------------- |
| 123 | ++ * PUBLIC FUNCTIONS: THE EXAMPLE |
| 124 | ++ * -------------------------------------------------------------- */ |
| 125 | ++ |
| 126 | ++// The entry point, main(): before this is called the system |
| 127 | ++// clocks must have been started and the RTOS must be running; |
| 128 | ++// we are in task space. |
| 129 | ++U_PORT_TEST_FUNCTION("[example]", "GnssUartSetup") |
| 130 | ++{ |
| 131 | ++ uDeviceHandle_t devHandle = NULL; |
| 132 | ++ int32_t ret; |
| 133 | ++ |
| 134 | ++ // Try to open the device at 115200 baud (in case already configured) |
| 135 | ++ uPortInit(); |
| 136 | ++ uDeviceInit(); |
| 137 | ++ gDeviceCfg.transportCfg.cfgUart.baudRate = 115200; |
| 138 | ++ printf("opening gps at %d baud ...", gDeviceCfg.transportCfg.cfgUart.baudRate); |
| 139 | ++ ret = uDeviceOpen(&gDeviceCfg, &devHandle); |
| 140 | ++ if (ret == 0) { |
| 141 | ++ puts(" done\n"); |
| 142 | ++ |
| 143 | ++ // send hot reset |
| 144 | ++ puts("sending hot reset ..."); |
| 145 | ++ uint8_t hot_rst_msg[] = { 0xb5, 0x62, 0x06, 0x04, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0f, 0x66 }; |
| 146 | ++ ret = uGnssMsgSend(devHandle, (void *)hot_rst_msg, sizeof(hot_rst_msg)); |
| 147 | ++ if (ret != sizeof(hot_rst_msg)) { |
| 148 | ++ printf(" error: uGnssMsgSend sent %d, expected %zu\n", ret, sizeof(hot_rst_msg)); |
| 149 | ++ goto deinit; |
| 150 | ++ } |
| 151 | ++ puts(" done\n"); |
| 152 | ++ |
| 153 | ++ // close device but keep it running |
| 154 | ++ uDeviceClose(devHandle, false); |
| 155 | ++ } else { |
| 156 | ++ printf(" error: uDeviceOpen failed with %d (expected on cold boot)\n", ret); |
| 157 | ++ } |
| 158 | ++ uDeviceDeinit(); |
| 159 | ++ uPortDeinit(); |
| 160 | ++ |
| 161 | ++ // device is now at reset defaults |
| 162 | ++ |
| 163 | ++ // Open the device at 38400 baud (reset defalt) |
| 164 | ++ uPortInit(); |
| 165 | ++ uDeviceInit(); |
| 166 | ++ gDeviceCfg.transportCfg.cfgUart.baudRate = 38400; |
| 167 | ++ printf("opening gps at %d baud ...", gDeviceCfg.transportCfg.cfgUart.baudRate); |
| 168 | ++ ret = uDeviceOpen(&gDeviceCfg, &devHandle); |
| 169 | ++ if (ret == 0) { |
| 170 | ++ puts(" done\n"); |
| 171 | ++ |
| 172 | ++ // reconfigure to 115200 |
| 173 | ++ printf("configuring for %d baud ...", 115200); |
| 174 | ++ uint8_t prt_cfg_msg[] = {0x24, 0x50, 0x55, 0x42, 0x58, 0x2C, 0x34, 0x31, 0x2c, 0x31, 0x2c, 0x30, 0x30, 0x32, 0x33, 0x2c, 0x30, 0x30, 0x30, 0x33, 0x2c, 0x31, 0x31, 0x35, 0x32, 0x30, 0x30, 0x2c, 0x30, 0x2a, 0x31, 0x45, 0x0d, 0x0a}; |
| 175 | ++ ret = uGnssMsgSend(devHandle, (void *)prt_cfg_msg, sizeof(prt_cfg_msg)); |
| 176 | ++ if (ret != sizeof(prt_cfg_msg)) { |
| 177 | ++ printf(" error: uGnssMsgSend sent %d, expected %zu\n", ret, sizeof(prt_cfg_msg)); |
| 178 | ++ goto deinit; |
| 179 | ++ } |
| 180 | ++ |
| 181 | ++ // wait for gps reconfiguration completion |
| 182 | ++ uPortTaskBlock(100); |
| 183 | ++ |
| 184 | ++ // close device but keep it running |
| 185 | ++ uDeviceClose(devHandle, false); |
| 186 | ++ } else { |
| 187 | ++ printf(" error: uDeviceOpen failed with %d\n", ret); |
| 188 | ++ goto deinit; |
| 189 | ++ } |
| 190 | ++ uDeviceDeinit(); |
| 191 | ++ uPortDeinit(); |
| 192 | ++ |
| 193 | ++ // Open the device at 115200 baud |
| 194 | ++ uPortInit(); |
| 195 | ++ uDeviceInit(); |
| 196 | ++ gDeviceCfg.transportCfg.cfgUart.baudRate = 115200; |
| 197 | ++ printf("opening gps at %d baud ...", gDeviceCfg.transportCfg.cfgUart.baudRate); |
| 198 | ++ ret = uDeviceOpen(&gDeviceCfg, &devHandle); |
| 199 | ++ if (ret == 0) { |
| 200 | ++ puts(" done\n"); |
| 201 | ++ } else { |
| 202 | ++ printf(" error: uDeviceOpen failed with %d\n", ret); |
| 203 | ++ goto deinit; |
| 204 | ++ } |
| 205 | ++ |
| 206 | ++ /* TODO: apply advanced configuration */ |
| 207 | ++ |
| 208 | ++ // close device but keep it running |
| 209 | ++ uDeviceClose(devHandle, false); |
| 210 | ++ |
| 211 | ++deinit: |
| 212 | ++ uDeviceDeinit(); |
| 213 | ++ uPortDeinit(); |
| 214 | ++ |
| 215 | ++ EXAMPLE_FINAL_STATE(ret == 0); |
| 216 | ++} |
| 217 | ++ |
| 218 | ++// End of file |
| 219 | +-- |
| 220 | +2.51.0 |
| 221 | + |
0 commit comments