У меня есть загрузчик (strap.s)
Код: Выделить всё
.global _start
_start:
ldr x0, =0x20000
mov sp, x0
bl notmain
hang:
b hang
.global PUT32
PUT32:
str w1,[x0]
ret
Код: Выделить всё
#include
#include "uart.h"
#include "commands.h"
#define MAX_INPUT_LENGTH 64
void notmain(void) {
char c;
char input_buffer[MAX_INPUT_LENGTH + 1]; // +1 для нуль-термінатора
int input_pos = 0;
uart_puts("UART test...\n");
uart_puts(">>>");
while (1) {
c = uart_getc();
// Виведення кожного зчитаного символу для відладки
uart_puts("Received char: ");
uart_putc(c);
uart_putc('\n');
if (c == '\r' || c == '\n') {
uart_putc('\r');
uart_putc('\n');
input_buffer[input_pos] = '\0'; // Завершення рядка нуль-термінатором
// Діагностика: виведення буфера перед передачею в process_command
uart_puts("Input buffer: ");
uart_puts(input_buffer);
uart_putc('\n');
process_command(input_buffer); // Виклик команди
input_pos = 0; // Скидання буфера
uart_puts(">>>");
} else if (c == '\b' || c == 127) { // Backspace
if (input_pos > 0) {
input_pos--;
uart_puts("\b \b"); // Видалення останнього символу з консолі
}
} else {
if (input_pos < MAX_INPUT_LENGTH) {
input_buffer[input_pos++] = c;
uart_putc(c); // Виведення символу на екран
}
}
}
}
в этом коде у нас есть файлы заголовков: uart.h и Commands.h
Код: Выделить всё
// uart.h
#ifndef UART_H
#define UART_H
#include
void uart_putc(char c);
char uart_getc();
void uart_puts(const char *str);
#endif // UART_H
и у меня также есть файл uart.c
Код: Выделить всё
// uart.c
#include "uart.h"
#define UART0_BASE 0x09000000
#define UART0_DR (*(volatile uint32_t *)(UART0_BASE + 0x00))
#define UART0_FR (*(volatile uint32_t *)(UART0_BASE + 0x18))
void uart_putc(char c){
while(UART0_FR & (1
Подробнее здесь: [url]https://stackoverflow.com/questions/79013632/arm-os-comparing-strings[/url]
Мобильная версия