generated from Embedded_Projects/NUC200_Template
Added UART for stdout.
This commit is contained in:
parent
fbc8ddefd4
commit
eae5f3c75b
|
@ -1,6 +1,6 @@
|
||||||
BasedOnStyle: Google
|
BasedOnStyle: Google
|
||||||
IndentWidth: 4
|
IndentWidth: 4
|
||||||
AlignConsecutiveMacros: AcrossEmptyLines
|
AlignConsecutiveMacros: Consecutive
|
||||||
AlignConsecutiveDeclarations: true
|
AlignConsecutiveDeclarations: true
|
||||||
AlignConsecutiveAssignments: true
|
AlignConsecutiveAssignments: true
|
||||||
BreakBeforeBraces: Custom
|
BreakBeforeBraces: Custom
|
||||||
|
|
|
@ -40,6 +40,7 @@ set(TARGET_C_SOURCES
|
||||||
"BSP/StdDriver/src/wwdt.c"
|
"BSP/StdDriver/src/wwdt.c"
|
||||||
"src/main.c"
|
"src/main.c"
|
||||||
"src/nfc_impl.c"
|
"src/nfc_impl.c"
|
||||||
|
"src/libc-hooks.c"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Copy them from Makefile
|
# Copy them from Makefile
|
||||||
|
|
|
@ -56,7 +56,7 @@
|
||||||
#define configQUEUE_REGISTRY_SIZE 8
|
#define configQUEUE_REGISTRY_SIZE 8
|
||||||
#define configUSE_QUEUE_SETS 0
|
#define configUSE_QUEUE_SETS 0
|
||||||
#define configUSE_TIME_SLICING 0
|
#define configUSE_TIME_SLICING 0
|
||||||
#define configUSE_NEWLIB_REENTRANT 0
|
#define configUSE_NEWLIB_REENTRANT 1 /* impure_ptr for each tasks */
|
||||||
#define configENABLE_BACKWARD_COMPATIBILITY 0
|
#define configENABLE_BACKWARD_COMPATIBILITY 0
|
||||||
#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 5
|
#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 5
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 09a2c0b3247605eca9a0cdd8450b9d4a88389ab1
|
Subproject commit 840214dc2981611509f9802f11d0b177dea164b7
|
|
@ -0,0 +1,81 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include "NUC200Series.h"
|
||||||
|
|
||||||
|
#include "FreeRTOS.h"
|
||||||
|
#include "task.h"
|
||||||
|
|
||||||
|
#define NEWLIB_HEAP_SIZE 0x400
|
||||||
|
|
||||||
|
/* Static heap for newlib. */
|
||||||
|
static uint8_t __attribute__((section(".heap"))) __attribute__((aligned(4))) s_heap[NEWLIB_HEAP_SIZE];
|
||||||
|
|
||||||
|
size_t s_heap_sz = 0;
|
||||||
|
|
||||||
|
int _getpid(void) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int _kill(int i, int j) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int _read(int fd, char *buf, int nbytes) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int _write(int fd, const void *buf, int nbytes) {
|
||||||
|
for(int i = 0; i < nbytes; i++) {
|
||||||
|
while(UART0->FSR & UART_FSR_TX_FULL_Msk) {
|
||||||
|
/* Wait for TX fifo available */
|
||||||
|
}
|
||||||
|
/* Write FIFO */
|
||||||
|
UART0->THR = ((uint8_t *)buf)[i];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nbytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
int _close(int file) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int _isatty(int file) {
|
||||||
|
return file <= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
int _fstat(int file, struct stat *st) {
|
||||||
|
st->st_mode = S_IFCHR;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int _lseek(int file, int ptr, int dir){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *_sbrk(intptr_t count) {
|
||||||
|
void *ret, *ptr;
|
||||||
|
|
||||||
|
/* Note: current implementation does NOT support calling malloc from ISRs. */
|
||||||
|
if(xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
|
||||||
|
taskENTER_CRITICAL(); /* Freeze! */
|
||||||
|
}
|
||||||
|
|
||||||
|
ptr = s_heap + s_heap_sz;
|
||||||
|
if(s_heap_sz + count < NEWLIB_HEAP_SIZE) {
|
||||||
|
s_heap_sz += count;
|
||||||
|
ret = ptr;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ret = (void *)-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
|
||||||
|
taskEXIT_CRITICAL();
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
35
src/main.c
35
src/main.c
|
@ -1,6 +1,7 @@
|
||||||
#include "NUC200Series.h"
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
|
#include "NUC200Series.h"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,7 +52,7 @@ static void system_clock_config(void) {
|
||||||
* HCLK: 48MHz
|
* HCLK: 48MHz
|
||||||
* SC0-2: 12MHz
|
* SC0-2: 12MHz
|
||||||
*/
|
*/
|
||||||
CLK->CLKDIV = CLK_CLKDIV_ADC(4) | CLK_CLKDIV_UART(4) | CLK_CLKDIV_USB(1) | CLK_CLKDIV_HCLK(1);
|
CLK->CLKDIV = CLK_CLKDIV_ADC(4) | CLK_CLKDIV_UART(1) | CLK_CLKDIV_USB(1) | CLK_CLKDIV_HCLK(1);
|
||||||
CLK->CLKDIV1 = CLK_CLKDIV1_SC2(4) | CLK_CLKDIV1_SC1(4) | CLK_CLKDIV1_SC0(4);
|
CLK->CLKDIV1 = CLK_CLKDIV1_SC2(4) | CLK_CLKDIV1_SC1(4) | CLK_CLKDIV1_SC0(4);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -74,18 +75,38 @@ static void system_clock_config(void) {
|
||||||
CLK->CLKSEL2 = 0x200FFU; /* Reset value */
|
CLK->CLKSEL2 = 0x200FFU; /* Reset value */
|
||||||
CLK->CLKSEL3 = 0x3FU; /* Reset value */
|
CLK->CLKSEL3 = 0x3FU; /* Reset value */
|
||||||
|
|
||||||
|
CLK_EnableModuleClock(UART0_MODULE);
|
||||||
|
CLK_EnableModuleClock(SPI0_MODULE);
|
||||||
|
|
||||||
SystemCoreClockUpdate();
|
SystemCoreClockUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pinmux_config(void) {
|
static void pinmux_config(void) {
|
||||||
GPIO_SetMode(PA, BIT3, GPIO_PMD_OPEN_DRAIN); /* LED_GREEN */
|
GPIO_SetMode(PA, BIT3, GPIO_PMD_OPEN_DRAIN); /* LED_GREEN */
|
||||||
GPIO_SetMode(PA, BIT4, GPIO_PMD_OPEN_DRAIN); /* LED_RED */
|
GPIO_SetMode(PA, BIT4, GPIO_PMD_OPEN_DRAIN); /* LED_RED */
|
||||||
|
|
||||||
|
/* UART */
|
||||||
|
SYS->GPB_MFP &= ~(SYS_GPB_MFP_PB0_Msk | SYS_GPB_MFP_PB1_Msk);
|
||||||
|
SYS->GPB_MFP |= SYS_GPB_MFP_PB0_UART0_RXD | SYS_GPB_MFP_PB1_UART0_TXD;
|
||||||
|
|
||||||
|
/* NFC SPI Port PC0-3 */
|
||||||
|
SYS->GPC_MFP &= ~(SYS_GPC_MFP_PC0_Msk | SYS_GPC_MFP_PC1_Msk | SYS_GPC_MFP_PC2_Msk | SYS_GPC_MFP_PC3_Msk);
|
||||||
|
SYS->GPC_MFP |=
|
||||||
|
SYS_GPC_MFP_PC0_SPI0_SS0 | SYS_GPC_MFP_PC1_SPI0_CLK | SYS_GPC_MFP_PC2_SPI0_MISO0 | SYS_GPC_MFP_PC3_SPI0_MOSI0;
|
||||||
|
|
||||||
|
SYS->ALT_MFP &= ~(SYS_ALT_MFP_PC0_Msk | SYS_ALT_MFP_PC1_Msk | SYS_ALT_MFP_PC2_Msk | SYS_ALT_MFP_PC3_Msk);
|
||||||
|
SYS->ALT_MFP |=
|
||||||
|
SYS_ALT_MFP_PC0_SPI0_SS0 | SYS_ALT_MFP_PC1_SPI0_CLK | SYS_ALT_MFP_PC2_SPI0_MISO0 | SYS_ALT_MFP_PC3_SPI0_MOSI0;
|
||||||
|
|
||||||
|
/* NFC Reset and IRQ */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hello_task(void *pvParameters) {
|
static void hello_task(void *pvParameters) {
|
||||||
PA->DOUT ^= BIT4;
|
PA->DOUT ^= BIT4;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
PA->DOUT ^= BIT3 | BIT4;
|
PA->DOUT ^= BIT3 | BIT4;
|
||||||
|
printf("Hello?\r\n");
|
||||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,7 +115,15 @@ int main(int argc, const char *argv[]) {
|
||||||
system_clock_config();
|
system_clock_config();
|
||||||
pinmux_config();
|
pinmux_config();
|
||||||
|
|
||||||
xTaskCreate(hello_task, "HELLO", 128, NULL, 6, NULL);
|
UART_Open(UART0, 921600);
|
||||||
|
|
||||||
|
printf("UART0 opened for stdout operations.\r\n");
|
||||||
|
|
||||||
|
if(xTaskCreate(hello_task, "HELLO", 128, NULL, 6, NULL) != pdPASS) {
|
||||||
|
for(;;) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
vTaskStartScheduler();
|
vTaskStartScheduler();
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,4 @@ void SPI0_IRQHandler(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* <-- EXTI --> */
|
/* <-- EXTI --> */
|
||||||
void GPAB_IRQHandler(void) {
|
void GPAB_IRQHandler(void) { /* ??? Sasuga Nuvoton */ }
|
||||||
/* ??? Sasuga Nuvoton */
|
|
||||||
}
|
|
Loading…
Reference in New Issue