zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.87k stars 6.62k forks source link

NRF52_ANOMALY_109_WORKAROUND causes "Unhandled interrupt on CPU 0" #63184

Closed marshalblx closed 1 year ago

marshalblx commented 1 year ago

Describe the bug When calling the "pwm_set_pulse_dt" API shortly after an "Unhandled interrupt on CPU 0" is encountered.

Please also mention any information which could help others to understand the problem you're facing:

To Reproduce Steps to reproduce the behavior:

  1. build a project with nrfx_pwm enabled on nrf52832 (CONFIG_PWM=y, CONFIG_PWM_NRFX=y). Here is a fragment from my board's dts file
    
    pwmleds {
        compatible = "pwm-leds";
        pwm_led0_green: pwm_led0 {
            label = "Green LED";
            pwms = <&pwm0 0 PWM_MSEC(20) PWM_POLARITY_NORMAL>;
        };
        pwm_led1_blue: pwm_led1 {
            label = "Blue LED";
            pwms = <&pwm0 1 PWM_MSEC(20) PWM_POLARITY_NORMAL>;
        };
        pwm_led2_red: pwm_led2 {
            label = "Red LED";
            pwms = <&pwm0 2 PWM_MSEC(20) PWM_POLARITY_NORMAL>;
        };
    };
3. In the project call pwm_set_pulse_dt for all three LEDs. I observe the LEDs do turn on. I believe the error is encountered when they're turned off.

static void set_leds(const struct led_color *color, uint32_t brightness) { int ret;

uint32_t red_scale = COLOR_SCALE(color->red, brightness); uint32_t red_pulse = COLOR_SCALE(red_scale, red_pwm_led.period); ret = pwm_set_pulse_dt(&red_pwm_led, red_pulse); if (ret != 0) { LOG_ERR("%d: red write failed", ret); }

uint32_t blue_scale = COLOR_SCALE(color->blue, brightness); uint32_t blue_pulse = COLOR_SCALE(blue_scale, blue_pwm_led.period); ret = pwm_set_pulse_dt(&blue_pwm_led, blue_pulse); if (ret != 0) { LOG_ERR("%d: blue write failed", ret); }

uint32_t green_scale = COLOR_SCALE(color->green, brightness); uint32_t green_pulse = COLOR_SCALE(green_scale, green_pwm_led.period); ret = pwm_set_pulse_dt(&green_pwm_led, green_pulse); if (ret != 0) { LOG_ERR("%d: green write failed", ret); } }

4. build and run project

**Expected behavior**
No fatal error occurs when running PWMs.

**Impact**
For now not much impact. N-selecting the symbol is adequate for my needs, assuming the anomaly 109 isn't encountered in another context.

**Logs and console output**

Booting Zephyr OS build zephyr-v3.4.0 I: Starting bootloader I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3 I: Scratch: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3 I: Boot source: primary slot I: Swap type: none I: Bootloader chainload address offset: 0xc000 I: Jumping to the first image slot

[00:00:00.012,634] bt_hci_core: HW Platform: Nordic Semiconductor (0x0002) [00:00:00.012,695] bt_hci_core: HW Variant: nRF52x (0x0002) [00:00:00.012,725] bt_hci_core: Firmware: Standard Bluetooth controller (0x00) Version 3.4 Build 99 [00:00:00.012,939] bt_hci_core: No ID address. App must call settings_load() [00:00:00.012,939] main: bt_ready: Bluetooth initialized [00:00:00.288,421] bt_hci_core: Identity: D4:DB:DE:27:BA:45 (random) [00:00:00.288,452] bt_hci_core: HCI: version 5.4 (0x0d) revision 0x0000, manufacturer 0x05f1 [00:00:00.288,482] bt_hci_core: LMP: version 5.4 (0x0d) subver 0xffff [00:00:00.288,513] main: bt_ready: Mesh initialized uart:~$ [00:02:24.100,982] button: button_work_handler: new press time 144100 [00:02:24.101,013] button: button_pub: hold time: 1 [00:02:24.101,043] main: button_press_listener: new press [00:02:24.101,165] bt_mesh_prov_device: Device UUID: 2c11f66c-a095-0cf5-0000-000000000000 [00:02:24.102,355] NRFX_PWM: nrfx_pwm_stop returned 1. [00:02:24.102,386] NRFX_PWM: nrfx_pwm_stopped_check returned 1. [00:02:24.102,416] NRFX_PWM: Function: nrfx_pwm_simple_playback, sequence length: 4. [00:02:24.102,447] os: >>> ZEPHYR FATAL ERROR 1: Unhandled interrupt on CPU 0 [00:02:24.102,508] os: Current thread: 0x20002600 (sysworkq) [00:02:24.215,576] os: Halting system uart:~$



**Environment (please complete the following information):**
 - OS: Linux
 - Toolchain: Zephyr SDK v16.3
 - Commit: 73b803ab4b

**Additional context**
github-actions[bot] commented 1 year ago

Hi @marshalblx! We appreciate you submitting your first issue for our open-source project. 🌟

Even though I'm a bot, I can assure you that the whole community is genuinely grateful for your time and effort. 🤖💙

fabiobaltieri commented 1 year ago

cc @JordanYates @carlescufi