Skip to content

Conversation

@QuinaGit
Copy link

Hi, this code does not work perfectly.

I intend to write the middleware that enables the bma400 accelerometer to be connected.
There are a few todo's still in the code, because I am unsure of a few things and want to revisit them.

I tried to find all the places in the code where the BMX160 is involved and used that as a reference for the BMA400 integration.

Feel free to edit the code if you find incorrect integration.

@liamw9534
Copy link
Collaborator

Is it your intention to remove bmx160 support completely and replace with bma400? I'm just thinking of existing hardware that has bmx160 fitted. Just checking the intention of the change -- sorry for interjecting but I don't have any visibility of the background to the change.

@QuinaGit
Copy link
Author

Yes, I had a look at the PSB design and electronic schematics and it seems like the Linkit hardware was designed to incorporate the BMA400. I also searched for the availability of BMX160 accelerometers, but it is a discontinued component. The only way I see that the BMX160 could be used is as a breakout board. There are even solder pads for the BMA400 on the Linkit. So, that is the intention of the change.
I have soldered the BMA400 onto the board (u7), and with the current code I don't get any response from the accelerometer, so I am not sure if it is because of the solder connection, or if I where unable to implement the code correctly.
Linkit V3_1_Schematics_2022-12-13.PDF
BMA400 datasheet.pdf

@liamw9534
Copy link
Collaborator

liamw9534 commented Apr 25, 2023 via email

@QuinaGit
Copy link
Author

No the intention is not really to push it to master. I have had contact with Alasdair regarding this request.
I am not familiar enough with the firmware to ensure that the code will be compatible or even worth pushing to master. I am not sure if I should rather have made a pull request to another branch.
I actually just need help to check if it is implemented correctly. Would it be possible for you to have a look at the code and help me integrate the BMA400?

InterruptLock lock;
bool value = m_irq_pending;
m_irq_pending = false;
DEBUG_TRACE("BMA400LL::check_and_clear_wakeup: pending=%u", (unsigned int)value);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't do debug trace output inside an interrupt lock.

@liamw9534
Copy link
Collaborator

liamw9534 commented Apr 25, 2023 via email

#include "error.hpp"
#include "nrf_irq.hpp"

//Todo: I cannot see the point of this unless there is more than 1 device connected to it.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, seems a bit overkill but harmless I suppose.

Comment on lines 135 to 141
nrfx_twim_xfer_desc_t xfer = NRFX_TWIM_XFER_DESC_TX(device.m_addr, (uint8_t*)buffer, length + sizeof(reg_addr));

err_code = nrfx_twim_xfer(&BSP::I2C_Inits[device.m_bus].twim, &xfer, 0);
//todo: what does this need?
// err_code = nrfx_twim_tx(&BSP::I2C_Inits[device.m_bus].twim, device.m_addr, buffer, length + sizeof(reg_addr), false);
if (err_code != NRFX_SUCCESS)
return BMA400_E_COM_FAIL;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend using the NrfI2C wrapper class. See nrf_i2c.hpp. Not sure why the old driver isn't using it but most i2c stuff is now moved over to the wrapper; example: https://github.com/arribada/CLS-Argos-Linkit-CORE/blob/master/ports/nrf52840/core/hardware/ltr_303/ltr_303.cpp.

It handles the exception throwing directly so you don't need your switch table for error checking. Should save some code.

Having said that, I do note that the existing code uses twim_tx and not twim_xfer although it should make no difference judging by your descriptor.

Comment on lines 151 to 163
nrfx_twim_xfer_desc_t xfer = NRFX_TWIM_XFER_DESC_TXRX(device.m_addr, &reg_addr, sizeof(reg_addr), (uint8_t*)reg_data, length);

err_code = nrfx_twim_xfer(&BSP::I2C_Inits[device.m_bus].twim, &xfer, 0);

// err_code = nrfx_twim_tx(&BSP::I2C_Inits[device.m_bus].twim, device.m_addr, &reg_addr, sizeof(reg_addr), true);
// if (err_code != NRFX_SUCCESS)
// return BMA400_E_COM_FAIL;

