S3C6410 bare metal UART driver (redefine printf to serial port)

Publisher:数据梦行者Latest update time:2017-02-26 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

To ensure that S3C6410 has been initialized, usually use UBOOT initialization

 

//Serial port register

//UART0

#defineULCON0 *((vu32*)0x7F005000) //UART channel 0 line control register

#defineUCON0 *((vu32*)0x7F005004) //UART channel 0 control register

#defineUFCON0 *((vu32*)0x7F005008) //UART channel 0 FIFO control register

#defineUMCON0 *((vu32*)0x7F00500C) //UART channel 0 modem control register

#defineUTRSTAT0 *((vu32*)0x7F005010) //UART channel 0 send/receive status register

#defineUERSTAT0 *((vu32*)0x7F005014) //UART channel 0 receive error status register

#defineUFSTAT0 *((vu32*)0x7F005018) //UART channel 0 FIFO status register

#defineUMSTAT0 *((vu32*)0x7F00501C) //UART channel 0 modem status register

#defineUTXH0 *((vu32*)0x7F005020) //UART channel 0 send buffer register

#defineURXH0 *((vu32*)0x7F005024) //UART channel 0 receive buffer register

#defineUBRDIV0 *((vu32*)0x7F005028) //Channel 0 baud rate divider register

#defineUDIVSLOT0 *((vu32*)0x7F00502C) //UART channel 0 frequency division slot register

#defineUINTP0 *((vu32*)0x7F005030) //Channel 0 interrupt processing register

#defineUINTSP0 *((vu32*)0x7F005034) //UART channel 0 interrupt source processing register

#defineUINTM0 *((vu32*)0x7F005038) //UART channel 0 interrupt mask register

 

 

 

 

 

//Author: Chen

//Creation time: 20120220

//Last modified time: 20120220

//Description: S3C6410 serial port related

 

#include "system.h"

#include "uart.h"

#include "s3c6410_map.h"

 

 

 

 

///////////////////////////////////////////////////// /////////////////

//Add the following code to support the printf function,

#if 1

 

#include "stdio.h"        

//Support functions required by the standard library                

struct __FILE

{

inthandle;

};

/* FILE is typedef'd in stdio.h. */

FILE __stdout;      

// define _sys_exit() to avoid using semihost mode   

_sys_exit(int x)

{

x= x;

}

//Redefine fputc function

int fputc(int ch,FILE *f)

{     

Uart0_SendByte((u8)ch);     

returnch;

}

#endif

 

 

 

static const u16UART_SPEED[13][2] ={{1717,0x4924},{858,0x4924},{428,0x4924},{285,0x4924},{213,0x4924},{142,0x4924},{106, 0x4924},{72,0x4924},{70,0x4924},{34,0x4924},{16,0x4924},{7,0x4924},{3,0x4924}};

 

 

 

 

/****************************************************** *************************************************** ************************

*Function: voidUart0_Init(void)

*Function: Serial port 0 initialization

*Parameters: None

*Return: None

*Depends on: underlying macro definitions

*Author : Chen

*Time: 20120220

* Last modified: 20120220

*Description: Initialize serial port 0

*************************************************** *************************************************** *********************/

void Uart0_Init(u8UART_Speed)

{

PCLK_GATE|= 1 << 1; //UART0 gates PCLK clock, 66mhz

GPIOA->CON&=~(0xff); //Clear previous settings, GPIOA0, GPIOA1

GPIOA->CON|= (HOST | (HOST <<4)); //Set GPIOA0, GPIOA1 to uart mode

ULCON0=0x3; //8 bits per frame //Clear settings//Normal mode, no parity, 1 stop bit

UCON0= (0x1 << 2) | 0x1 | (2 <<10); // Clear control register // Set (PCLK=66MHz) as baud rate clock

UFCON0=0; //Disable FIFO

UMCON0=0; //Disable AFC, nRTS high level is invalid

UBRDIV0 =UART_SPEED[UART_Speed][0]; //Set the integer part of the baud rate

UDIVSLOT0= UART_SPEED[UART_Speed][1]; //Set the decimal part of the baud rate

UINTP0= 0; //Disable UART0 interrupt

UINTSP0= 0; //Set interrupt source

UINTM0= 0; //Disable interrupt mask\

 

}

 

/****************************************************** *************************************************** ************************

*Function: voidUart0_SendByte(u8 data)

*Function: Serial port 0 sends a byte

*Parameter: data to be sent

*Return: None

*Depends on: underlying macro definitions

*Author : Chen

*Time: 20120220

* Last modified: 20120220

*Description: Use serial port 0 to send a byte

*************************************************** *************************************************** *********************/

voidUart0_SendByte(u8 data)

{

while(!(UTRSTAT0& (1 <<2))); //Wait for the send buffer to be empty

UTXH0= data; //Write data into the transmit buffer

Now



you can use printf directly to send data to the serial port.


Reference address:S3C6410 bare metal UART driver (redefine printf to serial port)

Previous article:Temporarily solve the problem that S3C6410 cannot perform bare metal floating point operations
Next article:The difference between main() and __main() in ARM

Recommended ReadingLatest update time:2024-11-16 15:00

How to use printf in C51 serial port
Use of serial port printf The function prototype is as follows: void USART0_Printf(char *fmt,...) //This is our printf function {  char* ap; //typedef char *va_list; va_list is a pointer of type char  charxdata string ; //Access external RAM two-byte alignment  va_start(ap,fmt); //The function of this function is to
[Microcontroller]
JZ2440 bare metal development and analysis: serial port programming 5 serial port implementation printf
Some important codes: main.c #include "s3c2440_soc.h" #include "uart.h" #include  "my_printf.h" int main(void) { unsigned char c; uart0_init(); puts("Hello, world!nr"); my_printf_test(); while(1) { c = getchar(); if (c == 'r') { putchar('n'); } if (c == 'n') { putchar('r'); } putchar(c); }
[Microcontroller]
Notes on using printf in KEIL C51
Key points of using printf() function in keil   When searching for information online, I found an article introducing the use of printf() function in keil. I copied it here as a memo. In Keil, printf sends data to the serial port by default. Therefore, if you use this function, you must initialize the serial port f
[Microcontroller]
Library function printf in KeilC51
When using Keil simulation to view the serial port output, I encountered a problem. The code is as follows: #include reg52.h #include stdio.h /* Add to use printf function*/ main() {      SCON = 0x50; /*SCON: working mode 1, 8-bit UART, allow receiving*/      TMOD |= 0x20;/*TMOD: Timer T1, working mode 2, 8-
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号