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

ISO11898 example: No GPIO init? #97

Closed
brainstorm opened this issue Feb 26, 2023 · 26 comments
Closed

ISO11898 example: No GPIO init? #97

brainstorm opened this issue Feb 26, 2023 · 26 comments

Comments

@brainstorm
Copy link

Going through the CAN (ISO11898) example, it seems like the pins init function, board_iso11898_gpio_init(), is commented out in the SDK itself and therefore no pins are assigned anywhere?

@brainstorm
Copy link
Author

brainstorm commented Mar 4, 2023

@gamelaster Following up over here from our Telegram discussion... you meant something like this?:

diff --git a/drivers/lhal/include/bflb_gpio.h b/drivers/lhal/include/bflb_gpio.h
index e4f410d8..1417c4b0 100644
--- a/drivers/lhal/include/bflb_gpio.h
+++ b/drivers/lhal/include/bflb_gpio.h
@@ -123,6 +123,7 @@
 #define GPIO_FUNC_AUDAC_PWM (25 << GPIO_FUNC_SHIFT)
 #define GPIO_FUNC_JTAG      (26 << GPIO_FUNC_SHIFT)
 #define GPIO_FUNC_PEC       (27 << GPIO_FUNC_SHIFT)
+#define GPIO_FUNC_ISO11898  (28 << GPIO_FUNC_SHIFT)
 #define GPIO_FUNC_CLKOUT    (31 << GPIO_FUNC_SHIFT)
 #elif defined(BL606P) || defined(BL808)
 #define GPIO_FUNC_SDH     (0 << GPIO_FUNC_SHIFT)
diff --git a/examples/peripherals/iso11898/iso11898_selftest/main.c b/examples/peripherals/iso11898/iso11898_selftest/main.c
index 7298d861..d2b6318a 100644
--- a/examples/peripherals/iso11898/iso11898_selftest/main.c
+++ b/examples/peripherals/iso11898/iso11898_selftest/main.c
@@ -1,4 +1,5 @@
 #include "bflb_mtimer.h"
