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.93k stars 6.65k forks source link

Trying to run stm32f0_disco with blinky_pwm #79519

Open adri1mart1 opened 1 month ago

adri1mart1 commented 1 month ago

Hello zephyr community,

Describe the bug

I am using zephyr 3.7.0. I have tried to run the blinky_pwm example on the stm32f0_disco board. The overlay file does not exist (even on master branch) yet so i have created this one along with other overlay files:

To Reproduce

Add an stm32f0_disco.overlay in the zephyr\samples\basic\blinky_pwm\boards\ directory with the following content.

/ {
    pwmleds: pwmleds {
        compatible = "pwm-leds";
        status = "okay";
        green_pwm_led: green_pwm_led {
            pwms = <&pwm 1 PWM_MSEC(20) PWM_POLARITY_NORMAL>;
        };
    };

    aliases {
        pwm-led0 = &green_pwm_led;
    };
};

&timers1 {
    status = "okay";
    pwm: pwm {
        compatible = "st,stm32-pwm";
        status = "okay";
        #pwm-cells = < 0x3 >;
        pinctrl-0 = <&tim1_ch1_pa8>;
        pinctrl-names = "default";
    };
};

Note: green_pwm_led label is only a copy paste from another board, not very relevant probably but I did not check the schematic in details of the stm32f0_disco board. My goal here was just to have PA8 pin running a PWM signal.

In the blinky_pwm main.c, I've just modified the following two lines to be compatible with my hardware and my needs:

#define MIN_PERIOD PWM_SEC(1U) / 16384U
#define MAX_PERIOD PWM_SEC(1U) / 1024U

Compiling and flashing:

west build -b stm32f0_disco .\zephyr\samples\basic\blinky_pwm\
west flash
*** Booting Zephyr OS build v3.7.0 ***
PWM-based blinky
Calibrating for channel 1...
Done calibrating; maximum/minimum periods 976562/61035 nsec
Using period 976562
[00:00:00.014,000] <err> os: ***** HARD FAULT *****

If I set the CONFIG_LOG_MODE_IMMEDIATE=n in the prj.conf, now things are working:

Expected behavior

*** Booting Zephyr OS build v3.7.0 ***
PWM-based blinky
Calibrating for channel 1...
Done calibrating; maximum/minimum periods 976562/61035 nsec
Using period 976562
Using period 488281
Using period 244140
[...]

And I have a valid PWM output on PA8.

Any idea on what's wrong with my try or is there something hidden ?

Environment

FRASTM commented 1 month ago

looking for a stm32f0_disco available but maybe one of my stm32f072b_disco can be similar. In the board DTS, the tim1_ch1_pa8 is correctly set as output pwm pin of the timer1 channel1 but the green_pwm_led is on pin PC9. I tested on nucleo_f091 whit the overlay above. for enabling timers1 and pwm channel1 on PA8 even if no led is blinking (no led on PA8) the sample is running

*** Booting Zephyr OS build v3.7.0-465-g26a4912e048a ***                        
PWM-based blinky                                                                
Calibrating for channel 1...                                                    
Done calibrating; maximum/minimum periods 976562/61035 nsec                     
Using period 976562                                                             
Using period 488281                                                             
Using period 244140                                                             
Using period 122070                                                             
Using period 61035     

(SHA1 318b49570a77ce631dc3d97ad7e7a05df5459d8e)