// err_code = nrfx_twim_rx(&BSP::I2C_Inits[device.m_bus].twim, device.m_addr, reg_data, length);
if (err_code != NRFX_SUCCESS)
return BMA400_E_COM_FAIL;

return BMA400_OK;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case I would use the NrfI2C::write (with no_stop=true) and NrfI2C::read following the example of the other drivers.

@liamw9534
Copy link
Collaborator

liamw9534 commented Apr 25, 2023 via email

@QuinaGit
Copy link
Author

With this current code I am able to build the firmware and flash it to the Linkit using pylinkit. I am just unable to read the config files (parmr, dumpd,...).

Thank you. I will apply these changes, do some testing and keep you up to date.

@liamw9534
Copy link
Collaborator

liamw9534 commented Apr 25, 2023 via email

@QuinaGit
Copy link
Author

QuinaGit commented May 2, 2023

Oh, I see. Did you try attaching a UART cable to the DBG output pin on the board? Baud rate is 4680800-8-1-N. It might give some clues about what is failing. I'm assuming that you had these commands working before on the previous version of code.

On Tue, 25 Apr 2023 at 12:00, Quintin Strydom @.> wrote: With this current code I am able to build the firmware and flash it to the Linkit using pylinkit. I am just unable to read the config files (parmr, dumpd,...). Thank you. I will apply these changes, do some testing and keep you up to date. — Reply to this email directly, view it on GitHub <#1 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTRST7JBA5M7P36U4GVCULXC6VENANCNFSM6AAAAAAXJZD7XA . You are receiving this because you commented.Message ID: @.>

I was able to read the UART DBG pin, and it seemed to fail with a null pointer error in the BMA400LL::init() function.
So, I saw that I did not define m_bma400_dev.intf_ptr. I defined it and changed some of the code to fit your suggestions and I compiled it and loaded the firmware. Now the code is stuck in the initialise fase and does not continue to run anything. I am not sure what caused it to do so, but that means that I cannot get the Linkit into bluetooth mode to flash new firmware.

Will I be able to flash firmware using DFU mode over USB? Or would you recommend I set up my dev environment to do debugging via the Tag-Connect interface?

@liamw9534
Copy link
Collaborator

liamw9534 commented May 2, 2023 via email

@QuinaGit
Copy link
Author

QuinaGit commented May 2, 2023

Oh, I see. Did you try attaching a UART cable to the DBG output pin on the board? Baud rate is 4680800-8-1-N. It might give some clues about what is failing. I'm assuming that you had these commands working before on the previous version of code.

Oh, and just to note: The debug Baud rate is 460800-8-1-N. I noticed that the documentation also has it like you said (460800), but I found it to not work at that speed.

@liamw9534
Copy link
Collaborator

liamw9534 commented May 2, 2023 via email

@QuinaGit
Copy link
Author

QuinaGit commented May 4, 2023

So, I made a new commit which fixed the null pointer that intf_ptr caused. The code has a bunch of DEBUG_TRACE's that could probably be removed in a later commit, but helped a lot to track which instructions are sent to the sensor.

A problem that I am picking up is that when I connect to the device with bluetooth, I am not able to read config files. It gives the following error:

pylinkit --device EE:4D:40:38:C4:61 --parmr config.txt
2023-05-04 09:13:18,777 client  INFO    Services resolved for BleakClientWinRT (EE:4D:40:38:C4:61)
Traceback (most recent call last):
  File "C:\...\Python\Python39\Scripts\pylinkit-script.py", line 33, in <module>
    sys.exit(load_entry_point('pylinkit==3.3.6', 'console_scripts', 'pylinkit')())
  File "C:\...\Python\Python39\lib\site-packages\pylinkit-3.3.6-py3.9.egg\pylinkit\__main__.py", line 81, in main
  File "C:\...\Python\Python39\lib\site-packages\pylinkit-3.3.6-py3.9.egg\pylinkit\__init__.py", line 23, in sync
  File "C:\...\Python\Python39\lib\site-packages\pylinkit-3.3.6-py3.9.egg\pylinkit\dte.py", line 50, in parmr
  File "C:\...\Python\Python39\lib\site-packages\pylinkit-3.3.6-py3.9.egg\pylinkit\dte.py", line 35, in _decode_response
