参考链接:yq.aliyun.com/articles/61…
代码
修改hello world.c
选择helloworld@stm32l476rg-nucleo,修该helloworld.c
#include <stdio.h>
#include <aos/kernel.h>
#include <aos/hal/gpio.h>
gpio_dev_t LED1;
static void LED1_Off(void *arg);
static void LED1_On(void *arg)
{
hal_gpio_output_high(&LED1);
aos_post_delayed_action(100, LED1_Off, NULL);
}
static void LED1_Off(void *arg)
{
hal_gpio_output_low(&LED1);
aos_post_delayed_action(100, LED1_On, NULL);
}
int application_start(int argc, char *argv[])
{
LED1.port = 18;
LED1.config = OUTPUT_PUSH_PULL;
hal_gpio_init(&LED1);
aos_post_delayed_action(1000, LED1_On, NULL);
aos_loop_run();
// while(1) {
// printf("hello world! count %d \r\n", count++);
// aos_msleep(1000);
// };
}
编译下载,可以看到红色灯亮
修改hal_gpio_stm32l4.h
添加
#define HAL_GPIO_48 ((uint8_t)48) /* represent GPIOD pin 0 */
#define HAL_GPIO_49 ((uint8_t)49) /* represent GPIOD pin 1 */
#define HAL_GPIO_50 ((uint8_t)50) /* represent GPIOD pin 2 */
#define HAL_GPIO_51 ((uint8_t)51) /* represent GPIOD pin 3 */
#define HAL_GPIO_52 ((uint8_t)52) /* represent GPIOD pin 4 */
#define HAL_GPIO_53 ((uint8_t)53) /* represent GPIOD pin 5 */
#define HAL_GPIO_54 ((uint8_t)54) /* represent GPIOD pin 6 */
#define HAL_GPIO_55 ((uint8_t)55) /* represent GPIOD pin 7 */
#define HAL_GPIO_56 ((uint8_t)56) /* represent GPIOD pin 8 */
#define HAL_GPIO_57 ((uint8_t)57) /* represent GPIOD pin 9 */
#define HAL_GPIO_58 ((uint8_t)58) /* represent GPIOD pin 10 */
#define HAL_GPIO_59 ((uint8_t)59) /* represent GPIOD pin 11 */
#define HAL_GPIO_60 ((uint8_t)60) /* represent GPIOD pin 12 */
#define HAL_GPIO_61 ((uint8_t)61) /* represent GPIOD pin 13 */
#define HAL_GPIO_62 ((uint8_t)62) /* represent GPIOD pin 14 */
#define HAL_GPIO_63 ((uint8_t)63) /* represent GPIOD pin 15 */
#define HAL_GPIO_64 ((uint8_t)64) /* represent GPIOE pin 0 */
#define HAL_GPIO_65 ((uint8_t)65) /* represent GPIOE pin 1 */
#define HAL_GPIO_66 ((uint8_t)66) /* represent GPIOE pin 2 */
#define HAL_GPIO_67 ((uint8_t)67) /* represent GPIOE pin 3 */
#define HAL_GPIO_68 ((uint8_t)68) /* represent GPIOE pin 4 */
#define HAL_GPIO_69 ((uint8_t)69) /* represent GPIOE pin 5 */
#define HAL_GPIO_70 ((uint8_t)70) /* represent GPIOE pin 6 */
#define HAL_GPIO_71 ((uint8_t)71) /* represent GPIOE pin 7 */
#define HAL_GPIO_72 ((uint8_t)72) /* represent GPIOE pin 8 */
#define HAL_GPIO_73 ((uint8_t)73) /* represent GPIOE pin 9 */
#define HAL_GPIO_74 ((uint8_t)74) /* represent GPIOE pin 10 */
#define HAL_GPIO_75 ((uint8_t)75) /* represent GPIOE pin 11 */
#define HAL_GPIO_76 ((uint8_t)76) /* represent GPIOE pin 12 */
#define HAL_GPIO_77 ((uint8_t)77) /* represent GPIOE pin 13 */
#define HAL_GPIO_78 ((uint8_t)78) /* represent GPIOE pin 14 */
#define HAL_GPIO_79 ((uint8_t)79) /* represent GPIOE pin 15 */
然后把LED port改为72,绿色灯亮