-->
Page 1 of 15

pwm_init creates a platform restart

PostPosted: Fri Aug 21, 2015 8:50 am
by limpkin
Hey everyone,

Using sdk1.3.0, cnlhor's makefile from https://github.com/cnlohr/esp8266ws2812i2s I'm getting a platform restart everytime I call pwm_init.
The code I use is exactly the same one as in the IOT_demo:
Code: Select alluint32 io_info[][3] = {{PWM_0_OUT_IO_MUX,PWM_0_OUT_IO_FUNC,PWM_0_OUT_IO_NUM},{PWM_1_OUT_IO_MUX,PWM_1_OUT_IO_FUNC,PWM_1_OUT_IO_NUM},{PWM_2_OUT_IO_MUX,PWM_2_OUT_IO_FUNC,PWM_2_OUT_IO_NUM}};
   uint32 pwm_duty_init[PWM_CHANNEL] = {0};

   pwm_init(PWM_PER, pwm_duty_init, PWM_CHANNEL, io_info);

   set_pwm_debug_en(0);


Funny thing is that that code works perfectly when embedded in the httpd project.... any ideas?
Thanks!

Re: pwm_init creates a platform restart

PostPosted: Sat Aug 22, 2015 6:36 am
by eriksl
Way too much #defines, totally unclear what it does.

Check in my code in the universal i/o bridge.

Re: pwm_init creates a platform restart

PostPosted: Sun Aug 23, 2015 9:18 am
by limpkin
eriksl wrote:Way too much #defines, totally unclear what it does.

Check in my code in the universal i/o bridge.


I fail to see why the defines would be the cause of the problem when I don't get any warnings during compilation... and when the same code works in another project.

Re: pwm_init creates a platform restart

PostPosted: Sun Aug 23, 2015 10:05 am
by eriksl
limpkin wrote:
eriksl wrote:Way too much #defines, totally unclear what it does.

Check in my code in the universal i/o bridge.


I fail to see why the defines would be the cause of the problem when I don't get any warnings during compilation... and when the same code works in another project.

LOL....

You won't get warnings because:

- the Espressif SDK prototypes are either missing or incomplete so the compiler can't even know what to expect, so you can throw in almost anything you want and the compiler won't complain; that doesn't mean it will work;
- if you didn't enable some extra (useful) warnings, you won't get much warnings anyway (start with -Wall and -Wextra)
- #defines are processed before the compiler sees the code, so anything you put in a #define can't be reasonably checked by the compiler anyway.

Rules of thumb regarding #define

- don't use them, use enum or static const int instead (that's what they're meant for, and they're not transparent to the compiler)
- it's counterproductive and confusing to #define the obvious, like FALSE and TRUE; "false" must be 0 and "true" must be !0, that's a requirement of the C language, you can rely on that. Equally a null pointer is always 0, so either compare to (your data type *)0 or to 0, but NULL is for Pascal quiche -eaters.
- don't use #define's to size an array or other data type; just declare it numeric (like a[100]) and then use sizeof(a) wherever you need the size, it's so much clearer than #define A_LENGTH 100 a[A_LENGTH] for(....; < A_LENGTH), less prone to errors. You may to calculate byte size to a single object size though using something like e.g. sizeof(a) / sizeof(a[0]).

Bottom line: just don't use #define. And if you really must, use a proper understandable identifier, which especially espressif often fails to achieve (e.g.: ICACHE_FLASH_ATTR).