hod5b
This commit is contained in:
@@ -70,6 +70,7 @@
|
||||
echo " - Target : $MBED_TARGET"
|
||||
echo " - Compiler : ${armGcc}"
|
||||
echo " - Commands : mbed-tools, pyocd, openocd, st-flash"
|
||||
echo "probe-rs run --chip STM32U575ZITxQ cmake_build/NUCLEO_U575ZI_Q/develop/GCC_ARM/mbed-os-example-blinky.elf"
|
||||
echo
|
||||
'';
|
||||
};
|
||||
|
||||
@@ -1,60 +1,47 @@
|
||||
// main.cpp
|
||||
#include "mbed.h"
|
||||
|
||||
#define MAXIMUM_BUFFER_SIZE 32
|
||||
/*
|
||||
* Copyright (c) 2020 Arm Limited and affiliates.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include "mbed.h"
|
||||
|
||||
DigitalOut led1(LED1);
|
||||
DigitalOut led2(LED2);
|
||||
DigitalOut led3(LED3);
|
||||
DigitalIn button(PC_13);
|
||||
|
||||
Thread thread;
|
||||
#define MAXIMUM_BUFFER_SIZE 32
|
||||
|
||||
volatile bool led_on = false;
|
||||
EventFlags flag;
|
||||
|
||||
static BufferedSerial serial_port(USBTX, USBRX);
|
||||
|
||||
int another_press(int press_num) {
|
||||
press_num += 1;
|
||||
if (press_num >= 8) {
|
||||
press_num = 0;
|
||||
};
|
||||
void led2_thread() {
|
||||
serial_port.set_baud(9600);
|
||||
serial_port.set_format(
|
||||
/* bits */ 8,
|
||||
/* parity */ BufferedSerial::None,
|
||||
/* stop bit */ 1);
|
||||
while (true) {
|
||||
|
||||
return press_num;
|
||||
}
|
||||
if (uint32_t num = serial_port.read(buf, sizeof(buf))) {
|
||||
// Echo the input back to the terminal.
|
||||
serial_port.write(buf, num_presses);
|
||||
}
|
||||
|
||||
void set_led(int number) {
|
||||
led1 = (number & 1) ? 1 : 0;
|
||||
led2 = (number & 2) ? 1 : 0;
|
||||
led3 = (number & 4) ? 1 : 0;
|
||||
thread.start(led2_thread);
|
||||
led2 = !led2;
|
||||
ThisThread::sleep_for(1000);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
serial_port.set_baud(9600);
|
||||
serial_port.set_format(
|
||||
/* bits */ 8,
|
||||
/* parity */ BufferedSerial::None,
|
||||
/* stop bit */ 1
|
||||
);
|
||||
|
||||
char buf[MAXIMUM_BUFFER_SIZE] = {0};
|
||||
|
||||
int num_presses = 0;
|
||||
while (1) {
|
||||
led1 = 0;
|
||||
led2 = 0;
|
||||
led3 = 0;
|
||||
|
||||
if (uint32_t num = serial_port.read(buf, sizeof(buf))) {
|
||||
num_presses = another_press(num_presses);
|
||||
set_led(num_presses);
|
||||
|
||||
// Echo the input back to the terminal.
|
||||
serial_port.write(buf, num);
|
||||
|
||||
while (num == 0) {
|
||||
ThisThread::sleep_for(10ms);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ThisThread::sleep_for(150ms);
|
||||
while (true) {
|
||||
led1 = !led1;
|
||||
ThisThread::sleep_for(500);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user