Skip to content

Commit

Permalink
Merge pull request #14 from Embedded-System-Lovers/port_init_and_docs
Browse files Browse the repository at this point in the history
Dedicated Port_Init() and update docs
  • Loading branch information
ckormanyos authored Jun 24, 2024
2 parents eed5880 + 94729be commit 541dbb2
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 19 deletions.
7 changes: 4 additions & 3 deletions Build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,12 @@ endif
############################################################################################
# Source Files
############################################################################################
SRC_FILES := $(SRC_DIR)/Appli/main.c \
SRC_FILES := $(SRC_DIR)/Appli/main.c \
$(SRC_DIR)/Mcal/Mcu.c \
$(SRC_DIR)/Mcal/Port.c \
$(SRC_DIR)/Mcal/SysTick.c \
$(SRC_DIR)/Startup/boot.s \
$(SRC_DIR)/Startup/intvect.c \
$(SRC_DIR)/Startup/boot.s \
$(SRC_DIR)/Startup/intvect.c \
$(SRC_DIR)/Startup/Startup.c

############################################################################################
Expand Down
6 changes: 5 additions & 1 deletion Code/Appli/main.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#include "SysTick.h"
#include <Port.h>
#include <SysTick.h>

// cd /mnt/c/Users/ckorm/Documents/Ks/uC_Software/Boards/WCH_V307_RISC-V
// wget --no-check-certificate https://buildbot.embecosm.com/job/riscv32-gcc-ubuntu2204-release/10/artifact/riscv32-embecosm-ubuntu2204-gcc13.2.0.tar.gz
Expand All @@ -10,7 +11,10 @@

int main(void)
{
Port_Init();

SysTick_Init();

SysTick_Start(SYSTICK_TIMEOUT_SEC(1));

for(;;)
Expand Down
33 changes: 33 additions & 0 deletions Code/Mcal/Port.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/******************************************************************************************
Filename : Port.c
Core : QingKe V4F (RISC-V)
MCU : CH32V307VCT6 (WCH)
Author : Christopher Kormanyos
Owner : Christopher Kormanyos
Date : 24.06.2024
Description : port driver implementation
******************************************************************************************/

//=========================================================================================
// Includes
//=========================================================================================
#include <Port.h>

//-----------------------------------------------------------------------------------------
/// \brief
///
/// \param
///
/// \return
//-----------------------------------------------------------------------------------------
void Port_Init(void)
{
GPIOC->OUTDR.bit.ODR0 = 0u;
}
29 changes: 29 additions & 0 deletions Code/Mcal/Port.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/******************************************************************************************
Filename : SysTick.h
Core : QingKe V4F (RISC-V)
MCU : CH32V307VCT6 (WCH)
Author : Chalandi Amine
Owner : Chalandi Amine
Date : 23.01.2023
Description : system tick timer driver header file
******************************************************************************************/

#ifndef __PORT_H__
#define __PORT_H__

//=========================================================================================
// Includes
//=========================================================================================
#include <CH32V30xxx.h>
#include <Platform_Types.h>

void Port_Init(void);

#endif /* __PORT_H__ */
6 changes: 4 additions & 2 deletions Code/Mcal/SysTick.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//=========================================================================================
// Includes
//=========================================================================================
#include "SysTick.h"
#include <SysTick.h>

//=========================================================================================
// Defines
Expand Down Expand Up @@ -71,7 +71,8 @@ void SysTick_Init(void)
//-----------------------------------------------------------------------------------------
void SysTick_Start(uint64 timeout)
{
*(volatile uint64*)(&R32_STK_CMPLR->u32Reg) = (uint64)timeout;
*(volatile uint64*) (&R32_STK_CMPLR->u32Reg) = (uint64) timeout;

R32_STK_CTLR->bit.u1STE = 1u;
}

Expand All @@ -98,6 +99,7 @@ void SysTick_Stop(void)
void Isr_SysTick(void)
{
GPIOC->OUTDR.bit.ODR0 ^= 1u;

R32_STK_SR->bit.u1CNTIF = 0u;
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions Code/Mcal/SysTick.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
//=========================================================================================
// Includes
//=========================================================================================
#include "CH32V30xxx.h"
#include "Platform_Types.h"
#include <CH32V30xxx.h>
#include <Platform_Types.h>

//=========================================================================================
// Types definitions
Expand Down
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ Features include:
- blinky LED show with adjustable frequency,
- implementation in C99 with absolute minimal use of assembly.

Clear and easy-to-understand build systems based on either
GNUmake or CMake complete this fun and educational project.
A clear and easy-to-understand build system based on GNUmake
completes this fun and educational project.

This repository provides keen insight on starting up
a _bare_ _metal_ SiFive RISC-V controller. It emphasizes
Expand All @@ -36,8 +36,14 @@ for LED blinky.

The adjustable LED-phase (its half-period) can be tuned
to provide a rudimentary, visible blinky LED show.
The timebase for blinky is based on the `mtimer`
interrupt handler.
The timebase for blinky is based on the `R32_STK` timer
with an interrupt handler once per second.

Blinky running on the target is shown in the image below.
A wire-connection is required between port pins `PC0` and `LED1`
in order to observe the blinky toggle (see the orange wire).

![](./images/wch_v307.jpg)

## Building the Application

Expand All @@ -55,13 +61,6 @@ cd Build
./Rebuild.sh
```

### CMake

```sh
mkdir Output && cd Output
cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchain-unix.cmake .. && make
```

The build results including ELF-file, HEX-mask, MAP-file
and assembly list file are created in the `Output` directory.

Expand Down
Binary file added images/wch_v307.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 541dbb2

Please sign in to comment.