parent
ffe99c1ed5
commit
f961a639f4
@ -0,0 +1,27 @@ |
||||
cmake_minimum_required(VERSION 3.7) |
||||
project(stm8 C) |
||||
project(STM8S) |
||||
set(CMAKE_CXX_STANDARD GNU99) |
||||
|
||||
add_definitions( |
||||
-DSKIP_TRAPS=1 |
||||
-DSTM8S103 |
||||
-D__SDCC__ |
||||
-D_SDCC_ |
||||
-DINTERRUPT= |
||||
-D__interrupt\(n\)=__attribute__\(\(interrupt\(n\)\)\) |
||||
-D__SDCC) |
||||
|
||||
# User program |
||||
include_directories(User) |
||||
include_directories(Library/SPL) |
||||
#include_directories(Libraries/SPL/inc) |
||||
file(GLOB_RECURSE USER_SOURCES "User/*.c" "User/*.h") |
||||
|
||||
file(GLOB_RECURSE LIB_SOURCES "Library/SPL/*.h") |
||||
|
||||
# Systemmake |
||||
include_directories(/usr/share/sdcc/include/) |
||||
link_directories(/usr/share/sdcc/include/) |
||||
|
||||
add_executable(firmware ${USER_SOURCES} ${LIB_SOURCES}) |
@ -1,12 +1,70 @@ |
||||
#include <stdio.h> |
||||
#include "stm8s.h" |
||||
#include <stdlib.h> |
||||
|
||||
#include <stm8s.h> |
||||
#include "stm8s_it.h" |
||||
void Delay(uint16_t nCount) { |
||||
uint8_t i; |
||||
for (; nCount != 0; nCount--) { |
||||
for (i = 255; i != 0; i--) {} |
||||
} |
||||
} |
||||
|
||||
void putchar(char c) { |
||||
while ((UART1->SR & UART1_SR_TXE) == 0); |
||||
UART1->DR = (u8)c; |
||||
} |
||||
|
||||
void puts(const char *ch) { |
||||
char c; |
||||
while ((c = *ch++) != 0) |
||||
putchar(c); |
||||
} |
||||
|
||||
void puts_itoa(int32_t n, unsigned char radix) { |
||||
char s[10], i, c; |
||||
_ltoa(n, s, radix); |
||||
i = 0; |
||||
while((c = s[i++]) != 0) { |
||||
putchar(c); |
||||
} |
||||
} |
||||
|
||||
void main(void) |
||||
{ |
||||
// Disable div8
|
||||
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1); |
||||
|
||||
// LED for blinking
|
||||
GPIO_Init(GPIOB, GPIO_PIN_5, GPIO_MODE_OUT_PP_HIGH_FAST); |
||||
|
||||
// minimal uart init
|
||||
UART_SimpleInit(UART_BAUD_115200); |
||||
|
||||
while(1); |
||||
// irq conf
|
||||
UART1_ITConfig(UART1_IT_RXNE_OR, ENABLE); |
||||
enableInterrupts(); |
||||
|
||||
// Clear screen & print system frequency
|
||||
puts("\033c\033[?25lClock freq = "); // cls
|
||||
puts_itoa(CLK_GetClockFreq(), 10); |
||||
puts(" Hz"); // cls
|
||||
|
||||
// echo & blinking
|
||||
while (1) { |
||||
Delay(2000); |
||||
GPIOB->ODR ^= GPIO_PIN_5; |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* @brief UART1 RX Interrupt routine. |
||||
* @param None |
||||
* @retval None |
||||
*/ |
||||
INTERRUPT_HANDLER(UART1_RX_IRQHandler, 18) |
||||
{ |
||||
if (UART1->SR & UART1_SR_RXNE) |
||||
UART1->DR = (u8) (UART1->DR); // echo
|
||||
|
||||
if (UART1->SR & UART1_SR_OR) |
||||
UART1->SR &= ~UART1_SR_OR; // clear OR flag
|
||||
} |
||||
|
Loading…
Reference in new issue