This the third part of the Zephyr RTOS demo in the Microchip PIC32CM PL10-CNANO evaluation board
The first Zephyr RTOS demo is the blinky demo and it used the following source code,
/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdio.h>
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>
/* 1000 msec = 1 sec */
#define SLEEP_TIME_MS 1000
/* The devicetree node identifier for the "led0" alias. */
#define LED0_NODE DT_ALIAS(led0)
/*
* A build error on this line means your board is unsupported.
* See the sample documentation for information on how to fix this.
*/
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
int main(void)
{
int ret;
bool led_state = true;
if (!gpio_is_ready_dt(&led)) {
return 0;
}
ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
if (ret < 0) {
return 0;
}
while (1) {
ret = gpio_pin_toggle_dt(&led);
if (ret < 0) {
return 0;
}
led_state = !led_state;
printf("LED state: %s\n", led_state ? "ON" : "OFF");
k_msleep(SLEEP_TIME_MS);
}
return 0;
}
This Zephyr RTOS program will blink the LED once per second. To build this source code please proceed as follows,
zephyrproject/zephyr$ west build -p always -b pic32cm_pl10_cnano samples/basic/blinky
...
...
[137/137] Linking C executable zephyr/zephyr.elf
Memory region Used Size Region Size %age Used
FLASH: 12068 B 60 KB 19.64%
RAM: 3864 B 8 KB 47.17%
IDT_LIST: 0 B 32 KB 0.00%
At this point we have successfully built the Zephyr RTOS blinky application that is ready to be downloaded to the target evaluation board. In our next article we will be downloading the Zephyr RTOS demo in the Microchip PIC32CM PL10-CNANO evaluation board. The Microchip PIC32CM PL10-CNANO evaluation board is low cost and powerful development board and is available at DigiKey.
Have a great day!
This article is available in spanish here.
Este artículo está disponible en español aquí.