+#include "bflb_gpio.h"
 #include "bflb_iso11898.h"
 #include "board.h"
 @@ -6,7 +7,7 @@ struct bflb_device_s *iso11898;
 
 struct bflb_iso11898_config_s cfg = {
     .prescaler = 0,                   /*!< specifies the length of a time quantum, ranges from 1 to 63, tq=tclk*2*(prescaler+1) */
-    .mode = ISO11898_MODE_LOOPBACK,   /*!< specifies the CAN operating mode. @ref ISO11898_MODE_XXX */
+    .mode = ISO11898_MODE_NORMAL,   /*!< specifies the CAN operating mode. @ref ISO11898_MODE_XXX */
     .sample = ISO11898_SAMPLE_TRIPLE, /*!< specifies the number of sample times. @ref ISO11898_SAMPLE_XXX */
     .sjw = ISO11898_SJW_2TQ,          /*!< specifies the maximum number of time quanta the ISO11898 hardware is allowed to lengthen or shorten a bit to perform resynchronization. @ref ISO11898_SJW_XXX */
     .bs1 = ISO11898_BS1_9TQ,          /*!< specifies the number of time quanta in Bit Segment 1. @ref ISO11898_BS1_XXX */
@@ -40,9 +41,11 @@ int main(void)
 {
     int ret = 0;
     board_init();
-    board_iso11898_gpio_init();
+    //board_iso11898_gpio_init();
 
     iso11898 = bflb_device_get_by_name("iso11898");
+    bflb_gpio_init(iso11898, GPIO_PIN_16, GPIO_FUNC_ISO11898 | GPIO_ALTERNATE );
+    bflb_gpio_init(iso11898, GPIO_PIN_17, GPIO_FUNC_ISO11898 | GPIO_ALTERNATE );
 
     bflb_iso11898_init(iso11898, &cfg);
     bflb_iso11898_set_filter(iso11898, &filter);

Can't find in the datasheet where GPIOs can be mapped on the ISO11898 &config struct...

@gamelaster
Copy link
Contributor

@brainstorm this seems to be right.

@brainstorm
Copy link
Author

brainstorm commented Mar 4, 2023

@brainstorm this seems to be right.

No, it's not :/ @gamelaster How do you map those GPIOs, 16 and 17 to the ISO11898 config?

@brainstorm brainstorm changed the title ISO11898 example: Which pins for bl616's M0S Dock? ISO11898 example: No GPIO init? Mar 4, 2023
@brainstorm
Copy link
Author

After looking at the current SDK function state, as mentioned in the first comment:

https://github.com/bouffalolab/bl_mcu_sdk/blob/c75ba0cf8403802a30912e89d2105969b4b73913/bsp/board/bl616dk/board.c#L464-L469

I believe that the CAN (ISO11898 peripheral) has not seen much testing other than selftest (no actual GPIO pins output), am I right, @sakumisue?

@sakumisu
Copy link

sakumisu commented Mar 6, 2023

After looking at the current SDK function state, as mentioned in the first comment:

https://github.com/bouffalolab/bl_mcu_sdk/blob/c75ba0cf8403802a30912e89d2105969b4b73913/bsp/board/bl616dk/board.c#L464-L469

I believe that the CAN (ISO11898 peripheral) has not seen much testing other than selftest (no actual GPIO pins output), am I right, @sakumisue?

No,just not updated.

@sakumisu
Copy link

sakumisu commented Mar 6, 2023

Updated now.

@brainstorm
Copy link
Author

brainstorm commented Mar 6, 2023

I think that you closed this issue a bit too fast? I noticed your changes on those commit lines with unrelated commit message ... please reopen this issue as it's not solved yet 👇🏻 ?

When I plug my oscilloscope to GPIO 14 and GPIO 15 and make the following changes to the example code to trigger a continuous sending of CAN packets:

diff --git a/examples/peripherals/iso11898/iso11898_filter/main.c b/examples/peripherals/iso11898/iso11898_filter/main.c
index 1b3d0ad0..99e92c10 100644
--- a/examples/peripherals/iso11898/iso11898_filter/main.c
+++ b/examples/peripherals/iso11898/iso11898_filter/main.c
@@ -75,9 +75,9 @@ int main(void)
     bflb_iso11898_txint_mask(iso11898, false);
     bflb_iso11898_rxint_mask(iso11898, false);
     bflb_irq_enable(iso11898->irq_num);
-    bflb_iso11898_send(iso11898, &msg_tx, 1000);

     while (1) {
+        bflb_iso11898_send(iso11898, &msg_tx, 1000);
         bflb_mtimer_delay_ms(2000);
     }
 }

The oscilloscope does not register no signals:

IMG_2696

IMG_2697

Can you explain why that would be? Have you tested it yourself at your end after making those changes to the SDK and recompiling/flashing @sakumisu?

Btw, thanks for the making the make flash command work, that's good UX progress! :)

@sakumisue
Copy link
Contributor

image

@sakumisue
Copy link
Contributor

No problem.

@brainstorm
Copy link
Author

Can you hook up a logic analyser on IO14 and IO15 and verify that there's indeed CAN compatible signals in there and not just UART messages?

@sakumisu
Copy link

sakumisu commented Mar 6, 2023

This has already tested before, and i think you should check by yourself, i have no time to help you now.

@sakumisu
Copy link

sakumisu commented Mar 6, 2023

And i see you do not use another can module, it does not work. So no signals is right.

@sakumisue sakumisue reopened this Mar 6, 2023
@brainstorm
Copy link
Author

brainstorm commented Mar 14, 2023

Thanks for re-opening this issue. Even if there's no CAN transceiver attached, there should be signals showing up on the oscilloscope anyway.

@sakumisue
Copy link
Contributor

Thanks for re-opening this issue. Even if there's no CAN transceiver attached, there should be signals showing up on the oscilloscope anyway.

Follow our ic designer, he said.

@brainstorm
Copy link
Author

brainstorm commented Mar 15, 2023

Follow our ic designer, he said.

Excuse me, I cannot understand what you just said: what do you mean?

I've worked successfully with other ICs that support CAN (i.e TWAI on Espressif) and the signals before and after the transceiver IC (i.e TJA1043) can be seen on RXD/TXD as well as CAN_H/CAN_L pins, here's my scope dissecting arbitrary CAN packets on both ends (of a transceiver) attached to an ESP32S2:

IMG_BAE8938D8087-1

Can you show a similar result with your ISO11898 peripheral code? Is the BL616 SDK well tested (aside from UART debug) for this peripheral? Does it output on-spec signals on the pins you recently (a week ago?) defined in the SDK (GPIO_PIN_14 and GPIO_PIN_15)?

@sakumisu
Copy link

Yes, but you need can transceiver. i think this issue is done.

@sakumisu
Copy link

You can use any gpio pin for can tx and rx.

@sakumisu
Copy link

SDK defined is GPIO14 and GPIO15

@brainstorm
Copy link
Author

brainstorm commented Mar 15, 2023

Yes, but you need can transceiver. i think this issue is done.

Nope, you don't.

I've just posted a screenshot of my oscilloscope telling you otherwise, can you please test it on your end without a CAN transceiver attached? It should display the signals shown above in yellow and blue (roughly). The output in pink was either CAN_H/CAN_L transceiver output (cleaner and on-spec for CAN).

@brainstorm
Copy link
Author

brainstorm commented Mar 15, 2023

SDK defined is GPIO14 and GPIO15

My mistake, I meant those and those were the ones I probed on the BL616 test above ☝🏻 , editing the comment where I referred to those pins wrongly......

@sakumisu
Copy link

I have said, if you try without transceiver IC, it has no signals.

@brainstorm
Copy link
Author

brainstorm commented Mar 15, 2023

I have said, if you try without transceiver IC, it has no signals.

I understood fully what you said here and I'm telling you it makes no sense because the latest oscilloscope photo is showing you the opposite... what more evidence do you need?

@sakumisu
Copy link

sakumisu commented Mar 15, 2023

Your test is other ics not ours.

@brainstorm
Copy link
Author

You test is other ics not ours.

Fine, fair enough, I'll attach a transceiver and come back to you with more evidence, I hope I'm wrong :)

@sakumisu
Copy link

And your other ic test with transceiver IC, you can remove them to test.

@sakumisue
Copy link
Contributor

If you use transceiver IC,it will work.
IMG20230315113336

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

No branches or pull requests

4 participants