ifyall / zephyr-old

Early Access to PSoC 6 integration into Zephyr
Apache License 2.0
1 stars 5 forks source link

Unaligned memory access causing hard fault #2

Open szczys opened 2 years ago

szczys commented 2 years ago

I'm working with the wifi_station sample and a PSOC6 board to connect to the Golioth platform but have encountered a hard fault.

uart:~$ WLAN MAC Address : 74:7A:90:D4:5F:04
WLAN Firmware    : wl0: Jul 18 2021 19:15:39 version 7.45.98.120 (56df937 CY) FWID 01-69db62cf                                      
WLAN CLM         : API: 12.2 Data: 9.10.39 Compiler: 1.29.4 ClmImport: 1.36.3 Creation: 2021-07-18 19:03:20                         
WHD VERSION      : v2.2.0-dirty : v2.2.0 : GCC 10.3 : 2021-12-14 13:57:54 +0000                                                     
*** Booting Zephyr OS build 5fb80e74f153  ***                                                                                       

--------------------------------------------------------------------------------------------------
  #                  SSID                  RSSI   Channel       MAC Address              Security
----------------------------------------------------------------------------------------------------

[00:00:00.638,000] <wrn> net_sock_tls: No entropy device on the system, TLS communication is insecure!
[00:00:00.638,000] <inf> golioth_system: Initializing
[00:00:00.665,000] <err> os: ***** USAGE FAULT *****
[00:00:00.665,000] <err> os:   Unaligned memory access
[00:00:00.665,000] <err> os: r0/a1:  0x08033ce7  r1/a2:  0x000000ff  r2/a3:  0xffffffff
[00:00:00.665,000] <err> os: r3/a4:  0x08033ced r12/ip:  0x10015f15 r14/lr:  0x1001971d
[00:00:00.665,000] <err> os:  xpsr:  0x61000000
[00:00:00.665,000] <err> os: Faulting instruction address (r15/pc): 0x10019722
[00:00:00.666,000] <err> os: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0
[00:00:00.666,000] <err> os: Current thread: 0x8003f48 (main)
[00:00:00.765,000] <err> os: Halting system

To Reproduce Steps to reproduce the behavior:

  1. Add Golioth module to west.yml under projects

        - name: golioth
        path: modules/lib/golioth
        revision: 3086987ed8b4e80dd16312a418dcd1972ef00f5f
        url: https://github.com/golioth/zephyr-sdk.git
        - name: qcbor
        revision: 17b5607b8c49b835d22dec3effa97b25c89267b3
        url: https://github.com/golioth/QCBOR.git
        path: modules/lib/qcbor
  2. west update

  3. Add to the bottom of prj.con in wifi_station sample

        CONFIG_GOLIOTH=y
        CONFIG_GOLIOTH_SYSTEM_CLIENT=y
  4. Build and flash:

    west build -b cy8cproto_062_4343w samples/boards/infineon/wifi_station
    west flash
  5. Unaligned memory access fault happens when scanning for WiFi networks

Expected behavior A list of wifi APs should be displayed

Troubleshooting I asked Marcin on our firmware team about it and he thinks he's found some clue to the cause:

.noinit."WEST_TOPDIR/zephyr/drivers/wifi/infineon_wifi/cyw43xxx_wifi_drv.c".1
                0x000000000802794f     0x4b00 zephyr/drivers/wifi/libdrivers__wifi.a(cyw43xxx_wifi_drv.c.obj)

This is the memory pool that they allocate from. You can notice that it is starting from 0x000000000802794f, which is not aligned to 4 bytes (0xf at the end of address, means 15, which does not divide by 4). Then after allocation they try to reference uint32_t variables. This obviously results in Unaligned memory access that you are seeing.

The net_buf pool defined in:

NET_BUF_POOL_DEFINE(cyw43xxx_pool, 12, 1600, 0, NULL);

is not guaranteed to be 4 bytes aligned, but they seem to assume so.

ifyall commented 2 years ago

@szczys, thanks for the report. Can you let me know what commit you are using as a base?

Thanks,

Ian

szczys commented 2 years ago

Hi Ian, sorry I didn't include this before:

zephyr/samples/boards/infineon/wifi_station $ git rev-parse HEAD
5fb80e74f15336fb256bea81f9e4802558de0188
npal-cy commented 2 years ago

hi @szczys, we fixed this in https://github.com/ifyall/zephyr/commit/d8ef5443f1a02b1f7e20eb07e6cdb298d453ebda also i push PR to Zephyr to fix NET_BUF_POOL_DEFINE https://github.com/zephyrproject-rtos/zephyr/pull/48713

in future update i will revert NET_BUF_POOL_DEFINE (remove NET_BUF_POOL_FIXED_DEFINE_ALIGN ) in cyw43xxx driver once pull/48713 is merge.