FreeRTOS w/blink works

This commit is contained in:
cpq 2021-05-11 20:44:14 +01:00
parent c44549bfa5
commit 151e375091
5 changed files with 46 additions and 33 deletions

View File

@ -13,8 +13,8 @@ INCS = -I$(ARCH) -I. -I../.. -Ifreertos-kernel/include -Ifreertos-tcp/include -I
CFLAGS = -W -Wall -Os -g $(MCU) -fdata-sections -ffunction-sections $(INCS) $(MONGOOSE_OPTS) $(EXTRA)
LDFLAGS = $(MCU) -specs=nano.specs -Tobj/link.ld -nostartfiles -nostdlib -lc -lm -lnosys -lgcc #-Wl,-Map=obj/$(PROG).map,--cref -Wl,--gc-sections
SRCS = main.c # $(wildcard freertos-tcp/*.c)
# SRCS += freertos-kernel/portable/MemMang/heap_4.c $(ARCH)/port.c
# SRCS += freertos-kernel/list.c freertos-kernel/tasks.c freertos-kernel/queue.c
SRCS += freertos-kernel/portable/MemMang/heap_4.c $(ARCH)/port.c
SRCS += freertos-kernel/list.c freertos-kernel/tasks.c freertos-kernel/queue.c
OBJS = obj/boot.o $(SRCS:%.c=obj/%.o) #obj/mongoose.o # ORDER MATTERS - boot (vector table) first!
all: $(PROG).hex
@ -43,7 +43,7 @@ obj/mongoose.o:
$(DOCKER) arm-none-eabi-gcc $(CFLAGS) -c ../../mongoose.c -o $@
flash: $(PROG).bin
st-flash write $< 0x8000000
st-flash --reset write $< 0x8000000
gdb: $(PROG).elf
arm-none-eabi-gdb \
@ -51,8 +51,6 @@ gdb: $(PROG).elf
-ex 'target extended-remote :4242' \
-ex 'monitor reset halt' \
-ex 'monitor reset init' \
-ex 'b main' \
-ex 'r' \
$<
clean:

View File

@ -33,8 +33,7 @@ static void fn(void *args) {
// int delay_ms = *(int *) args;
for (;;) {
led_toggle();
spin(500000);
// vTaskDelay(pdMS_TO_TICKS(0));
vTaskDelay(pdMS_TO_TICKS(300));
};
(void) args;
}
@ -42,8 +41,7 @@ static void fn(void *args) {
int main(void) {
init_ram();
init_hardware();
fn(NULL);
// xTaskCreate(fn, "server", 512, NULL, configMAX_PRIORITIES - 1, NULL);
// vTaskStartScheduler();
return 0;
xTaskCreate(fn, "server", 512, NULL, configMAX_PRIORITIES - 1, NULL);
vTaskStartScheduler(); // This blocks
return 0; // Unreachable
}

View File

@ -1,29 +1,33 @@
.cpu cortex-m3
.thumb
.word _estack /* stack top address */
.word _reset /* 1 Reset */
.word spin /* 2 NMI */
.word spin /* 3 Hard Fault */
.word spin /* 4 MM Fault */
.word spin /* 5 Bus Fault */
.word spin /* 6 Usage Fault */
.word spin /* 7 RESERVED */
.word spin /* 8 RESERVED */
.word spin /* 9 RESERVED*/
.word spin /* 10 RESERVED */
.word spin /* 11 SV call */
.word spin /* 12 Debug reserved */
.word spin /* 13 RESERVED */
.word spin /* 14 PendSV */
.word spin /* 15 SysTick */
.word spin /* 16 IRQ0 */
.word spin /* 17 IRQ1 */
.word spin /* 18 IRQ2 */
.word spin /* 19 ... */
/* On to IRQ67 */
.word _estack // 0 Stack top address
.word _reset // 1 Reset
.word pass // 2 NMI
.word halt // 3 Hard Fault
.word halt // 4 MM Fault
.word halt // 5 Bus Fault
.word halt // 6 Usage Fault
.word halt // 7 RESERVED
.word halt // 8 RESERVED
.word halt // 9 RESERVED
.word halt // 10 RESERVED
.word SVC_handler // 11 SV call
.word halt // 12 Debug reserved
.word halt // 13 RESERVED
.word pending_SV_handler // 14 PendSV
.word SysTick_handler // 15 SysTick
.word pass // 16 IRQ0
.word halt // 17 IRQ1
// On to IRQ67
.word halt,halt,halt,halt,halt,halt,halt,halt,halt,halt
.word halt,halt,halt,halt,halt,halt,halt,halt,halt,halt
.word halt,halt,halt,halt,halt,halt,halt,halt,halt,halt
.word halt,halt,halt,halt,halt,halt,halt,halt,halt,halt
.word halt,halt,halt,halt,halt,halt,halt,halt,halt,halt
spin: b spin
halt: b halt
pass: BX lr
.thumb_func
.global _reset

View File

@ -13,6 +13,17 @@ static inline void led_toggle(void) {
}
static inline void init_hardware(void) {
RCC->CR |= (RCC_CR_HSEON);
while (!(RCC->CR & RCC_CR_HSERDY)) (void) 0;
RCC->CFGR &= ~(RCC_CFGR_SW);
RCC->CFGR |= (RCC_CFGR_SW_HSE);
RCC->CFGR &= ~(RCC_CFGR_PLLMULL);
RCC->CFGR |= (RCC_CFGR_PLLMULL9);
RCC->CR |= (RCC_CR_PLLON);
while (!(RCC->CR & RCC_CR_PLLRDY)) (void) 0;
RCC->CFGR &= ~(RCC_CFGR_SW);
RCC->CFGR |= (RCC_CFGR_SW_PLL);
RCC->APB2ENR |= BIT(2) | BIT(3) | BIT(4); // Init GPIO banks A,B,C
gpio_init(LED1, OUTPUT); // Set LED
}

View File

@ -15,6 +15,8 @@ static inline void setreg(volatile uint32_t *r, uint32_t clear_mask, uint32_t se
// RCC registers, TRM section 7.3, memory map section 3.3
struct rcc { volatile uint32_t CR, CFGR, CIR, APB2RSTR, APB1RSTR, AHBENR, APB2ENR, APB1ENR, BDCR, CSR; };
#define RCC ((struct rcc *) 0x40021000)
enum {RCC_CR_HSEON = BIT(16), RCC_CR_HSERDY = BIT(17), RCC_CR_PLLON = BIT(24), RCC_CR_PLLRDY = BIT(25)};
enum {RCC_CFGR_SW = 3, RCC_CFGR_SW_HSI = 0, RCC_CFGR_SW_HSE = 1, RCC_CFGR_SW_PLL = 2, RCC_CFGR_PLLMULL = (15U << 18), RCC_CFGR_PLLMULL9 = (7U << 18)};
static inline void init_ram(void) {
extern uint32_t _bss_start, _bss_end;