Exception: PARMR - error 4

Do you know what might cause this?

@liamw9534
Copy link
Collaborator

liamw9534 commented May 4, 2023 via email

@QuinaGit
Copy link
Author

QuinaGit commented May 4, 2023

I tried to see why I am getting the error. So running the v3.3.27 firmware that Philippe sent me, it works perfectly.

I then did a git checkout to the tag v3.3.27 and compiled the code, uploaded it and I got the same error.

Terminal when executing pylinkit --device EE:4D:40:38:C4:61 --debug --parmr config1.txt:

2023-05-04 15:59:07,650 client  DEBUG   Connecting to BLE device @ EE:4D:40:38:C4:61
2023-05-04 15:59:08,784 client  DEBUG   session_status_changed_event_handler: id: <_bleak_winrt_Windows_Devices_Bluetooth.BluetoothDeviceId object at 0x00000122E00E1390>, error: 0, status: 1
2023-05-04 15:59:08,785 client  DEBUG   Get Services...
2023-05-04 15:59:11,988 client  INFO    Services resolved for BleakClientWinRT (EE:4D:40:38:C4:61)
2023-05-04 15:59:12,227 dte_nus DEBUG   PC -> DTE: b'$PARMR#000;\r'
2023-05-04 15:59:13,126 dte_nus DEBUG   PC <- DTE: $N;PARMR#001;4
Traceback (most recent call last):
  File "C:\...\Python39\Scripts\pylinkit-script.py", line 33, in <module>
    sys.exit(load_entry_point('pylinkit==3.3.6', 'console_scripts', 'pylinkit')())
  File "C:\...\Python39\lib\site-packages\pylinkit-3.3.6-py3.9.egg\pylinkit\__main__.py", line 81, in main
  File "C:\...\Python39\lib\site-packages\pylinkit-3.3.6-py3.9.egg\pylinkit\__init__.py", line 23, in sync
  File "C:\...\Python39\lib\site-packages\pylinkit-3.3.6-py3.9.egg\pylinkit\dte.py", line 50, in parmr
  File "C:\...\Python39\lib\site-packages\pylinkit-3.3.6-py3.9.egg\pylinkit\dte.py", line 35, in _decode_response
Exception: PARMR - error 4
2023-05-04 15:59:13,137 client  DEBUG   Disconnecting from BLE device...
2023-05-04 15:59:16,249 client  DEBUG   session_status_changed_event_handler: id: <_bleak_winrt_Windows_Devices_Bluetooth.BluetoothDeviceId object at 0x00000122E00E5470>, error: 0, status: 0

The Debug Trace showed this:

<info> app: Start advertising
<info> app: Connected
01/01/1970 00:00:31 [TRACE] IRQ ConfigurationState::on_ble_event: CONNECTED
01/01/1970 00:00:31 [TRACE] IRQ LEDConfigConnected: entry
<info> app: Data len is set to 0x14(537011264)
01/01/1970 00:00:35 [TRACE] IRQ BleInterface::nus_data_handler: received 12 bytes cumulative 12 (00c).
01/01/1970 00:00:35 [TRACE] IRQ ConfigurationState::on_ble_event: DTE_DATA_RECEIVED
01/01/1970 00:00:35 [TRACE]     received 12 bytes:
$PARMR#000;
01/01/1970 00:00:35 [ERROR]     DTE_PROTOCOL_PAYLOAD_LENGTH_MISMATCH, expected 12 but got 0
01/01/1970 00:00:35 [TRACE]     command = 129 expected_args = 1
01/01/1970 00:00:35 [TRACE]     error_code 4
01/01/1970 00:00:35 [TRACE]     abort error_code 4
01/01/1970 00:00:35 [TRACE]     responding: $N;PARMR#001;4
<info> app: Start advertising
<info> app: Disconnected for reason 0x13
01/01/1970 00:00:39 [TRACE] IRQ ConfigurationState::on_ble_event: DISCONNECTED

