LpcUart: [#22] This could have worked.
* It appears that LPC11u68 has ony USART0 redirected to USB as debug UART. * The code here was written only for USART1-4.
This commit is contained in:
parent
620439fff4
commit
13e392f37b
@ -6,12 +6,17 @@
|
|||||||
#include "ThreadCommon.h"
|
#include "ThreadCommon.h"
|
||||||
#include "Master.h"
|
#include "Master.h"
|
||||||
#include "Rotary.h"
|
#include "Rotary.h"
|
||||||
|
#include "retarget_uart.h"
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
SystemCoreClockUpdate();
|
SystemCoreClockUpdate();
|
||||||
Board_Init();
|
Board_Init();
|
||||||
|
|
||||||
|
retarget_init();
|
||||||
|
|
||||||
|
printf("Hello there!\r\n");
|
||||||
|
|
||||||
ThreadCommon::ThreadManager* manager = new ThreadCommon::ThreadManager;
|
ThreadCommon::ThreadManager* manager = new ThreadCommon::ThreadManager;
|
||||||
ThreadCommon::QueueManager* qmanager = new ThreadCommon::QueueManager;
|
ThreadCommon::QueueManager* qmanager = new ThreadCommon::QueueManager;
|
||||||
//Creating queues
|
//Creating queues
|
||||||
|
|||||||
@ -13,6 +13,10 @@
|
|||||||
* We don't have movable pins -> not needed.
|
* We don't have movable pins -> not needed.
|
||||||
*
|
*
|
||||||
* Muxing is like this:
|
* Muxing is like this:
|
||||||
|
* Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 14, (IOCON_FUNC4 | IOCON_MODE_INACT | IOCON_DIGMODE_EN));
|
||||||
|
* Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 13, (IOCON_FUNC4 | IOCON_MODE_INACT | IOCON_DIGMODE_EN));
|
||||||
|
*
|
||||||
|
* USART0 (the only debug uart):
|
||||||
* Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 18, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGMODE_EN));
|
* Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 18, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGMODE_EN));
|
||||||
* Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 19, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGMODE_EN));
|
* Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 19, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGMODE_EN));
|
||||||
*/
|
*/
|
||||||
@ -90,7 +94,7 @@ LpcUart::LpcUart(const LpcUartConfig &cfg) {
|
|||||||
* UARTs.
|
* UARTs.
|
||||||
* */
|
* */
|
||||||
/* Use main clock rate as base for UART baud rate divider */
|
/* Use main clock rate as base for UART baud rate divider */
|
||||||
Chip_Clock_SetUSARTNBaseClockRate(Chip_Clock_GetMainClockRate(), false);
|
Chip_Clock_SetUSARTNBaseClockRate(Chip_Clock_GetMainClockRate(), false); //(115200 * 256), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
uart = nullptr; // set default value before checking which UART to configure
|
uart = nullptr; // set default value before checking which UART to configure
|
||||||
@ -123,19 +127,19 @@ LpcUart::LpcUart(const LpcUartConfig &cfg) {
|
|||||||
|
|
||||||
|
|
||||||
if(cfg.tx.port >= 0) {
|
if(cfg.tx.port >= 0) {
|
||||||
Chip_IOCON_PinMuxSet(LPC_IOCON, cfg.tx.port, cfg.tx.pin, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGMODE_EN));
|
Chip_IOCON_PinMuxSet(LPC_IOCON, cfg.tx.port, cfg.tx.pin, (IOCON_FUNC4 | IOCON_MODE_INACT | IOCON_DIGMODE_EN));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(cfg.rx.port >= 0) {
|
if(cfg.rx.port >= 0) {
|
||||||
Chip_IOCON_PinMuxSet(LPC_IOCON, cfg.rx.port, cfg.rx.pin, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGMODE_EN));
|
Chip_IOCON_PinMuxSet(LPC_IOCON, cfg.rx.port, cfg.rx.pin, (IOCON_FUNC4 | IOCON_MODE_INACT | IOCON_DIGMODE_EN));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(use_cts) {
|
if(use_cts) {
|
||||||
Chip_IOCON_PinMuxSet(LPC_IOCON, cfg.cts.port, cfg.cts.pin, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGMODE_EN));
|
Chip_IOCON_PinMuxSet(LPC_IOCON, cfg.cts.port, cfg.cts.pin, (IOCON_FUNC4 | IOCON_MODE_INACT | IOCON_DIGMODE_EN));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(use_rts) {
|
if(use_rts) {
|
||||||
Chip_IOCON_PinMuxSet(LPC_IOCON, cfg.rts.port, cfg.rts.pin, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGMODE_EN));
|
Chip_IOCON_PinMuxSet(LPC_IOCON, cfg.rts.port, cfg.rts.pin, (IOCON_FUNC4 | IOCON_MODE_INACT | IOCON_DIGMODE_EN));
|
||||||
}
|
}
|
||||||
|
|
||||||
notify_rx = nullptr;
|
notify_rx = nullptr;
|
||||||
|
|||||||
91
source/shoh/src/peripherals/retarget_uart.cpp
Normal file
91
source/shoh/src/peripherals/retarget_uart.cpp
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
* retarget_uart.cpp
|
||||||
|
*
|
||||||
|
* Created on: 28.9.2021
|
||||||
|
* Author: keijo
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "LpcUart.h"
|
||||||
|
|
||||||
|
static LpcUart *dbgu;
|
||||||
|
|
||||||
|
void retarget_init()
|
||||||
|
{
|
||||||
|
LpcPinMap none = {-1, -1}; // unused pin has negative values in it
|
||||||
|
//Sadly, it seems that only USART0 is redirected to USB.
|
||||||
|
//It means that those are pins PIO0_18 and PIO0_19
|
||||||
|
LpcPinMap txpin = { 0, 14 }; // transmit pin that goes to debugger's UART->USB converter
|
||||||
|
LpcPinMap rxpin = { 0, 13 }; // receive pin that goes to debugger's UART->USB converter
|
||||||
|
LpcUartConfig cfg = { LPC_USART1, 115200, UARTN_CFG_DATALEN_8 | UARTN_CFG_PARITY_NONE | UARTN_CFG_STOPLEN_1, false, txpin, rxpin, none, none };
|
||||||
|
dbgu = new LpcUart(cfg);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
// ******************************************************************
|
||||||
|
// Redlib C Library function : __sys_write
|
||||||
|
// Newlib C library function : _write
|
||||||
|
//
|
||||||
|
// Function called by bottom level of printf routine within C library.
|
||||||
|
// With the default semihosting stub, this would write the
|
||||||
|
// character(s) to the debugger console window (which acts as
|
||||||
|
// stdout). But this version writes the character(s) to UART
|
||||||
|
// ******************************************************************
|
||||||
|
#if defined (__REDLIB__)
|
||||||
|
int __sys_write(int iFileHandle, char *pcBuffer, int iLength) {
|
||||||
|
#elif defined (__NEWLIB__)
|
||||||
|
int _write(int iFileHandle, char *pcBuffer, int iLength) {
|
||||||
|
#endif
|
||||||
|
if(dbgu) {
|
||||||
|
int len = iLength;
|
||||||
|
while(len > 0) {
|
||||||
|
if(*pcBuffer == '\n') { // send a CR before every LF
|
||||||
|
while(dbgu->write('\r')==0);
|
||||||
|
}
|
||||||
|
while(dbgu->write(*pcBuffer)==0);
|
||||||
|
++pcBuffer;
|
||||||
|
--len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Function returns number of bytes written
|
||||||
|
return iLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined (__REDLIB__)
|
||||||
|
// ******************************************************************
|
||||||
|
// Redlib C Library function : __sys_readc
|
||||||
|
//
|
||||||
|
// Called by bottom level of scanf routine within RedLib C library
|
||||||
|
// to read a character. With the default semihosting stub, this
|
||||||
|
// would read the character from the debugger console window (which
|
||||||
|
// acts as stdin). But this version reads the character from UART
|
||||||
|
// ******************************************************************
|
||||||
|
|
||||||
|
int __sys_readc(void) {
|
||||||
|
char c;
|
||||||
|
if(dbgu && dbgu->read(c)) return c;
|
||||||
|
else return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
// #endif REDLIB __sys_readc()
|
||||||
|
|
||||||
|
#elif defined (__NEWLIB__)
|
||||||
|
// ******************************************************************
|
||||||
|
// Function _read
|
||||||
|
//
|
||||||
|
// Called by bottom level of scanf routine within Newlib C library
|
||||||
|
// to read multiple characters. With the default semihosting stub, this
|
||||||
|
// would read characters from the debugger console window (which
|
||||||
|
// acts as stdin). But this version reads the characters from UART
|
||||||
|
// ******************************************************************
|
||||||
|
int _read(int iFileHandle, char *pcBuffer, int iLength) {
|
||||||
|
|
||||||
|
// TODO : Should potentially check that iFileHandle == 0 to confirm
|
||||||
|
// that read is from stdin
|
||||||
|
if(!dbgu) return 0;
|
||||||
|
return dbgu->read(pcBuffer, iLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // NEWLIB _read()
|
||||||
|
|
||||||
|
}
|
||||||
14
source/shoh/src/peripherals/retarget_uart.h
Normal file
14
source/shoh/src/peripherals/retarget_uart.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* retarget_uart.h
|
||||||
|
*
|
||||||
|
* Created on: 28.9.2021
|
||||||
|
* Author: keijo
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef RETARGET_UART_H_
|
||||||
|
#define RETARGET_UART_H_
|
||||||
|
|
||||||
|
void retarget_init();
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* RETARGET_UART_H_ */
|
||||||
@ -21,15 +21,19 @@ void Master::taskFunction() {
|
|||||||
{
|
{
|
||||||
case ThreadCommon::RotaryAction::Right:
|
case ThreadCommon::RotaryAction::Right:
|
||||||
Board_LED_Set(ThreadCommon::RotaryAction::Right, LedState);
|
Board_LED_Set(ThreadCommon::RotaryAction::Right, LedState);
|
||||||
|
printf("Right\r\n");
|
||||||
break;
|
break;
|
||||||
case ThreadCommon::RotaryAction::Left:
|
case ThreadCommon::RotaryAction::Left:
|
||||||
Board_LED_Set(ThreadCommon::RotaryAction::Left, LedState);
|
Board_LED_Set(ThreadCommon::RotaryAction::Left, LedState);
|
||||||
|
printf("Left\r\n");
|
||||||
break;
|
break;
|
||||||
case ThreadCommon::RotaryAction::Press:
|
case ThreadCommon::RotaryAction::Press:
|
||||||
Board_LED_Set(ThreadCommon::RotaryAction::Press, LedState);
|
Board_LED_Set(ThreadCommon::RotaryAction::Press, LedState);
|
||||||
|
printf("Press\r\n");
|
||||||
break;
|
break;
|
||||||
case ThreadCommon::RotaryAction::Idle:
|
case ThreadCommon::RotaryAction::Idle:
|
||||||
Board_LED_Set(ThreadCommon::RotaryAction::Right, LedState);
|
Board_LED_Set(ThreadCommon::RotaryAction::Right, LedState);
|
||||||
|
printf("Idle\r\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
LedState = !LedState;
|
LedState = !LedState;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user