Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR Matek M9NF4 GPS Uavcannode Initial Board Support #18621

Closed
wants to merge 5 commits into from

Conversation

dirksavage88
Copy link
Contributor

@dirksavage88 dirksavage88 commented Nov 11, 2021

PR to get the Matek M9NF4 GPS can nodes integrated into uavcannode.

Problem Description:
Integration Matek M9NF4 GPS can nodes and board support
-includes Matek M9NF4 GPS w/ RM3100.

Link vendor page: http://www.mateksys.com/?portfolio=m9n-f4#tab-id-4

Immediate goal is to get a baseline working version merged, then continue iterating on full support

WIP, nodes need testing and integration. Boards includes onboard gps, magnetometer, compass, barometer, and IMU

Additional Info: uavcannode driver based implementation. User friendly bootloader flashing via DFU USB. STM32F405RGT6 similar to omnibus stm32f4 chip.

@dagar
Copy link
Member

dagar commented Nov 11, 2021

Would mateksys_gnss-m9n-f4 be the closest thing to their naming? http://www.mateksys.com/?portfolio=m9n-f4#tab-id-9

@dirksavage88
Copy link
Contributor Author

Would mateksys_gnss-m9n-f4 be the closest thing to their naming? http://www.mateksys.com/?portfolio=m9n-f4#tab-id-9

I changed to matek_gnss-m9n-f4. Having issues with the canbootloader startup, I am not seeing anything on the zubax babel. So no node ID allocation occurs.

@ryanjAA
Copy link
Contributor

ryanjAA commented Nov 30, 2021

How’s this going @dirksavage88 ?

@dirksavage88
Copy link
Contributor Author

How’s this going @dirksavage88 ?

Not great. I'm getting a memory management fault, unexpected isr. Also a debugassert in boot.c, something having to do with the uavcan board identity. I changed the name in the uavcan board identity file to ""org.matek.gnss-m9n-f4"" but this issue persists.

See attached output from STM32CubeProgrammer. I have not found a way to get a debug probe on this board, so I've just been using STM32CubeProgrammer and reading the memory.

debugmatek.txt

@ryanjAA
Copy link
Contributor

ryanjAA commented Nov 30, 2021

Hmm. Maybe @davids5 has an idea about this? Will take a look as well.

@davids5
Copy link
Member

davids5 commented Nov 30, 2021

I would solder the wires on the F4 for SWD/SWCLK and debug it with Jtag.

@ryanjAA
Copy link
Contributor

ryanjAA commented Nov 30, 2021

thanks @davids5 for chiming in - @dirksavage88 there are swd/swc pads on the top routed to pa13 and 14 (they are sort of hidden when the plastic grommet is in place). See the attached pic. that should let you debug pretty quick:
IMG_1212

@dirksavage88
Copy link
Contributor Author

Thanks @ryanjAA I got it soldered to debug. @davids5 I have eclipse ready to go to debug, is it easier just to place breakpoints in timer.c and see where it breaks? Or do I need to create a custom hardfault handler?

@ryanjAA
Copy link
Contributor

ryanjAA commented Dec 3, 2021

@dirksavage88 breakpoints in timer.c although @davids5 would be the definitive word on this.

@davids5
Copy link
Member

davids5 commented Dec 3, 2021

Thanks @ryanjAA I got it soldered to debug. @davids5 I have eclipse ready to go to debug, is it easier just to place breakpoints in timer.c and see where it breaks? Or do I need to create a custom hardfault handler?

Set a breakpoint on arm_hardfault See https://video.ethz.ch/events/2019/px4_developer_summit/9b985acc-5443-4405-8331-2cc0017e9cfc.html ~ 17 min in.

@dirksavage88
Copy link
Contributor Author

Thanks @ryanjAA I got it soldered to debug. @davids5 I have eclipse ready to go to debug, is it easier just to place breakpoints in timer.c and see where it breaks? Or do I need to create a custom hardfault handler?

Set a breakpoint on arm_hardfault See https://video.ethz.ch/events/2019/px4_developer_summit/9b985acc-5443-4405-8331-2cc0017e9cfc.html ~ 17 min in.