This is also the same error that I get when compiling my code for this pull request.

@liamw9534
Copy link
Collaborator

liamw9534 commented May 4, 2023 via email

@liamw9534
Copy link
Collaborator

liamw9534 commented May 4, 2023 via email

@QuinaGit
Copy link
Author

QuinaGit commented May 5, 2023

Which compiler version are you using?

This is the compiler I am using:
gcc-arm-none-eabi 15:9-2019-q4-0ubuntu1 amd64 GCC cross compiler for ARM Cortex-R/M processors

@liamw9534
Copy link
Collaborator

liamw9534 commented May 5, 2023 via email

@QuinaGit
Copy link
Author

QuinaGit commented May 5, 2023

The only difference is that I have cmake version 3.26.3
It looks like there are a few dependencies that are going to make it difficult to downgrade to v3.22.1, but if I need to then I will.

here is the output of arm-none-eabi-gcc -v

Using built-in specs.
COLLECT_GCC=arm-none-eabi-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-none-eabi/9.2.1/lto-wrapper
Target: arm-none-eabi
Configured with: ../configure --build=x86_64-linux-gnu --prefix=/usr --includedir='/usr/lib/include' 
--mandir='/usr/lib/share/man' --infodir='/usr/lib/share/info' --sysconfdir=/etc --localstatedir=/var 
--disable-silent-rules --libdir='/usr/lib/lib/x86_64-linux-gnu' --libexecdir='/usr/lib/lib/x86_64-linux-gnu' 
--disable-maintainer-mode --disable-dependency-tracking --mandir=/usr/share/man --enable-languages=c,c++,lto 
--enable-multilib --disable-decimal-float --disable-libffi --disable-libgomp --disable-libmudflap --disable-libquadmath 
--disable-libssp --disable-libstdcxx-pch --disable-nls --disable-shared --disable-threads --enable-tls 
--build=x86_64-linux-gnu --target=arm-none-eabi --with-system-zlib --with-gnu-as --with-gnu-ld 
--with-pkgversion=15:9-2019-q4-0ubuntu1 --without-included-gettext --prefix=/usr/lib --infodir=/usr/share/doc/gcc-arm-none-eabi/info 
--htmldir=/usr/share/doc/gcc-arm-none-eabi/html --pdfdir=/usr/share/doc/gcc-arm-none-eabi/pdf --bindir=/usr/bin 
--libexecdir=/usr/lib --libdir=/usr/lib --disable-libstdc++-v3 --host=x86_64-linux-gnu --with-headers=no --without-newlib 
--with-multilib-list=rmprofile CFLAGS='-g -O2 -fdebug-prefix-map=/build/gcc-arm-none-eabi-Gl9kT9/gcc-arm-none-eabi-9-2019-q4=. -fstack-protector-strong' CPPFLAGS='-Wdate-time -D_FORTIFY_SOURCE=2' CXXFLAGS='-g -O2 -fdebug-prefix-map=/build/gcc-arm-none-eabi-Gl9kT9/gcc-arm-none-eabi-9-2019-q4=. -fstack-protector-strong' FCFLAGS='-g -O2 -fdebug-prefix-map=/build/gcc-arm-none-eabi-Gl9kT9/gcc-arm-none-eabi-9-2019-q4=. -fstack-protector-strong' FFLAGS='-g -O2 -fdebug-prefix-map=/build/gcc-arm-none-eabi-Gl9kT9/gcc-arm-none-eabi-9-2019-q4=. -fstack-protector-strong' GCJFLAGS='-g -O2 -fdebug-prefix-map=/build/gcc-arm-none-eabi-Gl9kT9/gcc-arm-none-eabi-9-2019-q4=. -fstack-protector-strong' LDFLAGS='-Wl,-Bsymbolic-functions -Wl,-z,relro' OBJCFLAGS='-g -O2 -fdebug-prefix-map=/build/gcc-arm-none-eabi-Gl9kT9/gcc-arm-none-eabi-9-2019-q4=. -fstack-protector-strong' OBJCXXFLAGS='-g -O2 -fdebug-prefix-map=/build/gcc-arm-none-eabi-Gl9kT9/gcc-arm-none-eabi-9-2019-q4=. -fstack-protector-strong' INHIBIT_LIBC_CFLAGS=-DUSE_TM_CLONE_REGISTRY=0 AR_FOR_TARGET=arm-none-eabi-ar AS_FOR_TARGET=arm-none-eabi-as LD_FOR_TARGET=arm-none-eabi-ld NM_FOR_TARGET=arm-none-eabi-nm OBJDUMP_FOR_TARGET=arm-none-eabi-objdump RANLIB_FOR_TARGET=arm-none-eabi-ranlib READELF_FOR_TARGET=arm-none-eabi-readelf STRIP_FOR_TARGET=arm-none-eabi-strip
Thread model: single
gcc version 9.2.1 20191025 (release) [ARM/arm-9-branch revision 277599] (15:9-2019-q4-0ubuntu1) 

