aboutsummaryrefslogtreecommitdiff
path: root/02-usart/src
diff options
context:
space:
mode:
Diffstat (limited to '02-usart/src')
-rw-r--r--02-usart/src/core/clock.c1
-rw-r--r--02-usart/src/core/usart.c10
-rw-r--r--02-usart/src/main.c15
-rw-r--r--02-usart/src/mem.c11
-rw-r--r--02-usart/src/stdlibrepl.c13
5 files changed, 37 insertions, 13 deletions
diff --git a/02-usart/src/core/clock.c b/02-usart/src/core/clock.c
index d779140..f32cb4e 100644
--- a/02-usart/src/core/clock.c
+++ b/02-usart/src/core/clock.c
@@ -103,4 +103,5 @@ int set_system_clock_src(system_clock_src_t src)
{
uint8_t value = RCC.cfg_r & ~0x03;
RCC.cfg_r = value | src;
+ return 0;
}
diff --git a/02-usart/src/core/usart.c b/02-usart/src/core/usart.c
index dc15e57..19d982e 100644
--- a/02-usart/src/core/usart.c
+++ b/02-usart/src/core/usart.c
@@ -5,12 +5,12 @@
void set_usart1_clock_src(__IO rcc_t* rcc, usart_clk_src_t usart_clk_src)
{
- rcc->ccip_r = rcc->ccip_r & (~0x03) | usart_clk_src;
+ rcc->ccip_r = (rcc->ccip_r & (~0x03)) | usart_clk_src;
}
void set_usart2_clock_src(__IO rcc_t* rcc, usart_clk_src_t usart_clk_src)
{
- rcc->ccip_r = rcc->ccip_r & ~(0x03 << 2) | (usart_clk_src << 2);
+ rcc->ccip_r = (rcc->ccip_r & ~(0x03 << 2)) | (usart_clk_src << 2);
}
void set_usart2_clock_enabled(__IO rcc_t* rcc, bool enable)
@@ -41,8 +41,6 @@ void usart_set_parity(__IO usart_t* usart, usart_parity_t parity)
void usart_set_enabled(__IO usart_t* usart, usart_enable_t enabled)
{
- uint32_t c_r1 = usart->c_r1;
-
if (!enabled) {
regset(usart->c_r1, usart_ue, 0);
} else {
@@ -104,6 +102,7 @@ void usart_printf(__IO usart_t* usart, const char* fmt, ...)
va_list l;
union {
void* ptr;
+ char* str;
int i;
} b;
char buf[128];
@@ -130,6 +129,9 @@ void usart_printf(__IO usart_t* usart, const char* fmt, ...)
decimalify(b.i, buf);
usart_transmit_str_sync(usart, buf);
break;
+ case 's':
+ b.str = va_arg(l, char*);
+ usart_transmit_str_sync(usart, b.str);
}
++ fmt;
} else {
diff --git a/02-usart/src/main.c b/02-usart/src/main.c
index d26dce4..b050d3e 100644
--- a/02-usart/src/main.c
+++ b/02-usart/src/main.c
@@ -81,9 +81,18 @@ int main()
for (;;);
}
- const char* thing = "HELLO DMA!\r\n";
- regset(USART2.ic_r, usart_tccf, 1);
- dma_mem2p_initiate_transfer(dma_chan, thing, strlen(thing));
+ // const char* thing = "Good Thing This Works!";
+
+ char* str = halloc(128);
+ strcpy(str, "Hello, Heap!");
+
+ usart_printf(&USART2, "DATA_SEGMENT_START %p\n", &DATA_SEGMENT_START);
+ usart_printf(&USART2, "DATA_SEGMENT_STOP: %p\n", &DATA_SEGMENT_STOP);
+ usart_printf(&USART2, "str at: %p\n", str);
+ usart_printf(&USART2, "str: %s\n", str);
+ // usart_printf(&USART2, "%s\n", thing);
+ // regset(USART2.ic_r, usart_tccf, 1);
+ // dma_mem2p_initiate_transfer(dma_chan, thing, strlen(thing));
__IO gpio_port_t* port_b = enable_gpio(GPIO_PORT_B);
gpio_output_pin_t pin3 = set_gpio_pin_output(port_b, PIN_3);
diff --git a/02-usart/src/mem.c b/02-usart/src/mem.c
index 0cb9ee4..02d59de 100644
--- a/02-usart/src/mem.c
+++ b/02-usart/src/mem.c
@@ -62,7 +62,7 @@ halloc_node_t* halloc_start;
void* halloc(size_t size)
{
if (!halloc_start) {
- halloc_start = (halloc_node_t*) DATA_SEGMENT_STOP;
+ halloc_start = (halloc_node_t*) DATA_SEGMENT_STOP_ADDR;
memset(halloc_start, 0, sizeof(halloc_node_t));
halloc_start->size = (MAX_HEAP_SIZE / 4) - 1;
}
@@ -161,20 +161,19 @@ int debug_halloc_assert_consistency(char* error, size_t len)
{
halloc_node_t* cur = halloc_node_at_off(0);
size_t total_size = 0;
- size_t offset = 0;
size_t loop_check = 0;
while(1) {
total_size += cur->size + 1;
halloc_node_t* next = halloc_node_next(cur);
- if (next == DATA_SEGMENT_STOP + MAX_HEAP_SIZE) {
+ if ((uint8_t*) next == ((uint8_t*)&DATA_SEGMENT_STOP) + MAX_HEAP_SIZE) {
break;
- } else if (next > (void*)(DATA_SEGMENT_STOP + MAX_HEAP_SIZE)){
+ } else if ((uint8_t*) next > (uint8_t*)DATA_SEGMENT_STOP_ADDR + MAX_HEAP_SIZE){
snprintf(
error, len, "Next node points is out of bounds. %p vs max of %p\n",
next,
- (void*)(DATA_SEGMENT_STOP + MAX_HEAP_SIZE));
+ (void*)(DATA_SEGMENT_STOP_ADDR + MAX_HEAP_SIZE));
return 1;
}
cur = next;
@@ -182,7 +181,7 @@ int debug_halloc_assert_consistency(char* error, size_t len)
if (total_size * 4 != MAX_HEAP_SIZE) {
snprintf(
- error, len, "Total recorded size is inconsistent. %d vs %d\n",
+ error, len, "Total recorded size is inconsistent. %lu vs %lu\n",
total_size * 4, MAX_HEAP_SIZE);
return 1;
}
diff --git a/02-usart/src/stdlibrepl.c b/02-usart/src/stdlibrepl.c
new file mode 100644
index 0000000..2d9d839
--- /dev/null
+++ b/02-usart/src/stdlibrepl.c
@@ -0,0 +1,13 @@
+/*
+ * Replacement for common stdlib functions that don't exist
+ * on the ARM bare-metal compilation environment.
+ */
+
+#include <stddef.h>
+
+size_t strlen(char* ch)
+{
+ size_t ret = 0;
+ while(*(ch ++) != 0) ++ ret;
+ return ret;
+}