I have gotten past the hardfault, I’ll commit my changes and compare the builds (changed board.h to match what is in the ardupilot hw_def). But the bad news is that I am once again stuck on reading the master status register within the ‘can_autobaud’ function. This is the second ardupilot can node board ported over that is not reading the MSR and receiving samples during the canbootloader bit rate detect. Either I’m doing something wrong or these boards aren’t a direct port for the canbootloader to function out of the box (without changing the bootloader stm32 minimal driver code)?

@davids5
Copy link
Member

davids5 commented Dec 4, 2021

Please check the pinout and pin mapping.

@ryanjAA
Copy link
Contributor

ryanjAA commented Dec 5, 2021

@dirksavage88 went to take a look at your pin mapping but saw that it hasn't been updated (or the version in your branch is incomplete). I'll take a look at is as well after you do the pr (assuming you dont have it working).

@dirksavage88
Copy link
Contributor Author

@dirksavage88 went to take a look at your pin mapping but saw that it hasn't been updated (or the version in your branch is incomplete). I'll take a look at is as well after you do the pr (assuming you dont have it working).

Screenshot from 2021-12-05 17-54-09

Still not working, and still having hardfault issues.

@ryanjAA
Copy link
Contributor

ryanjAA commented Dec 6, 2021

Take a look at #18402 It's the same series f4. Additionally, I'd get the pinout and pin mapping sorted first.

@davids5
Copy link
Member

davids5 commented Dec 6, 2021

What are you using for an FMU to test with?

The board docs say

CAN1 PB8/PB9 F103/F303/F405

So that the pin mapping in board.h looks OK and I checked the nuttx mapping for

#define GPIO_CAN1_RX_2 (GPIO_ALT|GPIO_AF9|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN8)
#define GPIO_CAN1_TX_2 (GPIO_ALT|GPIO_AF9|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN9)

You can verify this with an ohm meter. CAN_{RX|TX} to the transceiver and the then the H and L. Check for H to H and L to L on this board to FMU.

image

Also I am assuming you have the CAN of the device connected to CAN1 on the FMU and uavcan is stated with
uavcan start
uavcan fw start

@dirksavage88
Copy link
Contributor Author

@davids5 Im using a zubax Babel to talk to the can node along with uavcan gui tool to set dynamic node id. Right now I get nothing coming from the CAN bus (no node status or anything) but I will try with a dmm to check the transceiver. I can switch CAN connectors on the Babel but it should pick up the node on both. At least it has done this for another node I am working with.

@ryanjAA
Copy link
Contributor

ryanjAA commented Dec 11, 2021

Is this still hard faulting?

@dirksavage88
Copy link
Contributor Author

Is this still hard faulting?

Yes, but i've narrowed it down to an app descriptor signature that is not lining up with application load address? In retrospect I probably should have made this a draft PR. I did get some of SPI, I2C settings to line up with the board mapping, but still having issues with the canbootloader application itself.

@dirksavage88
Copy link
Contributor Author

So as of now, I have a working canbootloader that gets a node ID from the allocation server, and the firmware can be updated. However, the app falls through somewhere. Is this something I can debug in eclipse? I assume the hand off to the application is working correctly, but something in my boardconfig/nuttx config on the application side is incorrect leading the image to fall through.

@ryanjAA
Copy link
Contributor

ryanjAA commented Dec 28, 2021

@dagar is there anything you can see that sticks out on the boardconfig for the f405?

@davids5
Copy link
Member

davids5 commented Dec 28, 2021

@dirksavage88 - there is a merge commit that has messed this up. Please rebase on master and force push.

Then make sure that the Apps' script.ld has this https://github.com/PX4/PX4-Autopilot/blob/master/boards/ark/can-rtk-gps/nuttx-config/scripts/script.ld#L73-L83

break in jump_to_app.

in eclipse' debug console you can use:

symbol-file <full path>/your_apps_default.elf

to then set breakpoints in the application.

Also ensure the watch dog is off until you get it stable. There should be code to disable the WD while in the debugger, but it might not be working on the F407.

