Topics

STM32 CAN bus driver issues #stm32 #can


josef@...
 

Hi, 

I am trying to get the STM32 CAN bus driver running with the latest revision from git. Unfortunately calling device_get_binding() fails and the reason for that is that the pointer 'driver_api' in the device struct is 0. 

I am now wondering if that's a bug (there were some reworks done in the CAN driver lately) or if I might have an issue in my code. Any ideas?

Thanks, 
Josef


josef@...
 

With some more debugging it looks like the STM32 CAN initialization fails in the STM32 HAL code: At HAL_CAN_Init() the loop waiting for the INAK bit in the CAN_MSR register to be reset when the initialization mode of the CAN controller is left. This works with another program (not using Zephyr) on the same board so I do not expect that my hardware is broken.


Erwan Gouriou
 

Hi Joseph,

Which board are you using? Did you check that CAN driver is available for this board?
Not sure it has been deployed for the whole STM32 family.

Erwan


On Fri, 29 Mar 2019 at 10:34, Josef Raschen <josef@...> wrote:
With some more debugging it looks like the STM32 CAN initialization
fails in the STM32 HAL code: At HAL_CAN_Init() the loop waiting for the
INAK bit in the CAN_MSR register to be reset when the initialization
mode of the CAN controller is left. This works with another program (not
using Zephyr) on the same board so I do not expect that my hardware is
broken.




Lawrence King
 

Hi Josef

 

To me, the problem look more like you didn’t include the CAN bus drivers when you built the kernel. Try running ‘make menuconfig’ and turning on the CAN bus, then rebuilding.

 

Lawrence King

Principal Developer

+1(416)627-7302

 

From: users@... <users@...> On Behalf Of Erwan Gouriou
Sent: Friday, March 29, 2019 11:21 AM
To: Josef Raschen <josef@...>
Cc: users <users@...>
Subject: Re: [Zephyr-users] STM32 CAN bus driver issues #stm32 #can

 

Hi Joseph,

 

Which board are you using? Did you check that CAN driver is available for this board?

Not sure it has been deployed for the whole STM32 family.

 

Erwan

 

On Fri, 29 Mar 2019 at 10:34, Josef Raschen <josef@...> wrote:

With some more debugging it looks like the STM32 CAN initialization
fails in the STM32 HAL code: At HAL_CAN_Init() the loop waiting for the
INAK bit in the CAN_MSR register to be reset when the initialization
mode of the CAN controller is left. This works with another program (not
using Zephyr) on the same board so I do not expect that my hardware is
broken.



Josef Raschen <josef@...>
 

Hi,

the driver is built into the kernel, but what I found out yesterday is, that the pinmuxing is not set up correctly. And the STM32 CAN controller will wait until it has received some bits before it leaves the init mode. So I think, when I fix that, it should work.

Thanks,
Josef

On 30.03.19 04:03, Lawrence King wrote:
To me, the problem look more like you didn’t include the CAN bus drivers when you built the kernel. Try running ‘make menuconfig’ and turning on the CAN bus, then rebuilding.


Josef Raschen <josef@...>
 

Update: CAN bus is working now with my board. I had to move by board config into the Zephyr tree, then pinmuxing seems to work. I still do not know the root cause. My configuration (for CAN) was identical to the one of the STM32F072B Discovery board in the Zephyr tree, but still pinmuxing was not working - at least for pins PB8 and PB9 where my CAN transceiver is connected to. Maybe I missed to set a variable for out-of-tree board definitions, or maybe there is a bug in the build scripts for out-of-tree builds. I thought that setting the BOARD_ROOT variable for CMake should be sufficient. Also the CONFIG_* flags were all set correctly, just my pinmuxing was ignored.

Anyway, I can live with having my board config in the Zephyr tree.

In case anybody is interested, I pushed everything to github: https://github.com/JosefR/zephyr (board name: hvac_sensors)

Thank you for all your help,
Josef

On 30.03.19 12:13, Josef Raschen wrote:
Hi,
the driver is built into the kernel, but what I found out yesterday is, that the pinmuxing is not set up correctly. And the STM32 CAN controller will wait until it has received some bits before it leaves the init mode. So I think, when I fix that, it should work.
Thanks,
Josef
On 30.03.19 04:03, Lawrence King wrote:
To me, the problem look more like you didn’t include the CAN bus drivers when you built the kernel. Try running ‘make menuconfig’ and turning on the CAN bus, then rebuilding.


Rodrigo Peixoto <rodrigopex@...>
 

Josef,

The BOARD_ROOT works for me even with Stm32 boards. The pinmux is mandatory for alternate functions on st boards.

You can run the following commad to set the board root:

west build -b hvac_sensors -s. -- -DBOARD_ROOT=`pwd`

