Problems with XCanPs_CfgInitialize on Zynq 7000

Guest #4739256
Rate this post
• ▲ useful
▼ not useful
Hi everyone,

I'm using a Zynq 7010 (ZynqBerry: 
http://www.trenz-electronic.de/de/produkte/fpga-boards/trenz-electronic/te0726-zynq.html).

I have successfully implemented an AXI-GPIO to blink an led. I want to 
use the CAN peripheral. Here is the problem: everytime I use 
XCanPs_CfgInitialize the software does not work. The build is 
successful, but does work an the Zynq at all. When I use an imported 
example from the Xilinx SDk, there is no problem. I also tried to use 
only XCanPs_LookupConfig and XCanPs_CfgInitialize, but the software 
didn't run on the Zynq as well.

Has anyone experienced the same problem?
Thanks.
1
#define LED_DEVICE_ID  XPAR_GPIO_DEVICE_ID
2
#define LED_CHANNEL   1
3

4
#define CAN_DEVICE_ID  XPAR_PS7_CAN_0_DEVICE_ID
5

6
#define TEST_BTR_SYNCJUMPWIDTH    3
7
#define TEST_BTR_SECOND_TIMESEGMENT  2
8
#define TEST_BTR_FIRST_TIMESEGMENT  15
9

10

11
XGpio  Gpio;
12

13
static  XCanPs  Can0;
14

15
uint32_t  TxFrame[10];
16
uint8_t   *FramePtr;
17
uint8_t    Index;
18

19

20
volatile int i = 0;
21

22
int main()
23
{
24
  int status;
25
  XCanPs *CanInstPtr = &Can0 ;
26
  XCanPs_Config *ConfigPtr;
27

28

29
    init_platform();
30
    xil_printf("Platform Init done\n");
31

32
    // GPIO (Led) Init
33
    status  = XGpio_Initialize(&Gpio, LED_DEVICE_ID);
34
    if (XST_SUCCESS != status) {
35
      xil_printf("XGpio Init (LED) failed\n");
36
      //return XST_FAILURE;
37
    }
38

39
    XGpio_SetDataDirection(&Gpio, LED_CHANNEL, 0x00);
40
    status  = XGpio_SelfTest(&Gpio);
41
    if (XST_SUCCESS != status) {
42
      xil_printf("XGpio Selftest failed\n");
43
      //return XST_FAILURE;
44
    }
45

46
    // CAN0 Init
47
    ConfigPtr  = XCanPs_LookupConfig(CAN_DEVICE_ID);
48
    if (NULL == ConfigPtr) {
49
      xil_printf("CAN0 LookUpConfig failed\n");
50
      //return XST_FAILURE;
51
    }
52
    else {
53
      xil_printf("CAN0 LookUpConfig success\n");
54
      xil_printf("ConfigPtr: %d\n", ConfigPtr);
55
    }
56

57
    status  = XCanPs_CfgInitialize(&Can0, ConfigPtr, ConfigPtr->BaseAddr);
58
    if (status != XST_SUCCESS) {
59
      xil_printf("CAN0 CfgInitialize failed\n");
60
      //return XST_FAILURE;
61
    }
62
    else {
63
      xil_printf("CAN0 CfgInitialize success\n");
64
    }
65

66
    // Selftest
67
    status = XCanPs_SelfTest(&Can0);
68
  if (status != XST_SUCCESS) {
69
    xil_printf("CAN0 SelfTest failed\n");
70
    //return XST_FAILURE;
71
  }
72

73
  //Enter Configuration Mode so we can setup Baud Rate Prescaler
74
  // Register (BRPR) and Bit Timing Register (BTR).
75
  XCanPs_EnterMode(CanInstPtr, XCANPS_MODE_CONFIG);
76
  while(XCANPS_MODE_CONFIG != XCanPs_GetMode(CanInstPtr) );
77

78
  // Setup Baud Rate Prescaler Register (BRPR) and
79
  // Bit Timing Register (BTR).
80
  XCanPs_SetBaudRatePrescaler(CanInstPtr, 199);
81
  XCanPs_SetBitTiming(CanInstPtr, TEST_BTR_SYNCJUMPWIDTH,
82
        TEST_BTR_SECOND_TIMESEGMENT,
83
        TEST_BTR_FIRST_TIMESEGMENT);
84

85
  // Enter Loop Back Mode
86
  XCanPs_EnterMode(CanInstPtr, XCANPS_MODE_NORMAL);
87
  while(XCANPS_MODE_NORMAL != XCanPs_GetMode(CanInstPtr) );
88

89

90
    while(1)
91
    {
92
      print("Hello World 2\n\r");
93
      for (i = 0; i < 10000000; i++) { ; }
94
      XGpio_DiscreteWrite(&Gpio, LED_CHANNEL, 0x00);
95
      for (i = 0; i < 10000000; i++) { ; }
96
      XGpio_DiscreteWrite(&Gpio, LED_CHANNEL, 0x01);
97

98
      TxFrame[0] = (u32)XCanPs_CreateIdValue((uint32_t)1000, 0, 0, 0, 0);
99
      TxFrame[1] = (u32)XCanPs_CreateDlcValue((uint8_t)8);
100

101
      FramePtr = (u8 *)(&TxFrame[2]);
102
    for (Index = 0; Index < 8; Index++) {
103
      *FramePtr++ = (u8)Index;
104
    }
105

106
      status  = XCanPs_Send(&Can0, TxFrame);
107
      if (XST_SUCCESS != status) {
108
        xil_printf("Can0 send failed\n");
109
      }
110
      else {
111
        xil_printf("Can0 send succeeded\n");
112
      }
113
    }
114

115

116
    cleanup_platform();
117
    return 0;
118
}
Guest #4741862
Rate this post
• ▲ useful
▼ not useful
So you have a working example and a broken example, right?
I would use a debugger or printf-debugging to check for differences in 
the CAN and timer registers.

Another point to check:
I didn't study the zynq system in that detail, but I can imagine you 
need a special configuration in the PL-system to get a working CAN 
interface.

Duke

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [vhdl]VHDL-Code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.