Signed-off-by: dirksavage88 <dirksavage88@gmail.com>

Added uavcan board identity

Signed-off-by: dirksavage88 <dirksavage88@gmail.com>

Added usb.c, LED rework may be needed

Signed-off-by: dirksavage88 <dirksavage88@gmail.com>

PX4 dates added to all files

Signed-off-by: dirksavage88 <dirksavage88@gmail.com>

Matek M9NF4 CAN Node initial board support

Signed-off-by: dirksavage88 <dirksavage88@gmail.com>

Changed GPS to ttyS3 in board sensors, led board on/off definitions

Signed-off-by: dirksavage88 <dirksavage88@gmail.com>

Added app descriptor section to canbootloader linker script

Signed-off-by: dirksavage88 <dirksavage88@gmail.com>

Changed board naming convention to match vendor

Signed-off-by: dirksavage88 <dirksavage88@gmail.com>

Changed canbootloader and nsh menuconfig

Signed-off-by: dirksavage88 <dirksavage88@gmail.com>
Signed-off-by: dirksavage88 <dirksavage88@gmail.com>
@dirksavage88
Copy link
Contributor Author

dirksavage88 commented Jan 1, 2022

@dirksavage88 - there is a merge commit that has messed this up. Please rebase on master and force push.

Then make sure that the Apps' script.ld has this https://github.com/PX4/PX4-Autopilot/blob/master/boards/ark/can-rtk-gps/nuttx-config/scripts/script.ld#L73-L83

break in jump_to_app.

in eclipse' debug console you can use:

symbol-file <full path>/your_apps_default.elf

to then set breakpoints in the application.

Also ensure the watch dog is off until you get it stable. There should be code to disable the WD while in the debugger, but it might not be working on the F407.

I rebased to master to get rid of the massive diff. App is now working. Still have to verify GPS + IMU config in PX4, but I see magnetometer and baro messages on the bus so far.

…S & IMU config

Signed-off-by: dirksavage88 <dirksavage88@gmail.com>
@ryanjAA
Copy link
Contributor

ryanjAA commented Jan 1, 2022