The code is considering your board is in the root directory following the structure boards/arm/hvac_sensors.

Done. Your board will run properly, I hope :)

At the dts, some configuration are applied to variables only and not affect the code at all. You'll need to use those variables on your code. If you want to check the dts generated variables, you can see the build/zephyr/include/generated/...

Good luck.
Best regards,
Rodrigo Peixoto

On Sat, 30 Mar 2019 at 11:37 Josef Raschen <josef@...> wrote:
Update: CAN bus is working now with my board. I had to move by board
config into the Zephyr tree, then pinmuxing seems to work. I still do
not know the root cause. My configuration (for CAN) was identical to the
one of the STM32F072B Discovery board in the Zephyr tree, but still
pinmuxing was not working - at least for pins PB8 and PB9 where my CAN
transceiver is connected to. Maybe I missed to set a variable for
out-of-tree board definitions, or maybe there is a bug in the build
scripts for out-of-tree builds. I thought that setting the BOARD_ROOT
variable for CMake should be sufficient. Also the CONFIG_* flags were
all set correctly, just my pinmuxing was ignored.

Anyway, I can live with having my board config in the Zephyr tree.

In case anybody is interested, I pushed everything to github:
https://github.com/JosefR/zephyr (board name: hvac_sensors)

Thank you for all your help,
Josef


On 30.03.19 12:13, Josef Raschen wrote:
> Hi,
>
> the driver is built into the kernel, but what I found out yesterday is,
> that the pinmuxing is not set up correctly. And the STM32 CAN controller
> will wait until it has received some bits before it leaves the init
> mode. So I think, when I fix that, it should work.
>
> Thanks,
> Josef
>
>
> On 30.03.19 04:03, Lawrence King wrote:
>> To me, the problem look more like you didn’t include the CAN bus
>> drivers when you built the kernel. Try running ‘make menuconfig’ and
>> turning on the CAN bus, then rebuilding.
>
>
>
>
>



--
Rodrigo Peixoto
Co-founder and Technical guru

+55 (82) 98144-8585
http://ayna.tech | Skype: rodrigopex

.


Rodrigo Peixoto <rodrigopex@...>
 

*Root directory = project folder

On Mon, 1 Apr 2019 at 22:27 Rodrigo Peixoto <rodrigopex@...> wrote:
Josef,

The BOARD_ROOT works for me even with Stm32 boards. The pinmux is mandatory for alternate functions on st boards.

You can run the following commad to set the board root:

west build -b hvac_sensors -s. -- -DBOARD_ROOT=`pwd`

The code is considering your board is in the root directory following the structure boards/arm/hvac_sensors.

Done. Your board will run properly, I hope :)

At the dts, some configuration are applied to variables only and not affect the code at all. You'll need to use those variables on your code. If you want to check the dts generated variables, you can see the build/zephyr/include/generated/...

Good luck.
Best regards,
Rodrigo Peixoto
On Sat, 30 Mar 2019 at 11:37 Josef Raschen <josef@...> wrote:
Update: CAN bus is working now with my board. I had to move by board
config into the Zephyr tree, then pinmuxing seems to work. I still do
not know the root cause. My configuration (for CAN) was identical to the
one of the STM32F072B Discovery board in the Zephyr tree, but still
pinmuxing was not working - at least for pins PB8 and PB9 where my CAN
transceiver is connected to. Maybe I missed to set a variable for
out-of-tree board definitions, or maybe there is a bug in the build
scripts for out-of-tree builds. I thought that setting the BOARD_ROOT
variable for CMake should be sufficient. Also the CONFIG_* flags were
all set correctly, just my pinmuxing was ignored.

Anyway, I can live with having my board config in the Zephyr tree.

In case anybody is interested, I pushed everything to github:
https://github.com/JosefR/zephyr (board name: hvac_sensors)

Thank you for all your help,
Josef


On 30.03.19 12:13, Josef Raschen wrote:
> Hi,
>
> the driver is built into the kernel, but what I found out yesterday is,
> that the pinmuxing is not set up correctly. And the STM32 CAN controller
> will wait until it has received some bits before it leaves the init
> mode. So I think, when I fix that, it should work.
>
> Thanks,
> Josef
>
>
> On 30.03.19 04:03, Lawrence King wrote:
>> To me, the problem look more like you didn’t include the CAN bus
>> drivers when you built the kernel. Try running ‘make menuconfig’ and
>> turning on the CAN bus, then rebuilding.
>
>
>
>
>



--
Rodrigo Peixoto
Co-founder and Technical guru

+55 (82) 98144-8585
http://ayna.tech | Skype: rodrigopex

.
--
Rodrigo Peixoto
Co-founder and Technical guru

+55 (82) 98144-8585
http://ayna.tech | Skype: rodrigopex

.