arm: working bootloader, example app
'make' will produce two outputs: - bootloader.elf to be loaded into the bitstream - app.bin to be loaded through the programmer Loading app.bin is as simple as: - reset the board - `python3 prog.py app.bin`
This commit is contained in:
53
arm/main.cc
53
arm/main.cc
@@ -1,30 +1,12 @@
|
||||
#include <cstdint>
|
||||
|
||||
#include "xuartlite.h"
|
||||
|
||||
struct Gpio {
|
||||
volatile uint32_t data;
|
||||
};
|
||||
|
||||
#define gpio0 ((Gpio*) 0x40000000)
|
||||
#include "gpio.h"
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr uintptr_t kUart0BaseAddress = 0x40001000;
|
||||
XUartLite uart0;
|
||||
XUartLite_Config uart0_config = {
|
||||
.DeviceId = 0,
|
||||
.RegBaseAddr = kUart0BaseAddress,
|
||||
.BaudRate = 115200,
|
||||
.UseParity = false,
|
||||
.DataBits = 8,
|
||||
};
|
||||
|
||||
[[maybe_unused]]
|
||||
void sleep(int ms) {
|
||||
for (int i = 0; i < ms; i++) {
|
||||
// sleep for 1 ms
|
||||
for (int j = 0; j < 50000; j++) {
|
||||
for (int j = 0; j < 22000; j++) {
|
||||
asm("");
|
||||
}
|
||||
}
|
||||
@@ -32,24 +14,19 @@ void sleep(int ms) {
|
||||
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
int recv = 0;
|
||||
gpio0->data = 37;
|
||||
extern "C" int main() {
|
||||
uint8_t cnt = 0;
|
||||
|
||||
XUartLite_CfgInitialize(&uart0, &uart0_config, uart0_config.RegBaseAddr);
|
||||
for (int i = 0; i < 256; i++) {
|
||||
gpio0->data = cnt;
|
||||
cnt++;
|
||||
|
||||
while (true) {
|
||||
uint8_t c;
|
||||
int received_bytes = XUartLite_Recv(&uart0, &c, 1);
|
||||
if (received_bytes < 1) {
|
||||
continue;
|
||||
}
|
||||
recv++;
|
||||
gpio0->data = recv & 0xff;
|
||||
XUartLite_Send(&uart0, &c, 1);
|
||||
if (c == '\r') {
|
||||
c = '\n';
|
||||
XUartLite_Send(&uart0, &c, 1);
|
||||
}
|
||||
sleep(125);
|
||||
}
|
||||
}
|
||||
|
||||
auto* airc = reinterpret_cast<volatile uint32_t*>(0xe000ed0c);
|
||||
uint32_t a = *airc;
|
||||
*airc = a | 0x04;
|
||||
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user