How are you currently uploading the firmware? I happen to have one (matek module) with me but no jtag (I'm out of town). Is USB upload working? I can give the PR a try as well.

@dirksavage88
Copy link
Contributor Author

@ryanjAA I set the canbootloader + param storage to 64kb to match what the ardupilot bootloader is set to. However, I am not sure if flashing the px4 app firmware on top of the ardupilot canbootloader is preferable, I think the PX4 one does not brick whereas ardupilot can fail, but I can't verify if this is the case.

I flashed the PX4 canbootloader first using the arm debug pins (and JLinkGDBServer + arm-none-eabi-gdb), but I will try test stm32 cubeprogrammer as that is more user friendly (and uses USB).

After the px4 canbootloader was working, I used uavcan_gui_tool to update firmware, I have not tried to update over the FC yet.

@dirksavage88
Copy link
Contributor Author

@davids5 I think I'm ready for a review on this PR.

I was fighting with the IMU to get working but there isn't much in the Matek Sys docs to go from. Then there is the issue of calibration of the IMU...which may or may not be worth the hassle. @ryanjAA if you need the IMU, I can continue to shoot now that I have the dev console working on the node, if not, I think this can be finalized.

The GPS, mag, and baro seem to be working.

@ryanjAA
Copy link
Contributor

ryanjAA commented Jan 6, 2022

Pretty cool. I think support without the Imu is fine unless @dagar thinks it should be there for completeness.

Did you happen to test if the bootloader can be uploaded via usb? I’m also thinking about a generic user buying one of these and wanting to use it as a node and their setup workflow.

@dirksavage88
Copy link
Contributor Author

@ryanjAA I have not tested flashing the bootloader via usb, but it should be doable using stm32cubeprogrammer and flashing the *.bin file after holding down the dfu button and connecting via usb.

@dagar
Copy link
Member

dagar commented Jan 6, 2022

I'll give this another review.

@ryanjAA
Copy link
Contributor

ryanjAA commented Jan 6, 2022

@dirksavage88 i tried via USB but I wasn’t able to get it to work although i just grabbed the artifacts from the PR. I don’t have access to a jtag until next week but would be good to see if someone else can get this to work via usb.

@dirksavage88
Copy link
Contributor Author

@dirksavage88 i tried via USB but I wasn’t able to get it to work although i just grabbed the artifacts from the PR. I don’t have access to a jtag until next week but would be good to see if someone else can get this to work via usb.

I was able to flash the canbootloader over USB with STM32CubeProgrammer.

@ryanjAA
Copy link
Contributor

ryanjAA commented Jan 7, 2022

Just to confirm, I downloaded the artifact from: https://github.com/PX4/PX4-Autopilot/actions/runs/1661161132 rather then compiling.

Which is px4_package_matek_gnss-m9n-f4:

https://github.com/PX4/PX4-Autopilot/suites/4846264281/artifacts/137910222

then put it in dfu and uploaded the matek_gnss-m9n-f4_canbootloader.bin file via stm32cube but after putting the firmware on from the same artifact I see no can node when hooked up to a pixhawk 4 (hardware is fine checked it ap_prehiph).

I’ll take another more in-depth look but I’m missing something I think.

@dirksavage88
Copy link
Contributor Author

dirksavage88 commented Jan 7, 2022

Just to confirm, I downloaded the artifact from: https://github.com/PX4/PX4-Autopilot/actions/runs/1661161132 rather then compiling.

Which is px4_package_matek_gnss-m9n-f4:

https://github.com/PX4/PX4-Autopilot/suites/4846264281/artifacts/137910222

then put it in dfu and uploaded the matek_gnss-m9n-f4_canbootloader.bin file via stm32cube but after putting the firmware on from the same artifact I see no can node when hooked up to a pixhawk 4 (hardware is fine checked it ap_prehiph).

I’ll take another more in-depth look but I’m missing something I think.

There should be a firmware file xxx-x.x.xxxxxxxx.uavcan.bin, this is what is supposed to go on the flight controller SD card: https://docs.px4.io/master/en/uavcan/node_firmware.html

I believe uavcan has to be set to 'sensors automatic config' on the FC parameters.

EDIT: I can help troubleshoot much better on the discord: https://discord.com/invite/AWrd2XYrjj

@ryanjAA
Copy link
Contributor

ryanjAA commented Jan 7, 2022

Ohhh I was flashing all via stm32programmer. You’re doing it the easier (and correct) way which I stupidly didn’t try. Ya, so bootloader is most definitely in. I’ll redo this tomorrow. On master now you have to subscribe to each sensor but all works with other nodes. Will confirm after testing. 👍

Noted on discord. Will connect there.

@ryanjAA
Copy link
Contributor

ryanjAA commented Jan 7, 2022

Uploads fine...

Running dmesg after looks like mag isn't showing up and baro temp?:

ERROR [uavcan] GetSet error during param count
uavcan_baro adding channel for topic sensor_baro node 122...
uavcan_baro channel 122 instance 1 ok
uavcan_gnss adding channel for topic sensor_gps node 122...
uavcan_gnss node 122 instance 0 ok
uavcan_gnss node 122 topic sensor_gps instance 0 ok
WARN [uavcan] GNSS Fix2 msg detected for ch 0; disabling Fix msg for this node

and uavcan status:

Sensor 'baro':
name: uavcan_baro
channel 0: node id 122 --> instance 1

Sensor 'gnss':
name: uavcan_gnss
channel 0: node id 122 --> instance 0
uavcan: gnss: rtcm pub: 0 events, 0.00us avg, min 0us max 0us 0.000us rms

Sensor 'mag':
name: uavcan_mag

Online nodes (Node ID, Health, Mode):
122 OK OPERAT

listener sensor_baro:
Instance 1:
sensor_baro
timestamp: 510663421 (0.021021 seconds ago)
timestamp_sample: 510663421 (0 us before timestamp)
device_id: 8485379 (Type: 0x81, UAVCAN:0 (0x7A))
error_count: 0
pressure: 989.5113
temperature: -501.9000

@ryanjAA
Copy link
Contributor

ryanjAA commented Jan 8, 2022

@davids5 could there be an issue with something on nuttx here? I’ve been speaking with @dirksavage88 and the pr works for him but not me. With that, I can upload the bootloader and communicate to the device via a direct usb console and even see some Baro data both from a FC and directly but a few things are out of sorts:

  1. Baro data is showing massive negative temp
  2. GPS is started but not getting any sats (if I switch back to ardu and ap_periph it works and gets sats)
  3. Saved uavcan params don’t stay after a reboot
  4. There is no mag data at all or even a compass showing up as an instance. A manual compass start on the correct bus kicks out a no sensor on bus warning.
  5. A ver all doesn’t show that the chip is an f4, just an f???

So the initial conclusion we came to is a change of hardware on the manufacturer side (possible but unlikely, we can check the pins and traces manually this week if need be) or as @dirksavage88 thinks, something on the nuttx side not being configured correctly.

What’s the best thing to do at this point from a hardware standpoint? My binaries more pulled from the Ci artifacts and I put master on the FC from yesterday.

There are some screenshots below.
01C1BE55-BD64-4BDE-8F8A-D338A82C6AC7
9AEA9163-5AA3-4095-8098-3E9F0CC525D1
5EDEFC1D-5F3F-43B6-B0C2-6E7497BA900F
AF570FE6-EC19-4201-A828-4D7E5A1EBA8C
C7FA0EF9-064C-4BFA-BF96-444D3811B218
84F57EDA-4805-4808-835C-2B9731C68836

@davids5
Copy link
Member

davids5 commented Jan 8, 2022

@ryanjAA - did you ever share a bin file from @dirksavage88 build's deploy directory? It would be (nnnn.bin) where nnn is the board ID.

What is the state of the bootloaders on each of your units? This goes the the params getting wiped if they are FLASH based.

If you send me HW I can get this running for you.

@dirksavage88
Copy link
Contributor Author

dirksavage88 commented Jan 8, 2022

@davids5 the issue for the gps seems to be something going on with the GPS driver > PX4/PX4-GPSDrivers#82

@ryanjAA
Copy link
Contributor

ryanjAA commented Jan 8, 2022

@dirksavage88 I just built it from your repo and that has me on nuttx 8.2 so likely building from this pr will get it at nuttx 10 but still some issues as we discussed. seems the Baro temp is correct when viewed from the console on the node but not on the FC side.

@davids5 - yes, he sent me a binary directly from his build but the boot loader was still from the artifact so nuttx version was different). Regarding the boot loader we synced up and tried the same and different ones, no dice which is strange on the GPS side (it's not hardware, checked ardu again for good measure).

Still no mag which seems to be the top two reasons to use this unit but I'm sure it's just something mismatched.

If you message me an address and I'll get one of these sent to you - that would be a big help.

@ryanjAA
Copy link
Contributor

ryanjAA commented Jan 9, 2022

Also re Nuttx, I'm wondering if this: #18356 is occurring since I just pulled down master and built for a Pixhawk 4 and still reporting v 8.2

Signed-off-by: dirksavage88 <dirksavage88@gmail.com>
@davids5
Copy link
Member

davids5 commented Jan 21, 2022

@dirksavage88 , @ryanjAA - I have made progress. There is a NuttX change that gets us a working console. Would you like me to do a continuation PR or push to this PR?

@davids5
Copy link
Member

davids5 commented Jan 22, 2022

@dirksavage88 , @ryanjAA - I have made progress. There is a NuttX change that gets us a working console. Would you like me to do a continuation PR or push to this PR?

@dirksavage88 FYI - first post had a typo in the @

@dirksavage88
Copy link
Contributor Author

@dirksavage88 , @ryanjAA - I have made progress. There is a NuttX change that gets us a working console. Would you like me to do a continuation PR or push to this PR?

I’m okay with a continuation PR.

@davids5
Copy link
Member

davids5 commented Jan 22, 2022

Continued here #19061

@davids5 davids5 closed this Jan 22, 2022
@dirksavage88 dirksavage88 deleted the pr-matek_m9nf4can branch April 9, 2023 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants