bouffalolab / bouffalo_sdk

BouffaloSDK is the IOT and MCU software development kit provided by the Bouffalo Lab Team, supports all the series of Bouffalo chips. Also it is the combination of bl_mcu_sdk and bl_iot_sdk
Apache License 2.0
349 stars 123 forks source link

ISO11898 example: No GPIO init? #97

Closed brainstorm closed 1 year ago

brainstorm commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

@brainstorm this seems to be right.

brainstorm commented 1 year ago

@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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

Updated now.

brainstorm commented 1 year ago

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 commented 1 year ago

image

sakumisue commented 1 year ago

No problem.

brainstorm commented 1 year ago

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 commented 1 year ago

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

sakumisu commented 1 year ago

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

brainstorm commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

sakumisu commented 1 year ago

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

sakumisu commented 1 year ago

SDK defined is GPIO14 and GPIO15

brainstorm commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

brainstorm commented 1 year ago

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 commented 1 year ago

Your test is other ics not ours.

brainstorm commented 1 year ago

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 commented 1 year ago

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

sakumisue commented 1 year ago

If you use transceiver IC,it will work. IMG20230315113336