Blinky Example
The Blinky example is the simplest ALP SDK project. It toggles the on-board LED at a fixed interval, verifying that your toolchain, SDK installation, and hardware connection are working correctly.
Source Code
/**
* Blinky Example - ALP SDK
*
* Toggles the on-board LED every 500 ms using the GPIO driver.
*/
#include "alp_gpio.h"
#include "alp_board.h"
/* Board-specific LED pin definition (from BSP) */
/* TODO: Confirm LED pin macro name per board */
#define LED_PIN BOARD_LED_PIN
#define LED_PORT BOARD_LED_PORT
static ALP_GPIO_Driver_t *gpio;
/* Simple busy-wait delay */
static void delay_ms(uint32_t ms)
{
/* TODO: Replace with a timer-based delay or RTOS sleep in production */
volatile uint32_t count;
for (uint32_t i = 0; i < ms; i++) {
for (count = 0; count < 8000; count++) {
__asm volatile("nop");
}
}
}
int main(void)
{
/* Initialize the board (clocks, pin mux) */
ALP_Board_Init();
/* Get GPIO driver and initialize */
gpio = ALP_GPIO_GetDriver(LED_PORT);
gpio->Initialize(NULL);
gpio->PowerControl(ALP_POWER_FULL);
/* Configure LED pin as push-pull output */
gpio->SetDirection(LED_PIN, ALP_GPIO_DIR_OUTPUT);
gpio->SetOutputMode(LED_PIN, ALP_GPIO_OUTPUT_PUSH_PULL);
gpio->SetValue(LED_PIN, 0);
while (1) {
gpio->ToggleValue(LED_PIN);
delay_ms(500);
}
return 0;
}
FreeRTOS Variant
When using FreeRTOS, replace the busy-wait loop with vTaskDelay:
#include "FreeRTOS.h"
#include "task.h"
#include "alp_gpio.h"
#include "alp_board.h"
#define LED_PIN BOARD_LED_PIN
#define LED_PORT BOARD_LED_PORT
static ALP_GPIO_Driver_t *gpio;
void blinky_task(void *params)
{
(void)params;
gpio = ALP_GPIO_GetDriver(LED_PORT);
gpio->Initialize(NULL);
gpio->PowerControl(ALP_POWER_FULL);
gpio->SetDirection(LED_PIN, ALP_GPIO_DIR_OUTPUT);
gpio->SetOutputMode(LED_PIN, ALP_GPIO_OUTPUT_PUSH_PULL);
for (;;) {
gpio->ToggleValue(LED_PIN);
vTaskDelay(pdMS_TO_TICKS(500));
}
}
int main(void)
{
ALP_Board_Init();
xTaskCreate(blinky_task, "blinky", 256, NULL, 1, NULL);
vTaskStartScheduler();
/* Should never reach here */
for (;;);
}
Building
mkdir build && cd build
cmake -DBOARD=e1m_x_v2n -DEXAMPLE=blinky ..
cmake --build . --parallel
Expected Behavior
- The on-board LED toggles every 500 ms
- Serial console output (if UART is initialized by the BSP):
[ALP SDK] Blinky example started
Next Steps
- Modify the delay interval to experiment with different blink rates
- Add a second LED or toggle a GPIO pin connected to an oscilloscope
- Move on to the Sensor Reading example