@liamw9534
Copy link
Collaborator

liamw9534 commented May 5, 2023 via email

@QuinaGit
Copy link
Author

QuinaGit commented May 5, 2023

I can confirm that I am using the same build steps and I am cleaning out cache.

I don't have the same bleak version, but I did upgrade that.
I don't have winrt or bleak-winrt installed.

I will try to install that and let you know. Also, I am compiling the code on Ubuntu 20.

@liamw9534
Copy link
Collaborator

liamw9534 commented May 5, 2023 via email

int written;

snprintf(format, sizeof(format), "%%%zu", s.size());
snprintf(format, sizeof(format), "%%%u", s.size());
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So an update... this is what ended up being the issue with the ble interface.
The %zu and %zX is for a size_t format specifier and gives unexpected results.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turned out that these lines caused an error 4 - DTE_PROTOCOL_BAD_FORMAT and an error 5 - DTE_PROTOCOL_PAYLOAD_LENGTH_MISMATCH

@liamw9534
Copy link
Collaborator

liamw9534 commented May 11, 2023 via email

Tooww added a commit to Tooww/CLS-Argos-Linkit-CORE that referenced this pull request May 14, 2024
Tooww added a commit to Tooww/CLS-Argos-Linkit-CORE that referenced this pull request May 30, 2024
16.1 debug pgysical was good
Tooww added a commit to Tooww/CLS-Argos-Linkit-CORE that referenced this pull request Jun 3, 2024
Tooww added a commit to Tooww/CLS-Argos-Linkit-CORE that referenced this pull request Jun 7, 2024
Tooww added a commit to Tooww/CLS-Argos-Linkit-CORE that referenced this pull request Jun 13, 2024
Tooww added a commit to Tooww/CLS-Argos-Linkit-CORE that referenced this pull request Jun 14, 2024
Tooww added a commit to Tooww/CLS-Argos-Linkit-CORE that referenced this pull request Jun 18, 2024
NB : for argos msg still unit test pass (compilation test ok)
Tooww added a commit to Tooww/CLS-Argos-Linkit-CORE that referenced this pull request Jun 24, 2024
Tooww added a commit to Tooww/CLS-Argos-Linkit-CORE that referenced this pull request Jun 24, 2024
Tooww added a commit to Tooww/CLS-Argos-Linkit-CORE that referenced this pull request Jul 4, 2024
Tooww added a commit to Tooww/CLS-Argos-Linkit-CORE that referenced this pull request Jul 5, 2024
Tooww added a commit to Tooww/CLS-Argos-Linkit-CORE that referenced this pull request Jul 9, 2024
Tooww added a commit to Tooww/CLS-Argos-Linkit-CORE that referenced this pull request Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants