2024-09-22 08:56 AM
Hello,
I am trying to see if I can enable the J1939 protocols on the stm32 mp158d-dk1 board. I used the menuconfig to update the setting.
After doing that I updated the uimage, dtb, and modules to the stm32 mp1 device.
root@stm32mp1:/# dmesg | grep -i can
[ 0.256925] CAN device driver interface
[ 0.322146] can: controller area network core
[ 0.322257] NET: Registered PF_CAN protocol family
[ 0.322272] can: raw protocol
[ 0.322285] can: broadcast manager protocol
[ 0.322300] can: netlink gateway - max_hops=1
[ 0.322537] can: SAE J1939
[ 2.012003] m_can_platform 4400e000.can: m_can device registered (irq=50, version=32)
[ 2.411352] remoteproc remoteproc0: cannot get detach mbox
[ 369.920763] IPv6: ADDRCONF(NETDEV_CHANGE): can0: link becomes ready
I can see that SAE J 1939 protocol is active. I used the following headers to read from the linux user land.
#include<linux/can/j1939.h> // I got no errors with the header file.
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <linux/can.h>
#include <linux/can/j1939.h>
#define MAX_CAN_DLC 8
int main() {
int sock;
int ret;
struct sockaddr_can sockname;
struct sockaddr_can peername;
socklen_t peernamelen;
struct ifreq ifr;
uint8_t dat[128]; // Buffer to hold the received data
int value = 1; // Enable promiscuous mode
// Open a socket for J1939 protocol
sock = socket(AF_CAN, SOCK_DGRAM, CAN_J1939);
if (sock < 0) {
perror("Socket creation failed");
return 1;
}
// Specify the CAN interface (e.g., "can0")
strcpy(ifr.ifr_name, "can0");
ret = ioctl(sock, SIOCGIFINDEX, &ifr);
if (ret < 0) {
perror("ioctl failed");
close(sock);
return 1;
}
printf("CAN interface index: %d\n", ifr.ifr_ifindex);
I was wondering if anyone has success with j1939 protocol. I tried doing it, but I don't see any decoded frames in the user land.
Did anyone have success with J1939? If not I am planning to just use the regular CAN for my application.
Thanks