Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 5:1d465d550109, committed 2014-12-28
- Comitter:
- kenjiArai
- Date:
- Sun Dec 28 11:51:59 2014 +0000
- Parent:
- 4:76b3113c79ff
- Commit message:
- monitor program for only for mbed GR-PEACH
Changed in this revision
--- a/L3GD20.lib Sun Dec 14 09:17:01 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://developer.mbed.org/users/kenjiArai/code/L3GD20/#8073008f3036
--- a/LIS3DH.lib Sun Dec 14 09:17:01 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://developer.mbed.org/users/kenjiArai/code/LIS3DH/#cc943f8d76a2
--- a/PID.lib Sun Dec 14 09:17:01 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/aberk/code/PID/#6e12a3e5af19
--- a/ST7565_SPI_LCD.lib Sun Dec 14 09:17:01 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://developer.mbed.org/users/kenjiArai/code/ST7565_SPI_LCD/#7d03976a0cb3
--- a/debug_tools/CheckRTC.lib Sun Dec 14 09:17:01 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/kenjiArai/code/CheckRTC/#921a188e61c0
--- a/debug_tools/debug_common.h Sun Dec 14 09:17:01 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,188 +0,0 @@
-/*
- * mbed Application program (part of debuf_xxx.cpp)
- *
- * Copyright (c) 2010-2014 Kenji Arai / JH1PJL
- * http://www.page.sannet.ne.jp/kenjia/index.html
- * http://mbed.org/users/kenjiArai/
- * Created: October 16th, 2014
- * Revised: Nobember 2nd, 2014
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
- * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
- * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-// Definition ------------------------------------------------------------------------------------
-#define BAUD(x) pcm.baud(x)
-#define GETC(x) pcm.getc(x)
-#define PUTC(x) pcm.putc(x)
-#define PRINTF(...) pcm.printf(__VA_ARGS__)
-#define READABLE(x) pcm.readable(x)
-
-#define BAUD_RATE 9600
-
-// Object ----------------------------------------------------------------------------------------
-Serial pcm(USBTX, USBRX);
-
-// RAM -------------------------------------------------------------------------------------------
-char linebuf[64];
-int buf_size = sizeof(linebuf);
-
-// ROM / Constant data ---------------------------------------------------------------------------
-char *const mon_msg =
- "Debug Interface for mbed system, created on UTC: "__DATE__"("__TIME__")";
-
-// Function prototypes ---------------------------------------------------------------------------
-extern void mon_hw(void);
-extern void get_freq(int pr);
-
-//-------------------------------------------------------------------------------------------------
-// Control Program
-//-------------------------------------------------------------------------------------------------
-// Put \r\n
-void put_rn ( void )
-{
- PUTC('\r');
- PUTC('\n');
-}
-
-// Put \r
-void put_r ( void )
-{
- PUTC('\r');
-}
-
-// Put ", "
-void put_lin ( void )
-{
- PRINTF(", ");
-}
-
-// Put space n
-void put_spc( uint8_t n)
-{
- for(; n > 0; n--) {
- PUTC(' ');
- }
-}
-
-// Change string -> integer
-//int xatoi (char **str, unsigned long *res){
-int xatoi (char **str, int32_t *res)
-{
- unsigned long val;
- unsigned char c, radix, s = 0;
-
- while ((c = **str) == ' ') (*str)++;
- if (c == '-') {
- s = 1;
- c = *(++(*str));
- }
- if (c == '0') {
- c = *(++(*str));
- if (c <= ' ') {
- *res = 0;
- return 1;
- }
- if (c == 'x') {
- radix = 16;
- c = *(++(*str));
- } else {
- if (c == 'b') {
- radix = 2;
- c = *(++(*str));
- } else {
- if ((c >= '0')&&(c <= '9')) {
- radix = 8;
- } else {
- return 0;
- }
- }
- }
- } else {
- if ((c < '1')||(c > '9')) {
- return 0;
- }
- radix = 10;
- }
- val = 0;
- while (c > ' ') {
- if (c >= 'a') c -= 0x20;
- c -= '0';
- if (c >= 17) {
- c -= 7;
- if (c <= 9) return 0;
- }
- if (c >= radix) return 0;
- val = val * radix + c;
- c = *(++(*str));
- }
- if (s) val = -val;
- *res = val;
- return 1;
-}
-
-// Get key input data
-void get_line (char *buff, int len)
-{
- char c;
- int idx = 0;
-
- for (;;) {
- c = GETC();
- // Added by Kenji Arai / JH1PJL May 9th, 2010
- if (c == '\r') {
- buff[idx++] = c;
- break;
- }
- if ((c == '\b') && idx) {
- idx--;
- PUTC(c);
- PUTC(' ');
- PUTC(c);
- }
- if (((uint8_t)c >= ' ') && (idx < len - 1)) {
- buff[idx++] = c;
- PUTC(c);
- }
- }
- buff[idx] = 0;
- PUTC('\n');
-}
-
-// RTC related subroutines
-void chk_and_set_time(char *ptr)
-{
-//unsigned long p1;
- int32_t p1;
- struct tm t;
- time_t seconds;
- char buf[40];
-
- if (xatoi(&ptr, &p1)) {
- t.tm_year = (uint8_t)p1 + 100;
- PRINTF("Year:%d ",p1);
- xatoi( &ptr, &p1 );
- t.tm_mon = (uint8_t)p1 - 1;
- PRINTF("Month:%d ",p1);
- xatoi( &ptr, &p1 );
- t.tm_mday = (uint8_t)p1;
- PRINTF("Day:%d ",p1);
- xatoi( &ptr, &p1 );
- t.tm_hour = (uint8_t)p1;
- PRINTF("Hour:%d ",p1);
- xatoi( &ptr, &p1 );
- t.tm_min = (uint8_t)p1;
- PRINTF("Min:%d ",p1);
- xatoi( &ptr, &p1 );
- t.tm_sec = (uint8_t)p1;
- PRINTF("Sec: %d \r\n",p1);
- seconds = mktime(&t);
- set_time(seconds);
- }
- seconds = time(NULL);
- strftime(buf, 40, "%B %d,'%y, %H:%M:%S", localtime(&seconds));
- PRINTF("Date: %s\r\n", buf);
-}
--- a/debug_tools/debug_gr-peach.cpp Sun Dec 14 09:17:01 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,309 +0,0 @@
-/*
- * mbed Application program
- *
- * Copyright (c) 2010-2014 Kenji Arai / JH1PJL
- * http://www.page.sannet.ne.jp/kenjia/index.html
- * http://mbed.org/users/kenjiArai/
- * Created: May 15th, 2010
- * Spareted: June 25th, 2014 mon() & mon_hw()
- * Ported: September 22nd, 2014 from L152RE, LP1114
- * changed: October 15th, 2014 mon.cpp to debug_xxx.cpp
- * Ported: December 13th, 2014 ported to GR-PEACH
- * Revised: December 13th, 2014
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
- * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
- * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#if defined(TARGET_RZ_A1H)
-
-// Include ---------------------------------------------------------------------------------------
-#include "mbed.h"
-#include "debug_common.h"
-
-// Definition ------------------------------------------------------------------------------------
-//#define PIN_NUM
-#define LED_NAME
-//#define LED_COLOR
-
-// Object ----------------------------------------------------------------------------------------
-DigitalOut xLEDs[4] = {
- DigitalOut(LED1), DigitalOut(LED2), DigitalOut(LED3), DigitalOut(LED4)
-};
-DigitalIn xUSER_SWITCH[2] = {
- DigitalIn(P6_0), DigitalIn(P6_1)
-};
-
-#if 0
- #if defined(PIN_NUM)
- DigitalOut myledR(P4_4);
- DigitalOut myledG(P3_2);
- DigitalOut myledB(P4_6);
- DigitalOut myledU(P4_7);
- #elif defined(LED_NAME)
- DigitalOut myledR(LED1);
- DigitalOut myledG(LED2);
- DigitalOut myledB(LED3);
- DigitalOut myledU(LED4);
- #elif defined(LED_COLOR)
- DigitalOut myledR(LED_RED);
- DigitalOut myledG(LED_GREEN);
- DigitalOut myledB(LED_BLUE);
- DigitalOut myledU(LED_USER);
- #endif
-#endif
-
-// RAM -------------------------------------------------------------------------------------------
-
-// ROM / Constant data ---------------------------------------------------------------------------
-
-// Function prototypes ---------------------------------------------------------------------------
-//extern void cpu_inf( char *ptr );
-//extern void port_mco1_mco2_set(void);
-//extern void port_mco1_mco2_recover(void);
-
-//-------------------------------------------------------------------------------------------------
-// Control Program
-//-------------------------------------------------------------------------------------------------
-// Help Massage
-void msg_hlp (void)
-{
- PRINTF(mon_msg);
- put_rn();
- PRINTF("1 - goto step1 -> no connection all pins");
- put_rn();
- PRINTF("2 - goto step2 -> connects pin_x and pin_y");
- put_rn();
- PRINTF("t - Check and set RTC");
- put_rn();
- PRINTF("x - Goto HW monitor");
- put_rn();
- PRINTF("q - Return to main");
- put_rn();
-}
-
-void check_leds(uint8_t i){
- char c;
-
- switch(i){
- case 0:
- c = 'R';
- break;
- case 1:
- c = 'G';
- break;
- case 2:
- c = 'B';
- break;
- case 3:
- c = 'U';
- break;
- default:
- return;
- }
- xLEDs[i] = 0;
- PRINTF("Is $c LED on? -> enter y/n", c);
- put_rn();
- c = GETC();
- if (c == 'y') {
- PRINTF("Okay");
- } else {
- PRINTF("Are you sure? Check again!");
- for (c = 0; c < 30; c++) {
- xLEDs[i] = !xLEDs[i];
- wait(0.2);
- }
- xLEDs[i] = 0;
- put_rn();
- PRINTF("Is $c LED on? -> enter y/n", c);
- put_rn();
- c = GETC();
- if (c == 'y') {
- PRINTF("Looks okay");
- } else {
- PRINTF("Please check LED line");
- }
- }
- put_rn();
- xLEDs[i] = 1;
-}
-
-// ---------- Program starts here! ---------------------------------------------------------------
-void debug_interface(void)
-{
- char c;
- char *ptr;
- uint8_t quitflag;
-
- BAUD(BAUD_RATE);
- put_rn();
- put_rn();
- PRINTF("%s [Help:'?' key]", mon_msg);
- put_rn();
- for (;;) {
- put_r();
- PUTC('>');
- ptr = linebuf;
- get_line(ptr, sizeof(linebuf));
- switch (*ptr++) {
- //---------------------------------------------------------------------------------
- // Debug Step1
- //---------------------------------------------------------------------------------
- case '1' :
- put_r();
- PRINTF("Enter Step1: no connection all pins");
- put_rn();
- quitflag = 0;
- for (; quitflag != 0xff;) {
- PRINTF("1>");
- ptr = linebuf;
- get_line(ptr, buf_size);
- put_r();
- switch(*ptr++) {
- case 'l' :
- #if 0
- myledR = 0;
- PRINTF("Is Red LED on? -> enter y/n");
- put_rn();
- c = GETC();
- if (c == 'y') {
- PRINTF("Okay");
- } else {
- PRINTF("Are you sure? Check again!");
- for (c = 0; c < 30; c++) {
- myledR = !myledR;
- wait(0.2);
- }
- myledR = 0;
- put_rn();
- PRINTF("Is Red LED on? -> enter y/n");
- put_rn();
- c = GETC();
- if (c == 'y') {
- PRINTF("Looks okay");
- } else {
- PRINTF("Please check LED line");
- }
- }
- put_rn();
- myledR = 1;
- #else
- for (uint8_t i =0; i < 4; i++){
- xLEDs[i] = 1;
- }
- for (uint8_t i =0; i < 4; i++){
- check_leds(i);
- }
- #endif
- break;
- case 'b' :
- PRINTF("Please push [USER] button -> You can see LED on if you push a button");
- put_rn();
- PRINTF("Hit any key to exit");
- while (true) {
- if (xUSER_SWITCH[0] == 0) {
- xLEDs[3]= 0;
- } else {
- xLEDs[3] = 1;
- }
- if (READABLE()) {
- break;
- }
- }
- GETC();
- put_rn();
- PRINTF("Please push [USER] button -> You can see LED on if you push a button");
- put_rn();
- PRINTF("Hit any key to exit");
- while (true) {
- if (xUSER_SWITCH[1] == 0) {
- xLEDs[3] = 0;
- } else {
- xLEDs[3] = 1;
- }
- if (READABLE()) {
- break;
- }
- }
- GETC();
- put_rn();
- break;
- case 's' :
- PRINTF("----- CPU CLOCK Information -----");
- put_rn();
- c = 'f';
-// cpu_inf(&c);
- PRINTF("----- CPU TYPE Information ------");
- put_rn();
- c = 'c';
-// cpu_inf(&c);
- break;
- case '?' :
- PRINTF("l - Check LED");
- put_rn();
- PRINTF("b - Check button");
- put_rn();
- PRINTF("s - CPU system info & clock");
- put_rn();
- PRINTF("o - CPU clock output");
- put_rn();
- PRINTF("q - Return to all mode");
- put_rn();
- PRINTF("? - You know this");
- put_rn();
- break;
- case 'q' : // quit
- PRINTF("Back to all mode");
- quitflag = 0xff;
- break;
- default:
- PUTC('?');
- put_rn();
- }
- }
- put_rn();
- break;
- //---------------------------------------------------------------------------------
- // check and set RTC
- //---------------------------------------------------------------------------------
- case 't' :
- put_r();
- chk_and_set_time(ptr);
- break;
- //---------------------------------------------------------------------------------
- // help
- //---------------------------------------------------------------------------------
- case '?' :
- put_r();
- msg_hlp();
- break;
- //---------------------------------------------------------------------------------
- // Go to special command
- //---------------------------------------------------------------------------------
- case 'x' :
-// mon_hw();
- PRINTF("->Came back monitor\r\n");
- break;
- //---------------------------------------------------------------------------------
- // Go back to main()
- //---------------------------------------------------------------------------------
- case 'q' : // Quit
- PRINTF("\rReturn to main\r\n");
- //PRINTF("cannot control anymore from here\r\n");
- return;
- //---------------------------------------------------------------------------------
- // no support
- //---------------------------------------------------------------------------------
- default:
- put_r();
- PUTC('?');
- put_rn();
- break;
- }
- }
-}
-
-#endif // defined(TARGET_RZ_A1H)
--- a/debug_tools/debug_lpc1114.cpp Sun Dec 14 09:17:01 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,146 +0,0 @@
-/*
- * mbed Application program
- *
- * Copyright (c) 2010-2014 Kenji Arai / JH1PJL
- * http://www.page.sannet.ne.jp/kenjia/index.html
- * http://mbed.org/users/kenjiArai/
- * Created: May 15th, 2010
- * Spareted: June 25th, 2014 mon() & mon_hw()
- * Ported: September 22nd, 2014 from L152RE, LP1114
- * changed: October 15th, 2014 mon.cpp to debug_xxx.cpp
- * Revised: Nobember 2nd, 2014
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
- * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
- * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#if defined(TARGET_LPC1114)
-
-// Include ---------------------------------------------------------------------------------------
-#include "mbed.h"
-#include "debug_common.h"
-
-// Object ----------------------------------------------------------------------------------------
-
-// Definition ------------------------------------------------------------------------------------
-
-// RAM -------------------------------------------------------------------------------------------
-
-// ROM / Constant data ---------------------------------------------------------------------------
-
-// Function prototypes ---------------------------------------------------------------------------
-extern void cpu_inf (void);
-
-//-------------------------------------------------------------------------------------------------
-// Control Program
-//-------------------------------------------------------------------------------------------------
-// Help Massage
-void msg_hlp (void)
-{
- PRINTF(mon_msg);
- put_rn();
- PRINTF("1 - goto step1 -> no connection all pins");
- put_rn();
- PRINTF("2 - goto step2 -> connects pin_x and pin_y");
- put_rn();
- PRINTF("x - Goto HW monitor");
- put_rn();
- PRINTF("q - Return to main");
- put_rn();
-}
-
-// ---------- Program starts here! ---------------------------------------------------------------
-void debug_interface(void)
-{
- char *ptr;
- uint8_t quitflag;
-
- BAUD(BAUD_RATE);
- put_rn();
- put_rn();
- PRINTF("%s [Help:'?' key]", mon_msg);
- put_rn();
- for (;;) {
- put_r();
- PUTC('>');
- ptr = linebuf;
- get_line(ptr, sizeof(linebuf));
- switch (*ptr++) {
- //---------------------------------------------------------------------------------
- // Debug Step1
- //---------------------------------------------------------------------------------
- case '1' :
- put_r();
- PRINTF("Enter Step1: no connection all pins");
- put_rn();
- quitflag = 0;
- for (; quitflag != 0xff;) {
- PRINTF("1>");
- ptr = linebuf;
- get_line(ptr, buf_size);
- put_r();
- switch(*ptr++) {
- case 's' :
- PRINTF("----- CPU CLOCK Information -----");
- put_rn();
- get_freq(1);
- PRINTF("----- CPU TYPE Information ------");
- put_rn();
- cpu_inf();
- break;
- case '?' :
- PRINTF("s - CPU system info & clock");
- put_rn();
- PRINTF("q - Return to all mode");
- put_rn();
- PRINTF("? - You know this");
- put_rn();
- break;
- case 'q' : // quit
- PRINTF("Back to all mode");
- quitflag = 0xff;
- break;
- default:
- PUTC('?');
- put_rn();
- }
- }
- put_rn();
- break;
- //---------------------------------------------------------------------------------
- // help
- //---------------------------------------------------------------------------------
- case '?' :
- put_r();
- msg_hlp();
- break;
- //---------------------------------------------------------------------------------
- // Go to special command
- //---------------------------------------------------------------------------------
- case 'x' :
- mon_hw();
- PRINTF("->Came back monitor\r\n");
- break;
- //---------------------------------------------------------------------------------
- // Go back to main()
- //---------------------------------------------------------------------------------
- case 'q' : // Quit
- PRINTF("\rReturn to main\r\n");
- //PRINTF("cannot control anymore from here\r\n");
- return;
- //---------------------------------------------------------------------------------
- // no support
- //---------------------------------------------------------------------------------
- default:
- put_r();
- PUTC('?');
- put_rn();
- break;
- }
- }
-}
-
-#endif // defined(TARGET_LPC1114)
--- a/debug_tools/debug_lpc1768.cpp Sun Dec 14 09:17:01 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,224 +0,0 @@
-/*
- * mbed Application program
- *
- * Copyright (c) 2010-2014 Kenji Arai / JH1PJL
- * http://www.page.sannet.ne.jp/kenjia/index.html
- * http://mbed.org/users/kenjiArai/
- * Created: May 15th, 2010
- * Spareted: June 25th, 2014 mon() & mon_hw()
- * Ported: September 22nd, 2014 from L152RE, LP1114
- * changed: October 15th, 2014 mon.cpp to debug_xxx.cpp
- * Revised: Nobember 2nd, 2014
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
- * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
- * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#if defined(TARGET_LPC1768)
-
-// Include ---------------------------------------------------------------------------------------
-#include "mbed.h"
-#include "debug_common.h"
-
-// Object ----------------------------------------------------------------------------------------
-DigitalOut myled1(LED1);
-DigitalOut myled2(LED2);
-DigitalOut myled3(LED3);
-DigitalOut myled4(LED4);
-
-// Definition ------------------------------------------------------------------------------------
-
-// RAM -------------------------------------------------------------------------------------------
-
-// ROM / Constant data ---------------------------------------------------------------------------
-
-// Function prototypes ---------------------------------------------------------------------------
-extern void cpu_inf (void);
-
-//-------------------------------------------------------------------------------------------------
-// Control Program
-//-------------------------------------------------------------------------------------------------
-// Help Massage
-void msg_hlp (void)
-{
- PRINTF(mon_msg);
- put_rn();
- PRINTF("1 - goto step1 -> no connection all pins");
- put_rn();
- PRINTF("2 - goto step2 -> connects pin_x and pin_y");
- put_rn();
- PRINTF("t - Check and set RTC");
- put_rn();
- PRINTF("x - Goto HW monitor");
- put_rn();
- PRINTF("q - Return to main");
- put_rn();
-}
-
-// ---------- Program starts here! ---------------------------------------------------------------
-void debug_interface(void)
-{
- char c;
- char *ptr;
- uint8_t quitflag;
-
- BAUD(BAUD_RATE);
- put_rn();
- put_rn();
- PRINTF("%s [Help:'?' key]", mon_msg);
- put_rn();
- get_freq(0);
- for (;;) {
- put_r();
- PUTC('>');
- ptr = linebuf;
- get_line(ptr, sizeof(linebuf));
- switch (*ptr++) {
- //---------------------------------------------------------------------------------
- // Debug Step1
- //---------------------------------------------------------------------------------
- case '1' :
- put_r();
-#if !defined(RTOS_H)
- PRINTF("Enter Step1: no connection all pins");
- put_rn();
- quitflag = 0;
- for (; quitflag != 0xff;) {
- PRINTF("1>");
- ptr = linebuf;
- get_line(ptr, buf_size);
- put_r();
- switch(*ptr++) {
- case 'l' :
- myled1 = 1;
- wait(0.1);
- myled1 = 0;
- myled2 = 1;
- wait(0.1);
- myled2 = 0;
- myled3 = 1;
- wait(0.1);
- myled3 = 0;
- myled4 = 1;
- wait(0.1);
- myled4 = 0;
- myled1 = 1;
- wait(0.2);
- myled2 = 1;
- wait(0.2);
- myled3 = 1;
- wait(0.2);
- myled4 = 1;
- PRINTF("Is LED on? -> enter y/n");
- put_rn();
- c = GETC();
- if (c == 'y') {
- PRINTF("Okay");
- } else {
- PRINTF("Are you sure? Check again!");
- for (c = 0; c < 10; c++) {
- myled1 = !myled1;
- wait(0.1);
- myled2 = !myled2;
- wait(0.1);
- myled3 = !myled3;
- wait(0.1);
- myled4 = !myled4;
- wait(0.1);
- }
- myled1 = 1;
- myled2 = 1;
- myled3 = 1;
- myled4 = 1;
- put_rn();
- PRINTF("Is LED on? -> enter y/n");
- put_rn();
- c = GETC();
- if (c == 'y') {
- PRINTF("Looks okay");
- } else {
- PRINTF("Please check LED line");
- }
- }
- put_rn();
- myled1 = 0;
- myled2 = 0;
- myled3 = 0;
- myled4 = 0;
-#elif
- PRINTF("Not implement with RTOS");
-#endif
- break;
- case 's' :
- PRINTF("----- CPU CLOCK Information -----");
- put_rn();
- get_freq(1);
- PRINTF("----- CPU TYPE Information ------");
- put_rn();
- cpu_inf();
- break;
- case '?' :
- PRINTF("l - Check LED");
- put_rn();
- PRINTF("s - CPU system info & clock");
- put_rn();
- PRINTF("q - Return to all mode");
- put_rn();
- PRINTF("? - You know this");
- put_rn();
- break;
- case 'q' : // quit
- PRINTF("Back to all mode");
- quitflag = 0xff;
- break;
- default:
- PUTC('?');
- put_rn();
- }
- }
- put_rn();
- break;
- //---------------------------------------------------------------------------------
- // check and set RTC
- //---------------------------------------------------------------------------------
- case 't' :
- put_r();
- chk_and_set_time(ptr);
- break;
- //---------------------------------------------------------------------------------
- // help
- //---------------------------------------------------------------------------------
- case '?' :
- put_r();
- msg_hlp();
- break;
- //---------------------------------------------------------------------------------
- // Go to special command
- //---------------------------------------------------------------------------------
- case 'x' :
- mon_hw();
- PRINTF("->Came back monitor\r\n");
- break;
- //---------------------------------------------------------------------------------
- // Go back to main()
- //---------------------------------------------------------------------------------
- case 'q' : // Quit
- PRINTF("\rReturn to main\r\n");
- //PRINTF("cannot control anymore from here\r\n");
- return;
- //---------------------------------------------------------------------------------
- // no support
- //---------------------------------------------------------------------------------
- default:
- put_r();
- PUTC('?');
- put_rn();
- break;
- }
- }
-}
-
-#endif // defined(TARGET_LPC1768)
--- a/debug_tools/debug_nucleo_F4x1RE.cpp Sun Dec 14 09:17:01 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,249 +0,0 @@
-/*
- * mbed Application program
- *
- * Copyright (c) 2010-2014 Kenji Arai / JH1PJL
- * http://www.page.sannet.ne.jp/kenjia/index.html
- * http://mbed.org/users/kenjiArai/
- * Created: May 15th, 2010
- * Spareted: June 25th, 2014 mon() & mon_hw()
- * Ported: September 22nd, 2014 from L152RE, LP1114
- * changed: October 15th, 2014 mon.cpp to debug_xxx.cpp
- * Revised: Nobember 2nd, 2014
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
- * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
- * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#if defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE) || defined(TARGET_NUCLEO_L152RE)
-
-// Include ---------------------------------------------------------------------------------------
-#include "mbed.h"
-#include "debug_common.h"
-#include "CheckRTC.h"
-
-// Object ----------------------------------------------------------------------------------------
-DigitalOut myled(LED1);
-DigitalIn usr_sw(PC_13);
-
-// Definition ------------------------------------------------------------------------------------
-
-// RAM -------------------------------------------------------------------------------------------
-
-// ROM / Constant data ---------------------------------------------------------------------------
-
-// Function prototypes ---------------------------------------------------------------------------
-extern void cpu_inf( char *ptr );
-extern void port_mco1_mco2_set(void);
-extern void port_mco1_mco2_recover(void);
-
-//-------------------------------------------------------------------------------------------------
-// Control Program
-//-------------------------------------------------------------------------------------------------
-// Help Massage
-void msg_hlp (void)
-{
- PRINTF(mon_msg);
- put_rn();
- PRINTF("1 - goto step1 -> no connection all pins");
- put_rn();
- PRINTF("2 - goto step2 -> connects pin_x and pin_y");
- put_rn();
- PRINTF("t - Check and set RTC");
- put_rn();
- PRINTF("x - Goto HW monitor");
- put_rn();
- PRINTF("q - Return to main");
- put_rn();
-}
-
-// ---------- Program starts here! ---------------------------------------------------------------
-void debug_interface(void)
-{
- char c;
- char *ptr;
- uint8_t quitflag;
-
- BAUD(BAUD_RATE);
- put_rn();
- put_rn();
- PRINTF("%s [Help:'?' key]", mon_msg);
- put_rn();
- CheckRTC();
- for (;;) {
- put_r();
- PUTC('>');
- ptr = linebuf;
- get_line(ptr, sizeof(linebuf));
- switch (*ptr++) {
- //---------------------------------------------------------------------------------
- // Debug Step1
- //---------------------------------------------------------------------------------
- case '1' :
- put_r();
- PRINTF("Enter Step1: no connection all pins");
- put_rn();
- quitflag = 0;
- for (; quitflag != 0xff;) {
- PRINTF("1>");
- ptr = linebuf;
- get_line(ptr, buf_size);
- put_r();
- switch(*ptr++) {
- case 'l' :
- myled = 1;
- PRINTF("Is LED on? -> enter y/n");
- put_rn();
- c = GETC();
- if (c == 'y') {
- PRINTF("Okay");
- } else {
- PRINTF("Are you sure? Check again!");
- for (c = 0; c < 30; c++) {
- myled = !myled;
- wait(0.2);
- }
- myled = 1;
- put_rn();
- PRINTF("Is LED on? -> enter y/n");
- put_rn();
- c = GETC();
- if (c == 'y') {
- PRINTF("Looks okay");
- } else {
- PRINTF("Please check LED line");
- }
- }
- put_rn();
- myled = 0;
- break;
- case 'b' :
- PRINTF("Please push [USER] button -> You can see LED on if you push a button");
- put_rn();
- PRINTF("Hit any key to exit");
- while (true) {
- if (usr_sw == 0) {
- myled = 1;
- } else {
- myled = 0;
- }
- if (READABLE()) {
- break;
- }
- }
- GETC();
- put_rn();
- break;
- case 's' :
- PRINTF("----- CPU CLOCK Information -----");
- put_rn();
- c = 'f';
- cpu_inf(&c);
- PRINTF("----- CPU TYPE Information ------");
- put_rn();
- c = 'c';
- cpu_inf(&c);
- break;
-#if defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE)
- case 'o' :
- PRINTF("----- CPU CLOCK output from PA8 & PC9 -----");
- put_rn();
- PRINTF("Please check carefully that PA8 & PC9 are no connection!!");
- put_rn();
- PRINTF("Are you okay? [y/n]");
- put_rn();
- c = GETC();
- if (c == 'y') {
- port_mco1_mco2_set();
- PRINTF("Please measure PA8 & PC9 pins");
- put_rn();
-#if 0
- PRINTF("PA8: HSE/4");
- put_rn();
- PRINTF("PC9: SYSCLK/4");
- put_rn();
-#else
- PRINTF("PA8: HSE/1");
- put_rn();
- PRINTF("PC9: SYSCLK/2");
- put_rn();
-#endif
- PRINTF("If you finish, hit anykey");
- put_rn();
- c = GETC();
- port_mco1_mco2_recover();
- PRINTF("End");
- put_rn();
- }
- break;
-#endif // defined(TARGET_NUCLEO_F401RE)
- case '?' :
- PRINTF("l - Check LED");
- put_rn();
- PRINTF("b - Check button");
- put_rn();
- PRINTF("s - CPU system info & clock");
- put_rn();
-#if defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE)
- PRINTF("o - CPU clock output");
- put_rn();
-#endif // defined(TARGET_NUCLEO_F401RE)
- PRINTF("q - Return to all mode");
- put_rn();
- PRINTF("? - You know this");
- put_rn();
- break;
- case 'q' : // quit
- PRINTF("Back to all mode");
- quitflag = 0xff;
- break;
- default:
- PUTC('?');
- put_rn();
- }
- }
- put_rn();
- break;
- //---------------------------------------------------------------------------------
- // check and set RTC
- //---------------------------------------------------------------------------------
- case 't' :
- put_r();
- chk_and_set_time(ptr);
- break;
- //---------------------------------------------------------------------------------
- // help
- //---------------------------------------------------------------------------------
- case '?' :
- put_r();
- msg_hlp();
- break;
- //---------------------------------------------------------------------------------
- // Go to special command
- //---------------------------------------------------------------------------------
- case 'x' :
- mon_hw();
- PRINTF("->Came back monitor\r\n");
- break;
- //---------------------------------------------------------------------------------
- // Go back to main()
- //---------------------------------------------------------------------------------
- case 'q' : // Quit
- PRINTF("\rReturn to main\r\n");
- //PRINTF("cannot control anymore from here\r\n");
- return;
- //---------------------------------------------------------------------------------
- // no support
- //---------------------------------------------------------------------------------
- default:
- put_r();
- PUTC('?');
- put_rn();
- break;
- }
- }
-}
-
-#endif // defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_L152RE)
--- a/debug_tools/mon_hw_LPC1114.cpp Sun Dec 14 09:17:01 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1493 +0,0 @@
-/*
- * mbed Application program for the mbed LPC1114FN28
- * Monitor program Ver.3 for only for LPC1114FN28
- *
- * Copyright (c) 2010-2014 Kenji Arai / JH1PJL
- * http://www.page.sannet.ne.jp/kenjia/index.html
- * http://mbed.org/users/kenjiArai/
- * Created: May 15th, 2010
- * release as "monitor_01" http://mbed.org/users/kenjiArai/code/monitor_01/
- * Spareted: June 25th, 2014 mon() & mon_hw()
- * Revised: Nobember 2nd, 2014
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
- * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
- * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#if defined(TARGET_LPC1114)
-
-// Include ---------------------------------------------------------------------------------------
-#include "mbed.h"
-#include "mon_hw_config.h"
-#include "mon_hw_common.h"
-
-// Object ----------------------------------------------------------------------------------------
-
-// Definition ------------------------------------------------------------------------------------
-// Define clocks
-#define __XTAL (12000000UL) // Oscillator frequency
-#define __SYS_OSC_CLK ( __XTAL) // Main oscillator frequency
-#define __IRC_OSC_CLK (12000000UL) // Internal RC oscillator frequency
-
-// RAM -------------------------------------------------------------------------------------------
-uint32_t SystemFrequency;
-
-// ROM / Constant data ---------------------------------------------------------------------------
-#if USE_MEM
-// Memory range data
-const uint32_t mem_range[][2] = { // Memory access range
- { 0x00000000, 0x00007fff }, // On-chip non-volatile memory //32KB Flash memory
- { 0x10000000, 0x10000fff }, // On-chip SRAM //4KB local RAM
- { 0x1fff0000, 0x1fff3fff }, // Boot ROM //16KB Boot ROM
- { 0x40000000, 0x4007ffff }, // IO area
- { 0x50000000, 0x501fffff } // IO area
-};
-#endif // USE_MEM
-
-char *const mon_msg = "HW monitor only for mbed LPC1114FN28 created on "__DATE__","__TIME__"";
-
-char *const xmsg0 = "Not implimented yet";
-
-char *const hmsg0 = "m - Entry Memory Mode";
-char *const hmsg1 = "m>? -> Help ";
-char *const hmsg2 = "r - Show PORT,I2C,SPI,UART & other Reg.";
-char *const hmsg3 = "r>? -> Help";
-char *const hmsg4 = "sf - System Clock";
-char *const hmsg5 = "sc - System / CPU information";
-char *const hmsg6 = "x - Special command for Debug";
-char *const hmsg7 = "q - Quit (back to called routine)";
-
-#if (USE_PORT==0)||(USE_UART==0)||(USE_SPI==0)||(USE_I2C==0)
-char *const io_port_name0 = "PIO0_";
-char *const io_port_name1 = "PIO1_";
-char *const iomsg0 = "Func->select ";
-char *const iomsg1 = "IO";
-char *const iomsg2 = "Reserved";
-char *const iomsg30 = "B0_MAT";
-char *const iomsg31 = "B1_MAT";
-char *const iomsg4 = "Std/F-md I2C";
-char *const iomsg5 = "func. R";
-char *const iomsg6 = "D-Mode";
-char *const iomsg7 = "A-Mode";
-#endif
-
-// Calculate CPU System Clock Frequency /refrence: system_LPCxx.c
-char *const fmsg0 = "Internal RC Oscillator";
-char *const fmsg1 = "Xtal Osc Clock";
-char *const fmsg2 = "Watch dog Osc Clock";
-char *const fmsg3 = "with PLL";
-char *const fmsg4 = "System Clock =";
-char *const fmsg5 = "PLL Post divider ratio =";
-char *const fmsg6 = "feedback devider =";
-char *const fmsg7 = "NO Clock ?!";
-
-#if (USE_UART==1) || (USE_SPI==1) || (USE_I2C == 1)
-char *const imsg2 = "-->Control Reg.";
-char *const imsg3 = "-->Status Reg.";
-char *const imsg4 = "-->Data Reg.";
-char *const imsg5 = "-->Clock control Reg.";
-#endif
-
-// Function prototypes ---------------------------------------------------------------------------
-
-//-------------------------------------------------------------------------------------------------
-// Control Program
-//-------------------------------------------------------------------------------------------------
-// No function
-void not_yet_impliment( void )
-{
- PRINTF(xmsg0);
- put_rn();
-}
-
-// No function
-#if (USE_MEM==0)||(USE_PORT==0)||(USE_UART==0)||(USE_SPI==0)||(USE_I2C==0)||(USE_SYS==0)
-void not_select( void )
-{
- PRINTF("Not select the function (refer mon_hw_config.h)");
- put_rn();
-}
-#endif
-
-// Help Massage
-void msg_hlp_hw (void)
-{
- PRINTF(mon_msg);
- put_rn();
- PRINTF(hmsg0);
- put_rn();
- PRINTF(hmsg1);
- put_rn();
- PRINTF(hmsg2);
- put_rn();
- PRINTF(hmsg3);
- put_rn();
- PRINTF(hmsg4);
- put_rn();
- PRINTF(hmsg5);
- put_rn();
- PRINTF(hmsg6);
- put_rn();
- PRINTF(hmsg7);
- put_rn();
-}
-
-#if USE_MEM
-char *const rmsg0 = "FLASH ";
-char *const rmsg1 = "SRAM ";
-char *const rmsg2 = "Boot ROM ";
-char *const rmsg3 = "IO Area0 ";
-char *const rmsg4 = "IO Area1 ";
-
-#include "mon_hw_mem.h"
-#endif // USE_MEM
-
-// Show 16bit register contents
-void reg_print(uint16_t size, uint16_t reg)
-{
- uint16_t i, j, k, n;
-
- if (size == 8) {
- PRINTF(" 7, 6, 5, 4, 3, 2, 1, 0");
- put_rn();
- i = 8;
- n = 0x80;
- } else if (size == 16) {
- PRINTF( "15,14,13,12,11,10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0" );
- put_rn();
- i = 16;
- n = 0x8000;
- } else {
- PRINTF("0x%08x", reg);
- return;
- }
- PUTC(' ');
- for (; i>0; i--) {
- k = n >> (size-i);
- j = reg & k;
- if (j) {
- PUTC('1');
- } else {
- PUTC('0');
- }
- PUTC(' ');
- PUTC(' ');
- }
- PRINTF(" (0x%04x)", reg);
-}
-
-#if USE_PORT
-void io_mode(uint32_t reg)
-{
- PRINTF("MODE->");
- switch (reg) {
- case 0:
- PRINTF("Inactive");
- break;
- case 1:
- PRINTF("P-DWN");
- break;
- case 2:
- PRINTF("P-UP");
- break;
- case 3:
- PRINTF("Repeater");
- break;
- }
-}
-
-void io_hys(uint32_t reg)
-{
- PRINTF("HIS->");
- switch (reg) {
- case 0:
- PRINTF("Dis");
- break;
- case 1:
- PRINTF("Ena");
- break;
- }
-}
-
-void io_od(uint32_t reg)
-{
- PRINTF("OD->");
- switch (reg) {
- case 0:
- PRINTF("no OD");
- break;
- case 1:
- PRINTF("OD");
- break;
- }
-}
-
-void io_mode_hys_od(uint32_t reg)
-{
- io_mode ((reg >> 3) & 0x3);
- put_lin();
- io_hys (( reg >> 5) & 0x1);
- put_lin();
- io_od (( reg >> 10) & 0x1);
-}
-
-// I/O Config IO0_x
-void io_config0(void)
-{
- uint32_t r0;
-
- // P0_0
- r0 = LPC_IOCON->RESET_PIO0_0;
- PRINTF("RESET_%s0(dp23)", io_port_name0);
- put_spc(1);
- reg_print( SIZE_X, r0 );
- put_spc(2);
- PRINTF( iomsg0 );
- if ((r0 & 0x7) == 0) {
- PRINTF("RESET");
- } else {
- PRINTF( iomsg1 );
- }
- put_lin();
- io_mode_hys_od( r0 );
- put_rn();
- // P0_1
- r0 = LPC_IOCON->PIO0_1;
- PRINTF("%s1(dp24)", io_port_name0);
- put_spc(3);
- reg_print( SIZE_X, r0 );
- put_spc(2);
- PRINTF( iomsg0 );
- switch (r0 & 0x7) {
- case 0:
- PRINTF(iomsg1);
- break;
- case 1:
- PRINTF("CLKOUT");
- break;
- case 2:
- PRINTF("32%s2", iomsg30);
- break;
- }
- put_lin();
- io_mode_hys_od(r0);
- put_rn();
- // P0_2
- r0 = LPC_IOCON->PIO0_2;
- PRINTF("%s2(dp25)",io_port_name0);
- put_spc(3);
- reg_print(SIZE_X, r0);
- put_spc(2);
- PRINTF(iomsg0);
- switch (r0 & 0x7) {
- case 0:
- PRINTF(iomsg1);
- break;
- case 1:
- PRINTF("SSEL0");
- break;
- case 2:
- PRINTF("16B0_CAP0");
- break;
- }
- put_lin();
- io_mode_hys_od(r0);
- put_rn();
- // P0_3
- r0 = LPC_IOCON->PIO0_3;
- PRINTF("%s3(dp26)",io_port_name0);
- put_spc(3);
- reg_print(SIZE_X, r0);
- put_spc(2);
- PRINTF(iomsg0);
- switch (r0 & 0x7) {
- case 0:
- PRINTF(iomsg1);
- break;
- }
- put_lin();
- io_mode_hys_od(r0);
- put_rn();
- // P0_4
- r0 = LPC_IOCON->PIO0_4;
- PRINTF("%s4(dp27)",io_port_name0);
- put_spc(3);
- reg_print(SIZE_X, r0);
- put_spc(2);
- PRINTF(iomsg0);
- switch (r0 & 0x7) {
- case 0:
- PRINTF(iomsg1);
- break;
- case 1:
- PRINTF("SCL");
- break;
- }
- put_lin();
- switch (( r0 >> 8 ) & 0x3) {
- case 0:
- PRINTF(iomsg4);
- break;
- case 1:
- PRINTF(iomsg1);
- break;
- case 2:
- PRINTF("Fast md");
- break;
- case 3:
- PRINTF(iomsg2);
- break;
- }
- put_rn();
- // P0_5
- r0 = LPC_IOCON->PIO0_5;
- PRINTF("%s5(dp5)",io_port_name0);
- put_spc(4);
- reg_print(SIZE_X, r0);
- put_spc(2);
- PRINTF(iomsg0);
- switch (r0 & 0x7) {
- case 0:
- PRINTF(iomsg1);
- break;
- case 1:
- PRINTF("SDA");
- break;
- }
- put_lin();
- switch ( ( r0 >> 8 ) & 0x3 ) {
- case 0:
- PRINTF(iomsg4);
- break;
- case 1:
- PRINTF(iomsg1);
- break;
- case 2:
- PRINTF("Fast md");
- break;
- case 3:
- PRINTF(iomsg2);
- break;
- }
- put_rn();
- // P0_6
- r0 = LPC_IOCON->PIO0_6;
- PRINTF("%s6(dp6)", io_port_name0);
- put_spc(4);
- reg_print(SIZE_X, r0);
- put_spc(2);
- PRINTF(iomsg0);
- switch (r0 & 0x7) {
- case 0:
- PRINTF(iomsg1);
- break;
- case 1:
- PRINTF(iomsg2);
- break;
- case 2:
- PRINTF("SCK0");
- break;
- }
- put_lin();
- io_mode_hys_od(r0);
- put_rn();
- // P0_7
- r0 = LPC_IOCON->PIO0_7;
- PRINTF("%s7(dp28)", io_port_name0);
- put_spc(3);
- reg_print(SIZE_X, r0);
- put_spc(2);
- PRINTF(iomsg0);
- switch (r0 & 0x7) {
- case 0:
- PRINTF(iomsg1);
- break;
- case 1:
- PRINTF("CTS");
- break;
- }
- put_lin();
- io_mode_hys_od(r0);
- put_rn();
- // P0_8
- r0 = LPC_IOCON->PIO0_8;
- PRINTF("%s8(dp1)", io_port_name0);
- put_spc(4);
- reg_print(SIZE_X, r0);
- put_spc(2);
- PRINTF(iomsg0);
- switch (r0 & 0x7) {
- case 0:
- PRINTF(iomsg1);
- break;
- case 1:
- PRINTF("MISO0");
- break;
- case 2:
- PRINTF("16%s0", iomsg30);
- break;
- }
- put_lin();
- io_mode_hys_od(r0);
- put_rn();
- // P0_9
- r0 = LPC_IOCON->PIO0_9;
- PRINTF("%s9(dp2)", io_port_name0);
- put_spc(4);
- reg_print(SIZE_X, r0);
- put_spc(2);
- PRINTF(iomsg0);
- switch (r0 & 0x7) {
- case 0:
- PRINTF(iomsg1);
- break;
- case 1:
- PRINTF("MOSI0");
- break;
- case 2:
- PRINTF("16%s1", iomsg30);
- break;
- }
- put_lin();
- io_mode_hys_od(r0);
- put_rn();
- // P0_10
- r0 = LPC_IOCON->SWCLK_PIO0_10;
- PRINTF("SWCLK_%s10(dp3)", io_port_name0);
- put_spc(1);
- reg_print(SIZE_X, r0);
- put_spc(2);
- PRINTF(iomsg0);
- switch (r0 & 0x7) {
- case 0:
- PRINTF("SWCLK");
- break;
- case 1:
- PRINTF(iomsg1);
- break;
- case 2:
- PRINTF("SCK0");
- break;
- case 3:
- PRINTF("16%s2", iomsg30);
- break;
- }
- put_lin();
- io_mode_hys_od(r0);
- put_rn();
- // P0_11
- r0 = LPC_IOCON->R_PIO0_11;
- PRINTF("R_%s11(dp4)", io_port_name0);
- put_spc(1);
- reg_print(SIZE_X, r0);
- put_spc(2);
- PRINTF( iomsg0 );
- switch ( r0 & 0x7 ) {
- case 0:
- PRINTF(iomsg5);
- break;
- case 1:
- PRINTF(iomsg1);
- break;
- case 2:
- PRINTF("AD0");
- break;
- case 3:
- PRINTF("32%s3", iomsg30);
- break;
- }
- put_lin();
- io_mode_hys_od(r0);
- if ( r0 & 0x80 ) {
- PRINTF(", %s", iomsg6);
- } else {
- PRINTF(", %s", iomsg7);
- }
- put_rn();
-}
-
-// I/O Config IO1_x
-void io_config1(void)
-{
- uint32_t r0;
-
- // P1_0
- r0 = LPC_IOCON->R_PIO1_0;
- PRINTF("R_%s0(dp9)", io_port_name1);
- put_spc(2);
- reg_print(SIZE_X, r0);
- put_spc(2);
- PRINTF( iomsg0 );
- switch ( r0 & 0x7 ) {
- case 0:
- PRINTF(iomsg5);
- break;
- case 1:
- PRINTF(iomsg1);
- break;
- case 2:
- PRINTF("AD1");
- break;
- case 3:
- PRINTF("32B1_CAP0");
- break;
- }
- io_mode_hys_od(r0);
- if (r0 & 0x80) {
- PRINTF(", %s", iomsg6);
- } else {
- PRINTF(", %s", iomsg7);
- }
- put_rn();
- // P1_1
- r0 = LPC_IOCON->R_PIO1_1;
- PRINTF("R_%s1(dp10)", io_port_name1);
- put_spc(1);
- reg_print(SIZE_X, r0);
- put_spc(2);
- PRINTF(iomsg0);
- switch (r0 & 0x7) {
- case 0:
- PRINTF(iomsg5);
- break;
- case 1:
- PRINTF(iomsg1);
- break;
- case 2:
- PRINTF("AD2");
- break;
- case 3:
- PRINTF("32%s0", iomsg31);
- break;
- }
- io_mode_hys_od(r0);
- if (r0 & 0x80) {
- PRINTF(", %s", iomsg6);
- } else {
- PRINTF(", %s", iomsg7);
- }
- put_rn();
- // P1_2
- r0 = LPC_IOCON->R_PIO1_2;
- PRINTF("R_%s2(dp11)", io_port_name1);
- put_spc(1);
- reg_print(SIZE_X, r0);
- put_spc(2);
- PRINTF(iomsg0);
- switch (r0 & 0x7) {
- case 0:
- PRINTF(iomsg5);
- break;
- case 1:
- PRINTF(iomsg1);
- break;
- case 2:
- PRINTF("AD3");
- break;
- case 3:
- PRINTF("32%s1", iomsg31);
- break;
- }
- io_mode_hys_od( r0 );
- if (r0 & 0x80) {
- PRINTF(", %s", iomsg6);
- } else {
- PRINTF(", %s", iomsg7);
- }
- put_rn();
- // P1_3
- r0 = LPC_IOCON->SWDIO_PIO1_3;
- PRINTF("SWDIO_%s3(dp12)",io_port_name1);
- put_spc(1);
- reg_print(SIZE_X, r0);
- put_spc(3);
- PRINTF(iomsg0);
- switch (r0 & 0x7) {
- case 0:
- PRINTF("SWDIO");
- break;
- case 1:
- PRINTF(iomsg1);
- break;
- case 2:
- PRINTF("AD4");
- break;
- case 3:
- PRINTF("32%s2", iomsg31);
- break;
- }
- io_mode_hys_od(r0);
- if (r0 & 0x80) {
- PRINTF(", %s", iomsg6);
- } else {
- PRINTF(", %s", iomsg7);
- }
- put_rn();
- // P1_4
- r0 = LPC_IOCON->PIO1_4;
- PRINTF("%s4(dp13)",io_port_name1);
- put_spc(3);
- reg_print(SIZE_X, r0);
- put_spc(2);
- PRINTF( iomsg0 );
- switch (r0 & 0x7) {
- case 0:
- PRINTF(iomsg1);
- break;
- case 1:
- PRINTF("AD5");
- break;
- case 2:
- PRINTF("32%s3", iomsg31);
- break;
- }
- put_lin();
- io_mode_hys_od(r0);
- put_rn();
- // P1_5
- r0 = LPC_IOCON->PIO1_5;
- PRINTF("%s5(dp14)",io_port_name1);
- put_spc(3);
- reg_print(SIZE_X, r0);
- put_spc(2);
- PRINTF(iomsg0);
- switch (r0 & 0x7) {
- case 0:
- PRINTF(iomsg1);
- break;
- case 1:
- PRINTF("RTS");
- break;
- case 2:
- PRINTF("32B0_CAP0");
- break;
- }
- put_lin();
- io_mode_hys_od(r0);
- put_rn();
- // P1_6
- r0 = LPC_IOCON->PIO1_6;
- PRINTF("%s6(dp15)", io_port_name1);
- put_spc(3);
- reg_print(SIZE_X, r0);
- put_spc(2);
- PRINTF(iomsg0);
- switch (r0 & 0x7) {
- case 0:
- PRINTF(iomsg1);
- break;
- case 1:
- PRINTF("RXD");
- break;
- case 2:
- PRINTF( "32%s0", iomsg30 );
- break;
- }
- put_lin();
- io_mode_hys_od( r0 );
- put_rn();
- // P1_7
- r0 = LPC_IOCON->PIO1_7;
- PRINTF("%s7(dp16)", io_port_name1);
- put_spc(3);
- reg_print(SIZE_X, r0);
- put_spc(2);
- PRINTF(iomsg0);
- switch (r0 & 0x7) {
- case 0:
- PRINTF(iomsg1);
- break;
- case 1:
- PRINTF("TXD");
- break;
- case 2:
- PRINTF("32%s1", iomsg30);
- break;
- }
- put_lin();
- io_mode_hys_od(r0);
- put_rn();
- // P1_8
- r0 = LPC_IOCON->PIO1_8;
- PRINTF("%s8(dp17)", io_port_name1);
- put_spc(3);
- reg_print(SIZE_X, r0);
- put_spc(2);
- PRINTF(iomsg0);
- switch (r0 & 0x7) {
- case 0:
- PRINTF(iomsg1);
- break;
- case 1:
- PRINTF("32%s1", iomsg30);
- break;
- }
- put_lin();
- io_mode_hys_od(r0);
- put_rn();
- // P1_9
- r0 = LPC_IOCON->PIO1_9;
- PRINTF("%s9(dp18)", io_port_name1);
- put_spc(3);
- reg_print(SIZE_X, r0);
- put_spc(2);
- PRINTF(iomsg0);
- switch (r0 & 0x7) {
- case 0:
- PRINTF(iomsg1);
- break;
- case 1:
- PRINTF("16%s0", iomsg31);
- break;
- case 2:
- PRINTF("MOSI1");
- break;
- }
- put_lin();
- io_mode_hys_od(r0);
- put_rn();
-}
-#endif // USE_PORT
-
-#if USE_SPI
-void spi_reg(int no)
-{
- uint32_t n, r0, r1 ,r2, r3, r4, r5, r6, r7, r8;
-
- if (no == SPI_0) {
- n = 0;
- r0 = LPC_SSP0->CR1;
- r1 = LPC_SSP0->DR;
- r2 = LPC_SSP0->SR;
- r3 = LPC_SSP0->CPSR;
- r4 = LPC_SSP0->IMSC;
- r5 = LPC_SSP0->RIS;
- r6 = LPC_SSP0->MIS;
- r7 = LPC_SSP0->ICR;
- r8 = LPC_SSP0->CR0;
- } else if (no == SPI_1) {
- n = 1;
- r0 = LPC_SSP1->CR1;
- r1 = LPC_SSP1->DR;
- r2 = LPC_SSP1->SR;
- r3 = LPC_SSP1->CPSR;
- r4 = LPC_SSP1->IMSC;
- r5 = LPC_SSP1->RIS;
- r6 = LPC_SSP1->MIS;
- r7 = LPC_SSP1->ICR;
- r8 = LPC_SSP1->CR0;
- } else {
- return;
- }
- PRINTF("Show SSP%1d(SPI%1d) Registers", n, n);
- put_rn();
- PRINTF("CR0");
- PRINTF(imsg2);
- reg_print(SIZE8, r8);
- put_rn();
- PRINTF("CR1");
- PRINTF(imsg2);
- reg_print(SIZE8, r0);
- put_rn();
- PRINTF("DR");
- PRINTF(imsg4);
- reg_print(SIZE8, r1);
- put_rn();
- PRINTF("SR");
- PRINTF(imsg3);
- reg_print(SIZE8, r2);
- put_rn();
- PRINTF("CPSR");
- PRINTF(imsg5);
- reg_print(SIZE8, r3);
- put_rn();
- PRINTF("IMSC");
- PRINTF(imsg2);
- reg_print(SIZE8, r4);
- put_rn();
- PRINTF("RIS");
- PRINTF(imsg3);
- reg_print(SIZE8, r5);
- put_rn();
- PRINTF("MIS");
- PRINTF(imsg3);
- reg_print(SIZE8, r6);
- put_rn();
- PRINTF("ICR");
- PRINTF(imsg2);
- reg_print(SIZE8, r7);
- put_rn();
-}
-#endif //USE_SPI
-
-#if USE_UART
-void uart_reg(void)
-{
- uint32_t r0,r1,r2,r3,r4,r5,r6;
-
- // clear LCR[DLAB] to read registers
- LPC_UART->LCR &= ~(1 << 7);
- r0 = LPC_UART->RBR;
- r1 = LPC_UART->IER;
- r2 = LPC_UART->IIR;
- r3 = LPC_UART->TER;
- // set LCR[DLAB] to enable writing to divider registers
- LPC_UART->LCR |= (1 << 7);
- r4 = LPC_UART->DLL;
- r5 = LPC_UART->DLM;
- r6 = LPC_UART->FDR;
- // clear LCR[DLAB]
- LPC_UART->LCR &= ~(1 << 7);
- // Print each register
- PRINTF("Show UART Registers");
- put_rn();
- PRINTF("RBR");
- PRINTF(imsg4);
- reg_print(SIZE8, r0);
- put_rn();
- PRINTF("THR--Write only");
- PRINTF(imsg4);
- put_rn();
- PRINTF("DLL");
- PRINTF(imsg2);
- reg_print(SIZE8, r4);
- put_rn();
- PRINTF("DLM");
- PRINTF(imsg2);
- reg_print(SIZE8, r5);
- put_rn();
- PRINTF("IER");
- PRINTF(imsg2);
- reg_print(SIZE8, r1);
- put_rn();
- PRINTF("IIR");
- PRINTF(imsg2);
- reg_print(SIZE8, r2);
- put_rn();
- PRINTF("FCR--Write only");
- PRINTF(imsg2);
- put_rn();
- PRINTF("LCR,MCR,MSR,SCR,ACR--Not support");
- put_rn();
- PRINTF("FDR");
- PRINTF(imsg2);
- reg_print(SIZE8, r6);
- put_rn();
- PRINTF("TER");
- PRINTF(imsg3);
- reg_print(SIZE8, r3);
- put_rn();
- PRINTF("RS485CTRL,485ADRMATCH,485DLY--Not support");
- put_rn();
-}
-#endif //USE_UART
-
-//#if USE_SYS
-void cpu_inf (void)
-{
- unsigned long m1, m2;
-
- m1 = SCB->CPUID;
- m2 = (m1 >> 24);
- if (m2 == 0x41) {
- put_r();
- PRINTF("CPU = ARM ");
- } else {
- put_r();
- PRINTF("CPU = NOT ARM ");
- }
- m2 = (m1 >> 4) & 0xfff;
- if (m2 == 0xc23) {
- PRINTF("Cortex-M3");
- put_rn();
- } else if (m2 == 0xc20) {
- PRINTF("Cortex-M0");
- put_rn();
- } else {
- PRINTF("NOT Cortex-M3,M0");
- put_rn();
- }
- m2 = (m1 >> 20) & 0x0f;
- PRINTF("Variant:%x", m2);
- put_rn();
- m2 = m1 & 0x7;
- PRINTF("Revision:%x", m2);
- put_rn();
-#if 0
- // unique ID
- // http://nemuisan.blog.bai.ne.jp/?eid=192845
- m1 = *(__IO uint32_t *)((uint32_t)0x1FFF7A22);
- PRINTF("Unique device ID(94bits):(1) 0x%08x ", m1);
- m1 = *(__IO uint32_t *)((uint32_t)0x1FFF7A26);
- PRINTF("(2) 0x%08x ", m1);
- m1 = *(__IO uint32_t *)((uint32_t)0x1FFF7A2A);
- PRINTF( "(3) 0x%08x", m1 );
- put_rn();
-// m1 = DBGMCU->IDCODE;
-// PRINTF( "DBG ID: 0x%08x", m1 );
-#endif
-}
-
-// Calculate CPU System Clock Frequency
-void get_freq(int pr)
-{
- uint32_t wdt_osc = 0, pll_fct0 = 0, pll_fct1 = 0;
-
- // Determine clock frequency according to clock register values
- switch ((LPC_SYSCON->WDTOSCCTRL >> 5) & 0x0F) {
- case 0:
- wdt_osc = 400000;
- break;
- case 1:
- wdt_osc = 500000;
- break;
- case 2:
- wdt_osc = 800000;
- break;
- case 3:
- wdt_osc = 1100000;
- break;
- case 4:
- wdt_osc = 1400000;
- break;
- case 5:
- wdt_osc = 1600000;
- break;
- case 6:
- wdt_osc = 1800000;
- break;
- case 7:
- wdt_osc = 2000000;
- break;
- case 8:
- wdt_osc = 2200000;
- break;
- case 9:
- wdt_osc = 2400000;
- break;
- case 10:
- wdt_osc = 2600000;
- break;
- case 11:
- wdt_osc = 2700000;
- break;
- case 12:
- wdt_osc = 2900000;
- break;
- case 13:
- wdt_osc = 3100000;
- break;
- case 14:
- wdt_osc = 3200000;
- break;
- case 15:
- wdt_osc = 3400000;
- break;
- }
- wdt_osc /= ((LPC_SYSCON->WDTOSCCTRL & 0x1F) << 1) + 2;
- put_r();
- switch (LPC_SYSCON->MAINCLKSEL & 0x03) {
- case 0: // Internal RC oscillator
- SystemCoreClock = __IRC_OSC_CLK;
- if(pr) {
- PRINTF("%s = %dHz", fmsg0, SystemCoreClock);
- }
- break;
- case 1: // Input Clock to System PLL
- switch (LPC_SYSCON->SYSPLLCLKSEL & 0x03) {
- case 0: // Internal RC oscillator
- SystemCoreClock = __IRC_OSC_CLK;
- if(pr) {
- PRINTF("%s = %dHz", fmsg0, SystemCoreClock);
- }
- break;
- case 1: // System oscillator
- SystemCoreClock = __SYS_OSC_CLK;
- if(pr) {
- PRINTF("%s = %dHz", fmsg1, SystemCoreClock );
- }
- break;
- case 2: // WDT Oscillator
- SystemCoreClock = wdt_osc;
- if(pr) {
- PRINTF("%s = %dHz", fmsg2, wdt_osc );
- }
- break;
- case 3: // Reserved
- SystemCoreClock = 0;
- if(pr) {
- PRINTF(fmsg7);
- }
- break;
- }
- break;
- case 2: // WDT Oscillator
- SystemCoreClock = wdt_osc;
- if(pr) {
- PRINTF("%s = %dHz", fmsg2, wdt_osc );
- }
- break;
- case 3: // System PLL Clock Out
- switch (LPC_SYSCON->SYSPLLCLKSEL & 0x03) {
- case 0: // Internal RC oscillator
- if (LPC_SYSCON->SYSPLLCTRL & 0x180) {
- SystemCoreClock = __IRC_OSC_CLK;
- if(pr) {
- PRINTF("%s = %dHz", fmsg0, SystemCoreClock);
- }
- } else {
- pll_fct0 = (LPC_SYSCON->SYSPLLCTRL & 0x01F) + 1;
- pll_fct1 = (LPC_SYSCON->SYSPLLCTRL & 0x060) >> 5UL;
- SystemCoreClock = __IRC_OSC_CLK * pll_fct0;
- if(pr) {
- PRINTF("Use Internal RC = %dHz", __IRC_OSC_CLK);
- put_rn();
- PRINTF("%s %s = %dHz", fmsg0, fmsg3, SystemCoreClock);
- put_rn();
- PRINTF("%s %d, %s %d", fmsg5, pll_fct1, fmsg6, pll_fct0);
- }
- }
- break;
- case 1: // System oscillator
- if (LPC_SYSCON->SYSPLLCTRL & 0x180) {
- SystemCoreClock = __SYS_OSC_CLK;
- if(pr) {
- PRINTF("%s = %dHz", fmsg1, SystemCoreClock );
- }
- } else {
- pll_fct0 = (LPC_SYSCON->SYSPLLCTRL & 0x01F) + 1;
- pll_fct1 = (LPC_SYSCON->SYSPLLCTRL & 0x060) >> 5UL;
- SystemCoreClock = __SYS_OSC_CLK * pll_fct0;
- if(pr) {
- PRINTF("Use XTAL = %dHz", __XTAL);
- put_rn();
- PRINTF("%s %s = %dHz", fmsg1, fmsg3, SystemCoreClock);
- put_rn();
- PRINTF("%s %d, %s %d", fmsg5, pll_fct1, fmsg6, pll_fct0);
- }
- }
- break;
- case 2: // WDT Oscillator
- if (LPC_SYSCON->SYSPLLCTRL & 0x180) {
- SystemCoreClock = wdt_osc;
- if(pr) {
- PRINTF("%s = %dHz", fmsg2, wdt_osc );
- }
- } else {
- pll_fct0 = (LPC_SYSCON->SYSPLLCTRL & 0x01F) + 1;
- pll_fct1 = (LPC_SYSCON->SYSPLLCTRL & 0x060) >> 5UL;
- SystemCoreClock = wdt_osc * pll_fct0;
- if(pr) {
- PRINTF("Use WDT OSC = %dHz", wdt_osc);
- put_rn();
- PRINTF("%s %s = %dHz", fmsg2, fmsg3, SystemCoreClock);
- put_rn();
- PRINTF("%s %d, %s %d", fmsg5, pll_fct1, fmsg6, pll_fct0);
- }
- }
- break;
- case 3: // Reserved
- SystemCoreClock = 0;
- if(pr) {
- PRINTF("fmsg7");
- }
- break;
- }
- break;
- }
- SystemCoreClock /= LPC_SYSCON->SYSAHBCLKDIV;
- if(pr) {
- put_rn();
- PRINTF("%s %dHz", fmsg4, SystemCoreClock);
- put_rn();
- }
-}
-//#endif //USE_SYS
-
-#if USE_I2C
-void i2c_io_reg (void)
-{
- uint32_t r0;
-
- PRINTF("<Show IO Pin>");
- put_rn();
- // P0_4
- r0 = LPC_IOCON->PIO0_4;
- reg_print(SIZE_X, r0);
- put_spc(2);
- PRINTF("%s4(dp27)",io_port_name0);
- put_spc(2);
- PRINTF(iomsg0);
- switch (r0 & 0x7) {
- case 0:
- PRINTF(iomsg1);
- break;
- case 1:
- PRINTF("SCL");
- break;
- }
- put_lin();
- switch (( r0 >> 8 ) & 0x3) {
- case 0:
- PRINTF(iomsg4);
- break;
- case 1:
- PRINTF(iomsg1);
- break;
- case 2:
- PRINTF("Fast md");
- break;
- case 3:
- PRINTF(iomsg2);
- break;
- }
- put_rn();
- // P0_5
- r0 = LPC_IOCON->PIO0_5;
- reg_print( SIZE_X, r0 );
- put_spc(2);
- PRINTF("%s5(dp5)",io_port_name0);
- put_spc(3);
- PRINTF(iomsg0);
- switch (r0 & 0x7) {
- case 0:
- PRINTF(iomsg1);
- break;
- case 1:
- PRINTF("SDA");
- break;
- }
- put_lin();
- switch ((r0 >> 8 ) & 0x3) {
- case 0:
- PRINTF(iomsg4);
- break;
- case 1:
- PRINTF(iomsg1);
- break;
- case 2:
- PRINTF("Fast md");
- break;
- case 3:
- PRINTF(iomsg2);
- break;
- }
- put_rn();
-}
-
-void i2c_reg (void)
-{
- uint32_t r0,r1,r2,r3,r4,r5,r6,r7;
-
- r0 = LPC_I2C->CONSET;
- r1 = LPC_I2C->STAT;
- r2 = LPC_I2C->DAT;
- r3 = LPC_I2C->SCLH;
- r4 = LPC_I2C->SCLL;
- r5 = LPC_I2C->CONCLR;
- r6 = LPC_I2C->MMCTRL;
- r7 = LPC_I2C->DATA_BUFFER;
-
- PRINTF("<Show I2C Registers>");
- put_rn();
- reg_print(SIZE8, r0);
- put_spc(2);
- PRINTF("CONSET");
- PRINTF(imsg2);
- put_rn();
- reg_print(SIZE8, r1);
- put_spc(2);
- PRINTF("STAT");
- PRINTF(imsg3);
- put_rn();
- reg_print(SIZE8, r2);
- put_spc(2);
- PRINTF("DAT");
- PRINTF(imsg4);
- put_rn();
- put_spc(2);
- PRINTF("ADR0--Not support");
- put_rn();
- reg_print(SIZE8, r3);
- put_spc(2);
- PRINTF("SCLH");
- PRINTF(imsg2);
- put_rn();
- reg_print(SIZE8, r4);
- put_spc(2);
- PRINTF("SCLL");
- PRINTF(imsg2);
- put_rn();
- reg_print(SIZE8, r5);
- put_spc(2);
- PRINTF("CONCLR");
- PRINTF(imsg2);
- put_rn();
- reg_print(SIZE8, r6);
- put_spc(2);
- PRINTF("MMCTRL");
- PRINTF(imsg2);
- put_rn();
- put_spc(2);
- PRINTF("ADR1,2,3--Not support");
- put_rn();
- reg_print(SIZE8, r7);
- put_spc(2);
- PRINTF("DATA_BUFFER");
- PRINTF(imsg5);
- put_rn();
- put_spc(2);
- PRINTF("MASK0,1,2,3--Not support");
- put_rn();
-}
-
-void i2c_freq (void)
-{
- uint32_t r0,r1;
-
- r0 = LPC_I2C->SCLH;
- r1 = LPC_I2C->SCLL;
- get_freq(0);
- PRINTF("<I2C Status>");
- put_rn();
- PRINTF("Freq. = I2CPCLK/(SCLH+SCLL) = %d/(%d+%d) = %d Hz",
- SystemCoreClock, r0, r1, SystemCoreClock/(r0+r1));
- put_rn();
- r0 = LPC_I2C->CONSET;
- PRINTF("I2C I/F ");
- if ( r0 & 0x40 ) {
- PRINTF("Enabled");
- } else {
- PRINTF("disabled");
- }
- put_rn();
-}
-#endif
-
-//-------------------------------------------------------------------------------------------------
-// Monitor Main Program
-//-------------------------------------------------------------------------------------------------
-int mon_hw (void)
-{
- char *ptr;
-
- put_r();
- PRINTF("%s [Help:'?' key]", mon_msg);
- put_rn();
-#if USE_SYS
- get_freq(0);
-#endif //USE_SYS
- for (;;) {
- put_r();
- PUTC('>');
- ptr = linebuf;
- get_line(ptr, buf_size);
- switch (*ptr++) {
- //---------------------------------------------------------------------------------
- // Memory
- //---------------------------------------------------------------------------------
- case 'm' :
-#if USE_MEM
- mem_inf(ptr);
- put_rn();
- break;
-#else
- not_select();
-#endif // USE_MEM
- //---------------------------------------------------------------------------------
- // Register
- //---------------------------------------------------------------------------------
- case 'r' :
- uint8_t r_flg;
- put_r();
- PRINTF("Reg. Mode p,u,i,s,t,a,d,l,w,c & ?");
- put_rn();
- r_flg = 0;
- for (; r_flg != 0xff;) {
- PRINTF("r>");
- ptr = linebuf;
- get_line(ptr, buf_size);
- put_r();
- switch(*ptr++) {
- case 'p' :
-#if USE_PORT
- put_r();
- switch(*ptr++) {
- case '0' :
- io_config0();
- break;
- case '1' :
- io_config1();
- break;
- case '*' :
- io_config0();
- put_rn();
- io_config1();
- break;
- case '?' :
- default:
- PRINTF("Enter p0,p1 and p* for all");
- put_rn();
- }
-#else
- not_select();
-#endif // USE_PORT
- break;
- case 'u' :
-#if USE_UART
- uart_reg();
-#else
- not_select();
-#endif // USE_UART
- break;
- case 'i' :
-#if USE_I2C
- put_r();
- i2c_io_reg();
- i2c_reg();
- i2c_freq();
-#else
- not_select();
-#endif // USE_I2C
- break;
- case 's' :
-#if USE_SPI
- switch(*ptr++) {
- case '0' :
- spi_reg(SPI_0);
- break;
- case '1' :
- spi_reg(SPI_1);
- break;
- case '*' :
- spi_reg(SPI_0);
- put_rn();
- spi_reg( SPI_1 );
- break;
- case '?' :
- default:
- PRINTF("Enter s0,s1 and s* for all");
- put_rn();
- }
-#else
- not_select();
-#endif // USE_SPI
- break;
- case 't' : //
- not_yet_impliment();
- break;
- case 'a' : //
- not_yet_impliment();
- break;
- case 'd' : //
- not_yet_impliment();
- break;
- case 'w' : //
- not_yet_impliment();
- break;
- case 'l' : //
- not_yet_impliment();
- break;
- case 'c' : //
- not_yet_impliment();
- break;
- case 'x' : //
- not_yet_impliment();
- break;
- case 'y' : //
- not_yet_impliment();
- break;
- case 'q' : // quit
- r_flg = 0xff;
- break;
- case '?' :
- PRINTF("p - I/O Pin Config");
- put_rn();
- PRINTF("u - UART");
- put_rn();
- PRINTF("i - I2C");
- put_rn();
- PRINTF("s - SPI");
- put_rn();
- PRINTF("t - TIMER");
- put_rn();
- PRINTF("a - ADC");
- put_rn();
- PRINTF("d - DAC");
- put_rn();
- PRINTF("l - LDC");
- put_rn();
- PRINTF("w - WWDG");
- put_rn();
- PRINTF("c - COMP");
- put_rn();
- PRINTF("q - Exit mode");
- put_rn();
- break;
- default:
- PUTC('?');
- put_rn();
- }
- }
- PRINTF("Return to All Mode");
- put_rn();
- break;
- //---------------------------------------------------------------------------------
- // System
- //---------------------------------------------------------------------------------
- case 's' : // System related information
-#if USE_SYS
- switch (*ptr++) {
- case 'f' : // sc - show system clock frequency
- get_freq(1);
- break;
- case 'c' : // sc - show system CPU information
- cpu_inf();
- break;
- case '?' :
- default:
- put_r();
- PRINTF("sc - System CPU information");
- put_rn();
- PRINTF("sf - System Clock");
- put_rn();
- break;
- }
-#else
- not_select();
-#endif // USE_SYS
- break;
- //---------------------------------------------------------------------------------
- // Help
- //---------------------------------------------------------------------------------
- case '?' :
- put_r();
- msg_hlp_hw();
- break;
- //---------------------------------------------------------------------------------
- // Return to main routine
- //---------------------------------------------------------------------------------
- case 'q' : // Quit
- PRINTF("\rReturn to monitor ");
- return 0;
- //---------------------------------------------------------------------------------
- // Special command for DEBUG
- //---------------------------------------------------------------------------------
- case 'x' :
- not_yet_impliment();
- break;
- //---------------------------------------------------------------------------------
- // no support
- //---------------------------------------------------------------------------------
- default:
- PUTC('?');
- put_rn();
- break;
- }
- }
-}
-
-#endif // defined(TARGET_LPC1114)
--- a/debug_tools/mon_hw_LPC1768.cpp Sun Dec 14 09:17:01 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1839 +0,0 @@
-/*
- * mbed Application program for the mbed LPC1768 Board
- * Monitor program Ver.3 for only for LPC1768
- *
- * Copyright (c) 2010-2014 Kenji Arai / JH1PJL
- * http://www.page.sannet.ne.jp/kenjia/index.html
- * http://mbed.org/users/kenjiArai/
- * Started: May 9th, 2010
- * Created: May 15th, 2010
- * release as "monitor_01" http://mbed.org/users/kenjiArai/code/monitor_01/
- * restart: September 22nd, 2014
- * Revised: Nobember 2nd, 2014
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
- * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
- * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#if defined(TARGET_LPC1768)
-
-// Include ---------------------------------------------------------------------------------------
-#include "mbed.h"
-#include "mon_hw_config.h"
-#include "mon_hw_common.h"
-
-// Object ----------------------------------------------------------------------------------------
-
-// Definition ------------------------------------------------------------------------------------
-// Define clocks
-#define XTAL (12000000UL) // Oscillator frequency
-#define OSC_CLK ( XTAL) // Main oscillator frequency
-#define RTC_CLK ( 32000UL) // RTC oscillator frequency
-#define IRC_OSC ( 4000000UL) // Internal RC oscillator frequency
-
-// RAM -------------------------------------------------------------------------------------------
-uint32_t SystemFrequency;
-
-// ROM / Constant data ---------------------------------------------------------------------------
-#if USE_MEM
-// Memory range data
-const uint32_t mem_range[][2] = { // Memory access range
- { 0x00000000, 0x0007ffff }, // On-chip non-volatile memory // 512KB Flash memory
- { 0x10000000, 0x10007fff }, // On-chip SRAM // 32KB local RAM
- { 0x1fff0000, 0x1fff1fff }, // Boot ROM // 8KB Boot ROM
- { 0x2007c000, 0x2007ffff }, // On-chip SRAM // 16KB AHB SRAM
- { 0x20080000, 0x20083fff } // On-chip SRAM // 16KB AHB SRAM
-};
-#endif // USE_MEM
-
-char *const mon_msg = "HW monitor only for mbed LPC1768 created on "__DATE__","__TIME__"";
-char *const xmsg0 = "Not implimented yet";
-
-char *const hmsg0 = "m - Entry Memory Mode";
-char *const hmsg1 = "m>? -> Help ";
-char *const hmsg2 = "r - Show PORT,I2C,SPI,UART & other Reg.";
-char *const hmsg3 = "r>? -> Help";
-char *const hmsg4 = "sf - System Clock";
-char *const hmsg5 = "sc - System / CPU information";
-char *const hmsg6 = "x - Special command for Debug";
-char *const hmsg7 = "q - Quit (back to called routine)";
-
-// Function prototypes ---------------------------------------------------------------------------
-
-//-------------------------------------------------------------------------------------------------
-// Control Program
-//-------------------------------------------------------------------------------------------------
-// No function
-static void not_yet_impliment( void )
-{
- PRINTF(xmsg0);
- put_rn();
-}
-
-// No function
-#if (USE_MEM==0)||(USE_PORT==0)||(USE_UART==0)||(USE_SPI==0)||(USE_I2C==0)||(USE_SYS==0)
-static void not_select( void )
-{
- PRINTF("Not select the function (refer mon_hw_config.h)");
- put_rn();
-}
-#endif
-
-// Help Massage
-void msg_hlp_hw (void)
-{
- PRINTF(mon_msg);
- put_rn();
- PRINTF(hmsg0);
- put_rn();
- PRINTF(hmsg1);
- put_rn();
- PRINTF(hmsg2);
- put_rn();
- PRINTF(hmsg3);
- put_rn();
- PRINTF(hmsg4);
- put_rn();
- PRINTF(hmsg5);
- put_rn();
- PRINTF(hmsg6);
- put_rn();
- PRINTF(hmsg7);
- put_rn();
-}
-
-#if USE_MEM
-char *const rmsg0 = "FLASH ";
-char *const rmsg1 = "SRAM ";
-char *const rmsg2 = "Boot ROM ";
-char *const rmsg3 = "AHB SRAM0 ";
-char *const rmsg4 = "AHB SRAM1 ";
-
-#include "mon_hw_mem.h"
-#endif // USE_MEM
-
-#if USE_PORT
-void io_condition(uint32_t reg0, uint32_t reg1, uint8_t shift)
-{
- PRINTF("IO->");
- if (reg0 & (1UL << shift)) {
- PRINTF("Output=");
- } else {
- PRINTF("Input =");
- }
- if (reg1 & (1UL << shift)) {
- PUTC('1');
- } else {
- PUTC('0');
- }
-}
-
-void port_config_left(void)
-{
- uint32_t r0,r1;
-
- // p5(P0.9)
- PRINTF("p 5(P0. 9):");
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 18) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 9);
- break;
- case 1:
- PRINTF("I2STX_SDA");
- break;
- case 2:
- PRINTF("MOSI1");
- break;
- case 3:
- PRINTF("MAT2.3");
- break;
- }
- put_rn();
- // p6(P0.8)
- PRINTF("p 6(P0. 8):");
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 16) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 8);
- break;
- case 1:
- PRINTF("I2STX_WS");
- break;
- case 2:
- PRINTF("MISO1");
- break;
- case 3:
- PRINTF("MAT2.2");
- break;
- }
- put_rn();
- // p7(P0.7)
- PRINTF("p 7(P0. 7):");
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 14) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 7);
- break;
- case 1:
- PRINTF("I2STX_CLK");
- break;
- case 2:
- PRINTF("SCK1");
- break;
- case 3:
- PRINTF("MAT2.1");
- break;
- }
- put_rn();
- // p8(P0.6)
- PRINTF("p 8(P0. 6):");
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 12) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 6);
- break;
- case 1:
- PRINTF("I2SRX_SDA");
- break;
- case 2:
- PRINTF("SSEL1");
- break;
- case 3:
- PRINTF("MAT2.0");
- break;
- }
- put_rn();
- // p9(P0.0)
- PRINTF("p 9(P0. 0):");
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 0) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 0);
- break;
- case 1:
- PRINTF("RD1");
- break;
- case 2:
- PRINTF("TXD3");
- break;
- case 3:
- PRINTF("SDA1");
- break;
- }
- put_rn();
- // p10(P0.1)
- PRINTF("p10(P0. 1):");
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 2) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 1);
- break;
- case 1:
- PRINTF("TD1");
- break;
- case 2:
- PRINTF("RXD3");
- break;
- case 3:
- PRINTF("SCL1");
- break;
- }
- put_rn();
- // p11(P0.18)
- PRINTF("p11(P0.18):");
- r0 = LPC_PINCON->PINSEL1;
- r0 = (r0 >> 4) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 18);
- break;
- case 1:
- PRINTF("DCD1");
- break;
- case 2:
- PRINTF("MOSI0");
- break;
- case 3:
- PRINTF("MOSI");
- break;
- }
- put_rn();
- // p12(P0.17)
- PRINTF("p12(P0.17):");
- r0 = LPC_PINCON->PINSEL1;
- r0 = (r0 >> 2) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 17);
- break;
- case 1:
- PRINTF("CTS1");
- break;
- case 2:
- PRINTF("MISO0");
- break;
- case 3:
- PRINTF("MISO");
- break;
- }
- put_rn();
- // p13(P0.15)
- PRINTF("p13(P0.15):");
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 30) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 15);
- break;
- case 1:
- PRINTF("TXD1");
- break;
- case 2:
- PRINTF("SCK0");
- break;
- case 3:
- PRINTF("SCK");
- break;
- }
- put_rn();
- // p14(P0.16)
- PRINTF("p14(P0.16):");
- r0 = LPC_PINCON->PINSEL1;
- r0 = (r0 >> 0) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 16);
- break;
- case 1:
- PRINTF("RXD1");
- break;
- case 2:
- PRINTF("SSEL0");
- break;
- case 3:
- PRINTF("SSEL");
- break;
- }
- put_rn();
- // p15(P0.23)
- PRINTF("p15(P0.23):");
- r0 = LPC_PINCON->PINSEL1;
- r0 = (r0 >> 14) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 23);
- break;
- case 1:
- PRINTF("AD0.0");
- break;
- case 2:
- PRINTF("I2SRX_CLK");
- break;
- case 3:
- PRINTF("CAP3.0");
- break;
- }
- put_rn();
- // p16(P0.24)
- PRINTF("p16(P0.24):");
- r0 = LPC_PINCON->PINSEL1;
- r0 = (r0 >> 16) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 24);
- break;
- case 1:
- PRINTF("AD0.1");
- break;
- case 2:
- PRINTF("I2SRX_WS");
- break;
- case 3:
- PRINTF("CAP3.1");
- break;
- }
- put_rn();
- // p17(P0.25)
- PRINTF("p17(P0.25):");
- r0 = LPC_PINCON->PINSEL1;
- r0 = (r0 >> 18) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 25);
- break;
- case 1:
- PRINTF("AD0.2");
- break;
- case 2:
- PRINTF("I2SRX_SDA");
- break;
- case 3:
- PRINTF("TXD3");
- break;
- }
- put_rn();
- // p18(P0.26)
- PRINTF("p18(P0.26):");
- r0 = LPC_PINCON->PINSEL1;
- r0 = (r0 >> 20) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 26);
- break;
- case 1:
- PRINTF("AD0.3");
- break;
- case 2:
- PRINTF("AOUT");
- break;
- case 3:
- PRINTF("RXD3");
- break;
- }
- put_rn();
- // p19(P1.30)
- PRINTF("p19(P1.30):");
- r0 = LPC_PINCON->PINSEL3;
- r0 = (r0 >> 28) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO1->FIODIR;
- r1 = LPC_GPIO1->FIOPIN;
- io_condition(r0, r1, 30);
- break;
- case 1:
- PRINTF("Reserved");
- break;
- case 2:
- PRINTF("VBUS");
- break;
- case 3:
- PRINTF("AD0.4");
- break;
- }
- put_rn();
- // p20(P1.31)
- PRINTF("p20(P1.31):");
- r0 = LPC_PINCON->PINSEL3;
- r0 = (r0 >> 30) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO1->FIODIR;
- r1 = LPC_GPIO1->FIOPIN;
- io_condition(r0, r1, 31);
- break;
- case 1:
- PRINTF("Reserved");
- break;
- case 2:
- PRINTF("SCK1");
- break;
- case 3:
- PRINTF("AD0.5");
- break;
- }
- put_rn();
-}
-
-void port_config_right(void)
-{
- uint32_t r0, r1;
-
- // p30(P0.4)
- PRINTF("p30(P0. 4):");
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 8) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 4);
- break;
- case 1:
- PRINTF("I2SRX_CLK");
- break;
- case 2:
- PRINTF("RD2");
- break;
- case 3:
- PRINTF("CAP2.0");
- break;
- }
- put_rn();
- // p29(P0.5)
- PRINTF("p29(P0. 5):");
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 10) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 5);
- break;
- case 1:
- PRINTF("I2SRX_WS");
- break;
- case 2:
- PRINTF("TD2");
- break;
- case 3:
- PRINTF("CAP2.1");
- break;
- }
- put_rn();
- // p28(P0.10)
- PRINTF("p28(P0.10):");
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 20) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 10);
- break;
- case 1:
- PRINTF("TXD2");
- break;
- case 2:
- PRINTF("SDA2");
- break;
- case 3:
- PRINTF("MAT3.0");
- break;
- }
- put_rn();
- // p27(P0.11)
- PRINTF("p27(P0.11):");
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 22) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 11);
- break;
- case 1:
- PRINTF("RXD2");
- break;
- case 2:
- PRINTF("SCL2");
- break;
- case 3:
- PRINTF("MAT3.1");
- break;
- }
- put_rn();
- // p26(P2.0)
- PRINTF("p26(P2. 0):");
- r0 = LPC_PINCON->PINSEL4;
- r0 = (r0 >> 0) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO2->FIODIR;
- r1 = LPC_GPIO2->FIOPIN;
- io_condition(r0, r1, 0);
- break;
- case 1:
- PRINTF("PWM1.1");
- break;
- case 2:
- PRINTF("TXD1");
- break;
- case 3:
- PRINTF("Reserved");
- break;
- }
- put_rn();
- // p25(P2.1)
- PRINTF("p25(P2. 1):");
- r0 = LPC_PINCON->PINSEL4;
- r0 = (r0 >> 2) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO2->FIODIR;
- r1 = LPC_GPIO2->FIOPIN;
- io_condition(r0, r1, 1);
- break;
- case 1:
- PRINTF("PWM1.2");
- break;
- case 2:
- PRINTF("RXD1");
- break;
- case 3:
- PRINTF("Reserved");
- break;
- }
- put_rn();
- // p24(P2.2)
- PRINTF("p24(P2. 2):");
- r0 = LPC_PINCON->PINSEL4;
- r0 = (r0 >> 4) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO2->FIODIR;
- r1 = LPC_GPIO2->FIOPIN;
- io_condition(r0, r1, 2);
- break;
- case 1:
- PRINTF("PWM1.3");
- break;
- case 2:
- PRINTF("CTS1");
- break;
- case 3:
- PRINTF("Reserved");
- break;
- }
- put_rn();
- // p23(P2.3)
- PRINTF("p23(P2. 3):");
- r0 = LPC_PINCON->PINSEL4;
- r0 = (r0 >> 6) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO2->FIODIR;
- r1 = LPC_GPIO2->FIOPIN;
- io_condition(r0, r1, 3);
- break;
- case 1:
- PRINTF("PWM1.4");
- break;
- case 2:
- PRINTF("DCD1");
- break;
- case 3:
- PRINTF("Reserved");
- break;
- }
- put_rn();
- // p22(P2.4)
- PRINTF("p22(P2. 4):");
- r0 = LPC_PINCON->PINSEL4;
- r0 = (r0 >> 8) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO2->FIODIR;
- r1 = LPC_GPIO2->FIOPIN;
- io_condition(r0, r1, 4);
- break;
- case 1:
- PRINTF("PWM1.5");
- break;
- case 2:
- PRINTF("DSR1");
- break;
- case 3:
- PRINTF("Reserved");
- break;
- }
- put_rn();
- // p21(P2.5)
- PRINTF("p21(P2. 5):");
- r0 = LPC_PINCON->PINSEL4;
- r0 = (r0 >> 10) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO2->FIODIR;
- r1 = LPC_GPIO2->FIOPIN;
- io_condition(r0, r1, 5);
- break;
- case 1:
- PRINTF("PWM1.6");
- break;
- case 2:
- PRINTF("DTR1");
- break;
- case 3:
- PRINTF("Reserved");
- break;
- }
- put_rn();
-}
-#endif // USE_PORT
-
-//#if USE_SYS
-void cpu_inf ( void )
-{
- unsigned long m1, m2;
-
- m1 = SCB->CPUID;
- m2 = ( m1 >> 24 );
- if ( m2 == 0x41 ) {
- put_r();
- PRINTF("CPU = ARM ");
- } else {
- put_r();
- PRINTF("CPU = NOT ARM ");
- }
- m2 = ( m1 >> 4 ) & 0xfff;
- if ( m2 == 0xc23 ) {
- PRINTF("Cortex-M3");
- put_rn();
- } else {
- PRINTF("NOT Cortex-M3");
- put_rn();
- }
- m2 = ( m1 >> 20 ) & 0x0f;
- PRINTF("Variant:%x", m2);
- put_rn();
- m2 = m1 & 0x7;
- PRINTF("Revision:%x", m2);
- put_rn();
-}
-//#endif // USE_SYS
-
-// Calculate CPU System Clock Frequency
-void get_freq ( int pr )
-{
- if(pr) {
- put_r();
- PRINTF("System Clock = %dHz",SystemFrequency );
- put_rn();
- }
- if (((LPC_SC->PLL0STAT >> 24) & 3) == 3) {/* If PLL0 enabled and connected */
- if(pr) {
- PRINTF("PLL0 enabled");
- put_rn();
- }
- switch (LPC_SC->CLKSRCSEL & 0x03) {
- case 0: /* Internal RC oscillator => PLL0 */
- case 3: /* Reserved, default to Internal RC */
- if(pr) {
- PRINTF("Internal RC Oscillator");
- put_rn();
- }
- SystemFrequency = (IRC_OSC *
- (((2 * ((LPC_SC->PLL0STAT & 0x7FFF) + 1))) /
- (((LPC_SC->PLL0STAT >> 16) & 0xFF) + 1)) /
- ((LPC_SC->CCLKCFG & 0xFF)+ 1));
- break;
- case 1: /* Main oscillator => PLL0 */
- if(pr) {
- PRINTF("Xtal Osc Clock = %dHz",XTAL );
- put_rn();
- }
- SystemFrequency = (OSC_CLK *
- (((2 * ((LPC_SC->PLL0STAT & 0x7FFF) + 1))) /
- (((LPC_SC->PLL0STAT >> 16) & 0xFF) + 1)) /
- ((LPC_SC->CCLKCFG & 0xFF)+ 1));
- break;
- case 2: /* RTC oscillator => PLL0 */
- if(pr) {
- PRINTF("RTC Xtal Oscillator f = %dHz", RTC_CLK );
- put_rn();
- }
- SystemFrequency = (RTC_CLK *
- (((2 * ((LPC_SC->PLL0STAT & 0x7FFF) + 1))) /
- (((LPC_SC->PLL0STAT >> 16) & 0xFF) + 1)) /
- ((LPC_SC->CCLKCFG & 0xFF)+ 1));
- break;
- }
- } else {
- if(pr) {
- PRINTF("PLL0 disabled");
- }
- switch (LPC_SC->CLKSRCSEL & 0x03) {
- case 0: /* Internal RC oscillator => PLL0 */
- case 3: /* Reserved, default to Internal RC */
- if(pr) {
- PRINTF("Internal RC Oscillator");
- put_rn();
- }
- SystemFrequency = IRC_OSC / ((LPC_SC->CCLKCFG & 0xFF)+ 1);
- break;
- case 1: /* Main oscillator => PLL0 */
- if(pr) {
- PRINTF("Xtal Osc Clock = %dHz",XTAL );
- put_rn();
- }
- SystemFrequency = OSC_CLK / ((LPC_SC->CCLKCFG & 0xFF)+ 1);
- break;
- case 2: /* RTC oscillator => PLL0 */
- if(pr) {
- PRINTF("RTC Xtal Oscillator f = %dHz", RTC_CLK );
- put_rn();
- }
- SystemFrequency = RTC_CLK / ((LPC_SC->CCLKCFG & 0xFF)+ 1);
- break;
- }
- }
-}
-
-#if (USE_UART==1)||(USE_SPI==1)||(USE_I2C==1)
-char *const uismsg0 = "is enable";
-char *const uismsg1 = "is disable";
-char *const uismsg2 = "(mbed pins are not avairable)";
-char *const uismsg3 = "Other";
-#endif
-
-#if USE_UART
-// Show 16bit register contents
-void reg_print(uint16_t size, uint16_t reg)
-{
- uint16_t i, j, k, n;
-
- if (size == 8) {
- PRINTF(" 7, 6, 5, 4, 3, 2, 1, 0");
- put_rn();
- i = 8;
- n = 0x80;
- } else if (size == 16) {
- PRINTF( "15,14,13,12,11,10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0" );
- put_rn();
- i = 16;
- n = 0x8000;
- } else {
- PRINTF("0x%08x", reg);
- return;
- }
- PUTC(' ');
- for (; i>0; i--) {
- k = n >> (size-i);
- j = reg & k;
- if (j) {
- PUTC('1');
- } else {
- PUTC('0');
- }
- PUTC(' ');
- PUTC(' ');
- }
- PRINTF(" (0x%04x)", reg);
-}
-
-void uart_reg(uint8_t uart)
-{
- uint32_t c_lcr,c_fdr,c_dll,c_dlm;
- uint32_t divaddval,mulval,div,baud;
-
- PRINTF("<Show UART%d status>", uart);
- put_rn();
- c_lcr = c_fdr = c_dll = c_dlm = 0;
- divaddval = mulval = div = baud = 0;
- get_freq(0);
- switch (uart) {
- case 0:
- if (LPC_SC->PCONP & (1UL<<3)) {
- c_fdr = LPC_UART0->FDR;
- c_lcr = LPC_UART0->LCR;
- // set LCR[DLAB] to enable writing to divider registers
- LPC_UART0->LCR |= (1 << 7);
- c_dll = LPC_UART0->DLL;
- c_dlm = LPC_UART0->DLM;
- // clear LCR[DLAB]
- LPC_UART0->LCR &= ~(1 << 7);
- div = (LPC_SC->PCLKSEL0 >> 6) & 0x3;
- }
- break;
- case 1:
- if (LPC_SC->PCONP & (1UL<<4)) {
- c_fdr = LPC_UART1->FDR;
- c_lcr = LPC_UART1->LCR;
- // set LCR[DLAB] to enable writing to divider registers
- LPC_UART1->LCR |= (1 << 7);
- c_dll = LPC_UART1->DLL;
- c_dlm = LPC_UART1->DLM;
- // clear LCR[DLAB]
- LPC_UART1->LCR &= ~(1 << 7);
- div = (LPC_SC->PCLKSEL0 >> 8) & 0x3;
- }
- break;
- case 2:
- if (LPC_SC->PCONP & (1UL<<24)) {
- c_fdr = LPC_UART2->FDR;
- c_lcr = LPC_UART2->LCR;
- // set LCR[DLAB] to enable writing to divider registers
- LPC_UART2->LCR |= (1 << 7);
- c_dll = LPC_UART2->DLL;
- c_dlm = LPC_UART2->DLM;
- // clear LCR[DLAB]
- LPC_UART2->LCR &= ~(1 << 7);
- div = (LPC_SC->PCLKSEL1 >> 16) & 0x3;
- }
- break;
- case 3:
- if (LPC_SC->PCONP & (1UL<<25)) {
- c_fdr = LPC_UART3->FDR;
- c_lcr = LPC_UART3->LCR;
- // set LCR[DLAB] to enable writing to divider registers
- LPC_UART3->LCR |= (1 << 7);
- c_dll = LPC_UART3->DLL;
- c_dlm = LPC_UART3->DLM;
- // clear LCR[DLAB]
- LPC_UART3->LCR &= ~(1 << 7);
- div = (LPC_SC->PCLKSEL1 >> 18) & 0x3;
- }
- break;
- default:
- break;
- }
- if ((c_fdr == 0)&&(c_lcr == 0)&&(c_dll == 0)) {
- PRINTF("NOT Avairable (power off the UART module)");
- } else {
- // condition
- PRINTF("Word Length: ");
- switch ((c_lcr >> 0) & 0x03) {
- case 0:
- PUTC('5');
- break;
- case 1:
- PUTC('6');
- break;
- case 2:
- PUTC('7');
- break;
- case 3:
- PUTC('8');
- break;
- }
- PRINTF("-bit");
- put_rn();
- PRINTF("Stop bit: ");
- if (c_lcr & 0x04) {
- PUTC('1');
- } else {
- PUTC('2');
- }
- PRINTF("-bit");
- put_rn();
- PRINTF("Parity: ");
- if (c_lcr & 0x08) {
- switch ((c_lcr >> 4) & 0x03) {
- case 0:
- PRINTF("Odd");
- break;
- case 1:
- PRINTF("Even");
- break;
- case 2:
- PRINTF("Forced '1'");
- break;
- case 3:
- PRINTF("Forced '0'");
- break;
- }
- PRINTF(" parity");
- } else {
- PRINTF("None-Parity");
- }
- put_rn();
- switch (div) {
- case 0:
- div = 4;
- break;
- case 1:
- div = 1;
- break;
- case 2:
- div = 2;
- break;
- case 3:
- div = 8;
- break;
- }
- divaddval = (c_fdr >> 0) & 0x0f;
- mulval = (c_fdr >> 4) & 0x0f;
- baud = (SystemCoreClock/div)/(16 * (256 * c_dlm + c_dll) * (1 + divaddval/mulval));
- PRINTF("Baud rate: %d bps", baud);
- put_rn();
- PRINTF(" = PCLK(=Sys/div)/(16 x (256 x DLM + DLL) x (1 + DivAddVal/MulVal)");
- put_rn();
- PRINTF(" = (%d/%d)/(16 x (256 x %d + %d) x (1 + %d/%d)",
- SystemCoreClock,div,c_dlm,c_dll,divaddval,mulval);
- }
- put_rn();
-}
-
-void uart_io_print (void)
-{
- PRINTF("<Show IO Pin>");
- put_rn();
-}
-
-void uart_io_reg0 (void)
-{
- uint32_t r0;
-
- PRINTF("UART0/USBTX(P0.2),USBRX(P0.3):");
- // P0.2
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 4) & 0x03;
- if (r0 == 1) {
- PRINTF("TXD0 ");
- } else {
- PRINTF(uismsg3);
- }
- // P0.3
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 6) & 0x03;
- if (r0 == 1) {
- PRINTF(",RXD0");
- } else {
- PRINTF(",%s", uismsg3);
- }
- PRINTF("(connected to PC via USB)");
- put_rn();
-}
-
-void uart_io_reg1 (void)
-{
- uint32_t r0;
-
- PRINTF("UART1/ p13(P0.15), p14(P0.16):");
- // P0.15
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 30) & 0x03;
- if (r0 == 1) {
- PRINTF("TXD1 ");
- } else {
- PRINTF(uismsg3);
- }
- // P0.16
- r0 = LPC_PINCON->PINSEL1;
- r0 = (r0 >> 2) & 0x03;
- if (r0 == 1) {
- PRINTF(",RXD1");
- } else {
- PRINTF(",%s", uismsg3);
- }
- put_rn();
-}
-
-void uart_io_reg2 (void)
-{
- uint32_t r0;
-
- PRINTF("UART2/ p28(P0.10), p27(P0.11):");
- // P0.10
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 20) & 0x03;
- if (r0 == 1) {
- PRINTF("TXD2 ");
- } else {
- PRINTF(uismsg3);
- }
- // P0.11
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 22) & 0x03;
- if (r0 == 1) {
- PRINTF(",RXD2");
- } else {
- PRINTF(",%s", uismsg3);
- }
- put_rn();
-}
-
-void uart_io_reg3 (void)
-{
- uint32_t r0;
-
- PRINTF("UART3/ p 9(P0. 0), p10(P0. 1):");
- // P0.0
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 0) & 0x03;
- if (r0 == 2) {
- PRINTF("TXD3 ");
- } else {
- PRINTF(uismsg3);
- }
- // P0.1
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 2) & 0x03;
- if (r0 == 2) {
- PRINTF(",RXD3");
- } else {
- PRINTF(",%s", uismsg3);
- }
- put_rn();
-}
-#endif //USE_UART
-
-#if USE_SPI
-void spi_io_reg (void)
-{
- uint32_t r0;
-
- PRINTF("<Show IO Pin>");
- put_rn();
- //-----------------------------------------------------
- PRINTF("SPI /p11(P0.18),p12(P0.17),p13(P0.15):");
- // p11(P0.18)
- r0 = LPC_PINCON->PINSEL1;
- r0 = (r0 >> 4) & 0x03;
- if (r0 == 3) {
- PRINTF(",MOSI ");
- } else {
- PRINTF("%s", uismsg3);
- }
- // p12(P0.17)
- r0 = LPC_PINCON->PINSEL1;
- r0 = (r0 >> 2) & 0x03;
- if (r0 == 3) {
- PRINTF(",MISO ");
- } else {
- PRINTF(",%s", uismsg3);
- }
- // p13(P0.15)
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 30) & 0x03;
- if (r0 == 3) {
- PRINTF(",SCK ");
- } else {
- PRINTF(",%s", uismsg3);
- }
- put_rn();
- //-----------------------------------------------------
- PRINTF("SSP0/p11(P0.18),p12(P0.17),p13(P0.15):");
- // p11(P0.18)
- r0 = LPC_PINCON->PINSEL1;
- r0 = (r0 >> 4) & 0x03;
- if (r0 == 2) {
- PRINTF(",MOSI0");
- } else {
- PRINTF("%s", uismsg3);
- }
- // p12(P0.17)
- r0 = LPC_PINCON->PINSEL1;
- r0 = (r0 >> 2) & 0x03;
- if (r0 == 2) {
- PRINTF(",MISO0");
- } else {
- PRINTF(",%s", uismsg3);
- }
- // p13(P0.15)
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 30) & 0x03;
- if (r0 == 2) {
- PRINTF(",SCK0 ");
- } else {
- PRINTF(",%s", uismsg3);
- }
- put_rn();
- //-----------------------------------------------------
- PRINTF("SSP1/p 5(P0. 9),p 6(P0. 8),p 7(P0. 7):");
- // p5(P0.9)
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 18) & 0x03;
- if (r0 == 2) {
- PRINTF("MOSI1");
- } else {
- PRINTF(uismsg3);
- }
- // p6(P0.8)
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 16) & 0x03;
- if (r0 == 2) {
- PRINTF(",MISO1");
- } else {
- PRINTF(",%s", uismsg3);
- }
- // p7(P0.7)
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 14) & 0x03;
- if (r0 == 2) {
- PRINTF(",SCK1");
- } else {
- PRINTF(",%s", uismsg3);
- }
- put_rn();
-}
-
-void spi_freq (void)
-{
- uint32_t div, r0, r1;
-
- get_freq(0);
- //-----------------------------------------------------
- // SPI
- PRINTF("<Show SPI status>");
- put_rn();
- if (LPC_SC->PCONP & (1UL<<8)) {
- div = (LPC_SC->PCLKSEL0 >> 16) & 0x3;
- switch (div) {
- case 0:
- div = 4;
- break;
- case 1:
- div = 1;
- break;
- case 2:
- div = 2;
- break;
- case 3:
- div = 8;
- break;
- }
- r0 = LPC_SPI->SPCR;
- PRINTF("Data length: ");
- if (r0 & 0x04) {
- r1 = (r0 >> 8) & 0x0f;
- if (r1 == 0) {
- r1 = 16;
- }
- PRINTF("%d", r1);
- } else {
- PUTC('8');
- }
- PRINTF("bit, ");
- PRINTF("CPHA: ");
- PRINTF("%d", (r0 >> 3) & 0x01);
- PRINTF(", CPOL: ");
- PRINTF("%d", (r0 >> 4) & 0x01);
- put_rn();
- if ((r0 >> 5) & 0x01) {
- PRINTF("Master");
- } else {
- PRINTF("Slave");
- }
- PRINTF(" Mode");
- put_rn();
- if ((r0 >> 6) & 0x01) {
- PRINTF("MSB(bit7)");
- } else {
- PRINTF("LSB(Bit0)");
- }
- PRINTF(" first");
- put_rn();
- r1 = LPC_SPI->SPCCR;
- PRINTF("CLK = %d Hz", SystemCoreClock/div/r1);
- put_rn();
- PRINTF(" = PCLK_SPI(=Sys/div)/SPCCR0");
- put_rn();
- PRINTF(" = (%d/%d)/%d", SystemCoreClock, div, r1, SystemCoreClock/div/r1);
- } else {
- PRINTF("NOT Avairable (power off the module)");
- }
- put_rn();
- //-----------------------------------------------------
- // SSP0
- PRINTF("<Show SSP0 status>");
- put_rn();
- if (LPC_SC->PCONP & (1UL<<21)) {
- r0 = LPC_SSP0->CR1;
- if (r0 & 0x02) {
- div = (LPC_SC->PCLKSEL1 >> 10) & 0x3;
- switch (div) {
- case 0:
- div = 4;
- break;
- case 1:
- div = 1;
- break;
- case 2:
- div = 2;
- break;
- case 3:
- div = 8;
- break;
- }
- r1 = LPC_SSP0->CR0;
- PRINTF("SSP Mode: ");
- r1 = (r1 >> 4) & 0x03;
- switch (r1) {
- case 0:
- PRINTF("SPI");
- break;
- case 1:
- PRINTF("TI");
- break;
- case 2:
- PRINTF("Microwire");
- break;
- case 3:
- PRINTF("Not support");
- break;
- }
- put_rn();
- r1 = LPC_SSP0->CR0;
- PRINTF("Data length: ");
- PRINTF("%d", r1 & 0x0f);
- PRINTF("bit, ");
- PRINTF("CPHA: ");
- PRINTF("%d", (r1 >> 7) & 0x01);
- PRINTF(", CPOL: ");
- PRINTF("%d", (r1 >> 6) & 0x01);
- put_rn();
- if ((r0 >> 2) & 0x01) {
- PRINTF("Slave");
- } else {
- PRINTF("Master");
- }
- PRINTF(" Mode");
- put_rn();
- r1 = LPC_SSP0->CR0;
- r1 = (r1 >> 8) & 0xff;
- r0 = LPC_SSP0->CPSR;
- r0 = (r0 >> 0) & 0x0f;
- PRINTF("CLK = %d Hz", SystemCoreClock/div/(r0 * (r1+1)));
- put_rn();
- PRINTF(" = PCLK_SSP0(=Sys/div)/(CPSDVSR x [SCR+1])");
- put_rn();
- PRINTF(" = (%d/%d)/(%d x [%d + 1])", SystemCoreClock, div, r0, r1);
- } else {
- PRINTF("SSP0 is disabled");
- }
- } else {
- PRINTF("NOT Avairable (power off the module)");
- }
- put_rn();
- //-----------------------------------------------------
- // SSP1
- PRINTF("<Show SSP1 status>");
- put_rn();
- if (LPC_SC->PCONP & (1UL<<10)) {
- r0 = LPC_SSP1->CR1;
- if (r0 & 0x02) {
- div = (LPC_SC->PCLKSEL0 >> 20) & 0x3;
- switch (div) {
- case 0:
- div = 4;
- break;
- case 1:
- div = 1;
- break;
- case 2:
- div = 2;
- break;
- case 3:
- div = 8;
- break;
- }
- r1 = LPC_SSP1->CR0;
- PRINTF("SSP Mode: ");
- r1 = (r1 >> 4) & 0x03;
- switch (r1) {
- case 0:
- PRINTF("SPI");
- break;
- case 1:
- PRINTF("TI");
- break;
- case 2:
- PRINTF("Microwire");
- break;
- case 3:
- PRINTF("Not support");
- break;
- }
- put_rn();
- r1 = LPC_SSP1->CR0;
- PRINTF("Data length: ");
- PRINTF("%d", r1 & 0x0f);
- PRINTF("bit, ");
- PRINTF("CPHA: ");
- PRINTF("%d", (r1 >> 7) & 0x01);
- PRINTF(", CPOL: ");
- PRINTF("%d", (r1 >> 6) & 0x01);
- put_rn();
- if ((r0 >> 2) & 0x01) {
- PRINTF("Slave");
- } else {
- PRINTF("Master");
- }
- PRINTF(" Mode");
- put_rn();
- r1 = LPC_SSP1->CR0;
- r1 = (r1 >> 8) & 0xff;
- r0 = LPC_SSP1->CPSR;
- r0 = (r0 >> 0) & 0x0f;
- PRINTF("CLK = %d Hz", SystemCoreClock/div/(r0 * (r1+1)));
- put_rn();
- PRINTF(" = PCLK_SSP1(=Sys/div)/(CPSDVSR x [SCR+1])");
- put_rn();
- PRINTF(" = (%d/%d)/(%d x [%d + 1])", SystemCoreClock, div, r0, r1);
- } else {
- PRINTF("SSP1 is disabled");
- }
- } else {
- PRINTF("NOT Avairable (power off the module)");
- }
- put_rn();
-}
-#endif
-
-#if USE_I2C
-void i2c_io_reg (void)
-{
- uint32_t r0;
-
- PRINTF("<Show IO Pin>");
- put_rn();
- //-----------------------------------------------------
- PRINTF("I2C0/pxx(P0.27),pxx(P0.28):");
- // P0.27
- r0 = LPC_PINCON->PINSEL1;
- r0 = (r0 >> 22) & 0x03;
- if (r0 == 3) {
- PRINTF("SDA0");
- } else {
- PRINTF(uismsg3);
- }
- // P0.28
- r0 = LPC_PINCON->PINSEL1;
- r0 = (r0 >> 24) & 0x03;
- if (r0 == 3) {
- PRINTF(",SCL0");
- } else {
- PRINTF(",%s", uismsg3);
- }
- PRINTF(uismsg2);
- put_rn();
- //-----------------------------------------------------
- PRINTF("I2C1/p 9(P0. 0),p10(P0. 1):");
- // P0.0
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 0) & 0x03;
- if (r0 == 3) {
- PRINTF("SDA1");
- } else {
- PRINTF(uismsg3);
- }
- // P0.1
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 2) & 0x03;
- if (r0 == 3) {
- PRINTF(",SCL1");
- } else {
- PRINTF(",%s", uismsg3);
- }
- put_rn();
- //-----------------------------------------------------
- PRINTF("I2C1/pxx(P0.19),pxx(P0.20):");
- // P0.19
- r0 = LPC_PINCON->PINSEL1;
- r0 = (r0 >> 6) & 0x03;
- if (r0 == 3) {
- PRINTF("SDA1");
- } else {
- PRINTF(uismsg3);
- }
- // P0.20
- r0 = LPC_PINCON->PINSEL1;
- r0 = (r0 >> 8) & 0x03;
- if (r0 == 3) {
- PRINTF(",SCL1");
- } else {
- PRINTF(",%s", uismsg3);
- }
- PRINTF(uismsg2);
- put_rn();
- //-----------------------------------------------------
- PRINTF("I2C2/p28(P0.10),p27(P0.11):");
- // P0.10
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 20) & 0x03;
- if (r0 == 3) {
- PRINTF("SDA2");
- } else {
- PRINTF(uismsg3);
- }
- // P0.11
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 22) & 0x03;
- if (r0 == 3) {
- PRINTF(",SCL2");
- } else {
- PRINTF(",%s", uismsg3);
- }
- put_rn();
-}
-
-char *const msg_cal = " = I2CPCLK(=Sys/div)/(SCLH+SCLL)";
-
-void i2c_freq (void)
-{
- uint32_t r0, r1, r2, r3;
-
- get_freq(0);
- // I2C0
- r0 = LPC_I2C0->I2SCLL;
- r1 = LPC_I2C0->I2SCLH;
- r2 = LPC_I2C0->I2CONSET;
- r3 = (LPC_SC->PCLKSEL0 >> 14) & 0x3;
- switch (r3) {
- case 0:
- r3 = 4;
- break;
- case 1:
- r3 = 1;
- break;
- case 2:
- r3 = 2;
- break;
- case 3:
- r3 = 8;
- break;
- }
- PRINTF("<I2C Status>");
- put_rn();
- //-----------------------------------------------------
- PRINTF("I2C0 ");
- if (r2 & 0x40) {
- PRINTF(uismsg0);
- put_rn();
- PRINTF("CLK = %d Hz", SystemCoreClock/r3/(r0+r1));
- put_rn();
- PRINTF(msg_cal);
- put_rn();
- PRINTF(" = (%d/%d)/(%d+%d)", SystemCoreClock,r3, r0, r1);
- } else {
- PRINTF(uismsg1);
- }
- put_rn();
- //-----------------------------------------------------
- // I2C1
- r0 = LPC_I2C1->I2SCLL;
- r1 = LPC_I2C1->I2SCLH;
- r2 = LPC_I2C1->I2CONSET;
- r3 = (LPC_SC->PCLKSEL1 >> 6) & 0x3;
- switch (r3) {
- case 0:
- r3 = 4;
- break;
- case 1:
- r3 = 1;
- break;
- case 2:
- r3 = 2;
- break;
- case 3:
- r3 = 8;
- break;
- }
- PRINTF("I2C1 ");
- if (r2 & 0x40) {
- PRINTF(uismsg0);
- put_rn();
- PRINTF("CLK = %d Hz", SystemCoreClock/r3/(r0+r1));
- put_rn();
- PRINTF(msg_cal);
- put_rn();
- PRINTF(" = (%d/%d)/(%d+%d)", SystemCoreClock,r3, r0, r1);
- } else {
- PRINTF(uismsg1);
- }
- put_rn();
- //-----------------------------------------------------
- // I2C2
- r0 = LPC_I2C2->I2SCLL;
- r1 = LPC_I2C2->I2SCLH;
- r2 = LPC_I2C2->I2CONSET;
- r3 = (LPC_SC->PCLKSEL1 >> 20) & 0x3;
- switch (r3) {
- case 0:
- r3 = 4;
- break;
- case 1:
- r3 = 1;
- break;
- case 2:
- r3 = 2;
- break;
- case 3:
- r3 = 8;
- break;
- }
- PRINTF("I2C2 ");
- if (r2 & 0x40) {
- PRINTF(uismsg0);
- put_rn();
- PRINTF("CLK = %d Hz", SystemCoreClock/r3/(r0+r1));
- put_rn();
- PRINTF(msg_cal);
- put_rn();
- PRINTF(" = (%d/%d)/(%d+%d)", SystemCoreClock,r3, r0, r1);
- } else {
- PRINTF(uismsg1);
- }
- put_rn();
-}
-#endif
-
-//-----------------------------------------------------------------------------
-// Monitor Main Program
-//-----------------------------------------------------------------------------
-int mon_hw(void)
-{
- char *ptr;
-
- put_r();
- PRINTF("%s [Help:'?' key]", mon_msg);
- put_rn();
- get_freq(0);
- for (;;) {
- put_r();
- PUTC('>');
- ptr = linebuf;
- get_line(ptr, buf_size);
- put_r();
- switch (*ptr++) {
- //---------------------------------------------------------------------------------
- // Memory
- //---------------------------------------------------------------------------------
- case 'm' :
-#if USE_MEM
- mem_inf(ptr);
- put_rn();
-#else
- not_select();
-#endif // USE_MEM
- break;
- //--------------------------------------------------------------------------------------
- // Register
- //--------------------------------------------------------------------------------------
- case 'r' :
- uint8_t r_flg;
- put_r();
- PRINTF("Reg. Mode p,u,i,s,t,a,d,l,w,c & ?");
- put_rn();
- r_flg = 0;
- for (; r_flg != 0xff;) {
- PRINTF("r>");
- ptr = linebuf;
- get_line(ptr, buf_size);
- put_r();
- switch(*ptr++) {
- case 'p' :
-#if USE_PORT
- put_r();
- switch(*ptr++) {
- case 'l' :
- port_config_left();
- break;
- case 'r' :
- port_config_right();
- break;
- case '*' :
- port_config_left();
- port_config_right();
- break;
- case '?' :
- PRINTF("Enter pl,pr and p* for all");
- put_rn();
- break;;
- default:
- PUTC('?');
- put_rn();
- break;
- }
-#else
- not_select();
-#endif // USE_PORT
- break;
- case 'u' :
-#if USE_UART
- put_r();
- switch(*ptr++) {
- case '0' :
- uart_io_print();
- uart_io_reg0();
- uart_reg(0);
- break;
- case '1' :
- uart_io_print();
- uart_io_reg1();
- uart_reg(1);
- break;
- case '2' :
- uart_io_print();
- uart_io_reg2();
- uart_reg(2);
- break;
- case '3' :
- uart_io_print();
- uart_io_reg3();
- uart_reg(3);
- break;
- case '*' :
- uart_io_print();
- uart_io_reg0();
- uart_io_reg1();
- uart_io_reg2();
- uart_io_reg3();
- break;
- case '?' :
- PRINTF("Enter u0,u1,u2,u3 for each UART ");
- PRINTF("or u* for UART port assignment");
- put_rn();
- break;
- default:
- PUTC('?');
- put_rn();
- break;
- }
-#else
- not_select();
-#endif // USE_UART
- break;
- case 'i' :
-#if USE_I2C
- put_r();
- i2c_io_reg();
- i2c_freq();
-#else
- not_select();
-#endif // USE_I2C
- break;
- case 's' :
-#if USE_SPI
- put_r();
- spi_io_reg();
- spi_freq();
-#else
- not_select();
-#endif // USE_SPI
- break;
- case 't' : //
- not_yet_impliment();
- break;
- case 'a' : //
- not_yet_impliment();
- break;
- case 'd' : //
- not_yet_impliment();
- break;
- case 'w' : //
- not_yet_impliment();
- break;
- case 'l' : //
- not_yet_impliment();
- break;
- case 'c' : //
- not_yet_impliment();
- break;
- case 'x' : //
- not_yet_impliment();
- break;
- case 'y' : //
- not_yet_impliment();
- break;
- case 'q' : // quit
- r_flg = 0xff;
- break;
- case '?' :
- PRINTF("p - I/O Pin Config. pl(p5 to p20) & pr(p21 to p30)");
- put_rn();
- PRINTF("u - UART u0,1,2,3 or u* (port assignment)");
- put_rn();
- PRINTF("i - I2C");
- put_rn();
- PRINTF("s - SPI/SSP");
- put_rn();
- PRINTF("t - TIMER");
- put_rn();
- PRINTF("a - ADC");
- put_rn();
- PRINTF("d - DAC");
- put_rn();
- PRINTF("l - LDC");
- put_rn();
- PRINTF("w - WWDG");
- put_rn();
- PRINTF("c - COMP");
- put_rn();
- PRINTF("q - Exit mode");
- put_rn();
- break;
- default:
- PUTC('?');
- put_rn();
- }
- }
- PRINTF("Return to All Mode");
- put_rn();
- break;
- //---------------------------------------------------------------------------------
- // System
- //---------------------------------------------------------------------------------
- case 's' : // System related information
-#if USE_SYS
- switch (*ptr++) {
- case 'f' : // sc - show system clock frequency
- get_freq(1);
- break;
- case 'c' : // sc - show system CPU information
- cpu_inf();
- break;
- case '?' :
- default:
- put_r();
- PRINTF("sc - System CPU information");
- put_rn();
- PRINTF("sf - System Clock");
- put_rn();
- break;
- }
-#else
- not_select();
-#endif // USE_SYS
- break;
- //-----------------------------------------------------------------------------------------
- // Help
- //-----------------------------------------------------------------------------------------
- case '?' :
- msg_hlp_hw();
- break;
- //-----------------------------------------------------------------------------------------
- // Return to main routine
- //-----------------------------------------------------------------------------------------
- case 'q' : // Quit
- put_r();
- PRINTF("Return to monitor");
- put_rn();
- return 0;
- //-----------------------------------------------------------------------------------------
- // Special command for DEBUG
- //-----------------------------------------------------------------------------------------
- case 'x' :
- not_yet_impliment();
- break;
- //-----------------------------------------------------------------------------------------
- // no support
- //-----------------------------------------------------------------------------------------
- default:
- PUTC('?');
- put_rn();
- break;
- }
- }
-}
-#endif // defined(TARGET_LPC1768)
--- a/debug_tools/mon_hw_STM32.cpp Sun Dec 14 09:17:01 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1279 +0,0 @@
-/*
- * mbed Application program for the ST NUCLEO Board
- * Monitor program Ver.3 for only for STM32F401RE,F411RE & STM32L152RE
- *
- * Copyright (c) 2010-2014 Kenji Arai / JH1PJL
- * http://www.page.sannet.ne.jp/kenjia/index.html
- * http://mbed.org/users/kenjiArai/
- * Started: May 9th, 2010
- * Created: May 15th, 2010
- * release as "monitor_01" http://mbed.org/users/kenjiArai/code/monitor_01/
- * Spareted: June 25th, 2014 mon() & mon_hw()
- * restart: July 12th, 2014
- * Revised: Nobember 2nd, 2014
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
- * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
- * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#if defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE) || defined(TARGET_NUCLEO_L152RE)
-
-// Include ---------------------------------------------------------------------------------------
-#include "mbed.h"
-#include "mon_hw_config.h"
-#include "mon_hw_common.h"
-#include "mon_hw_STM32.h"
-
-// Object ----------------------------------------------------------------------------------------
-
-// Definition ------------------------------------------------------------------------------------
-// USB Frequency
-#define USB_FREQ_H 48100000
-#define USB_FREQ_L 47900000
-
-// RAM -------------------------------------------------------------------------------------------
-uint32_t SystemFrequency;
-uint8_t quitflag;
-
-uint32_t reg_save0, reg_save1, reg_save2, reg_save3, reg_save4;
-
-// ROM / Constant data ---------------------------------------------------------------------------
-#if defined(TARGET_NUCLEO_F401RE)
-char *const mon_msg =
- "HW monitor only for mbed Nucleo F401RE created on UTC:"__DATE__"("__TIME__")";
-
-#if USE_MEM
-const uint32_t mem_range[][2] = { // Memory access range
- { 0x08000000, 0x0807ffff }, // On-chip Flash memory, 512KB Flash
- { 0x1fff0000, 0x1fff7a0f }, // System memory
- { 0x1fffc000, 0x1fffc007 }, // Option bytes
- { 0x20000000, 0x20017fff }, // Main Embedded SRAM, 96KB SRAM
- { 0x40000000, 0x5003ffff } // IO area
-};
-#endif // USE_MEM
-#elif defined(TARGET_NUCLEO_F411RE)
-char *const mon_msg =
- "HW monitor only for mbed Nucleo F411RE created on UTC:"__DATE__"("__TIME__")";
-
-#if USE_MEM
-const uint32_t mem_range[][2] = { // Memory access range
- { 0x08000000, 0x0807ffff }, // On-chip Flash memory, 512KB Flash
- { 0x1fff0000, 0x1fff7a0f }, // System memory
- { 0x1fffc000, 0x1fffc007 }, // Option bytes
- { 0x20000000, 0x2001ffff }, // Main Embedded SRAM, 128KB SRAM
- { 0x40000000, 0x5003ffff } // IO area
-};
-#endif // USE_MEM
-#elif defined(TARGET_NUCLEO_L152RE)
-char *const mon_msg =
- "HW monitor only for mbed Nucleo L152RE created on UTC:"__DATE__"("__TIME__")";
-
-#if USE_MEM
-const uint32_t mem_range[][2] = { // Memory access range
- { 0x08000000, 0x0807ffff }, // On-chip Flash memory, 512KB Flash
- { 0x08080000, 0x08083fff }, // EEPROM, 16KB
- { 0x1ff00000, 0x1ff01fff }, // System memory
- { 0x1ff80000, 0x1ff8009f }, // Option bytes
- { 0x20000000, 0x20013fff }, // Main Embedded SRAM, 32KB SRAM
- { 0x40000000, 0x400267ff } // IO area
-};
-#endif // USE_MEM
-#endif
-
-char *const hmsg0 = "m - Entry Memory Mode";
-char *const hmsg1 = "m>? -> Aditinal functions can see by ?";
-char *const hmsg2 = "r - Entry Register Mode";
-char *const hmsg3 = "r>? -> Aditinal functions can see by ?";
-char *const hmsg4 = "s - System Clock -> sf, System / CPU information -> sc";
-char *const hmsg5 = "q - Quit (back to called routine)";
-char *const hmsg6 = "p - Entry Port Mode";
-char *const hmsg7 = "p>? -> Aditinal functions can see by ?";
-
-char *const mrmsg0 = "Enter Register Mode u,i,s,t,a,d,l,w,c & ? for help";
-#if (USE_UART==1) || (USE_SPI==1) || (USE_I2C == 1)
-char *const mrmsg1 = "------";
-char *const mrmsg2 = "USART";
-//
-char *const mrmsg4 = "I2C";
-//
-char *const mrmsg6 = "SPI";
-//
-#if defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE)
-char *const mrmsg3 = "Enter u1,u2,u6 and u* for all";
-char *const mrmsg5 = "Enter i1,i2,i3 and i* for all";
-char *const mrmsg7 = "Enter s1,s2,s3,s4 and s* for all";
-#elif defined(TARGET_NUCLEO_L152RE)
-char *const mrmsg3 = "Enter u1,u2,u3,u5 and u* for all";
-char *const mrmsg5 = "Enter i1,i2 and i* for all";
-char *const mrmsg7 = "Enter s1,s2,s3 and s* for all";
-#endif
-#endif // (USE_UART==1) || (USE_SPI==1) || (USE_I2C == 1)
-char *const mrmsg8 = "Return to All Mode";
-
-//-------------------------------------------------------------------------------------------------
-// Control Program
-//-------------------------------------------------------------------------------------------------
-// No function
-static void not_yet_impliment( void )
-{
- PRINTF("Not implimented yet");
- put_rn();
-}
-
-// No function
-#if (USE_MEM==0)||(USE_PORT==0)||(USE_UART==0)||(USE_SPI==0)||(USE_I2C==0)||(USE_SYS==0)
-static void not_select( void )
-{
- PRINTF("Not select the function (refer mon_hw_config.h)");
- put_rn();
-}
-#endif
-
-// Help Massage
-void hw_msg_hlp ( void )
-{
- PRINTF(mon_msg);
- put_rn();
- PRINTF(hmsg0);
- put_rn();
- PRINTF(hmsg1);
- put_rn();
- PRINTF(hmsg6);
- put_rn();
- PRINTF(hmsg7);
- put_rn();
- PRINTF(hmsg2);
- put_rn();
- PRINTF(hmsg3);
- put_rn();
- PRINTF(hmsg4);
- put_rn();
- PRINTF(hmsg5);
- put_rn();
-}
-
-#if USE_MEM
-#if defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE)
-char *const rmsg0 = "FLASH ";
-char *const rmsg1 = "SYS-Mem ";
-char *const rmsg2 = "OPTION ";
-char *const rmsg3 = "SRAM ";
-char *const rmsg4 = "IO ";
-#elif defined(TARGET_NUCLEO_L152RE)
-char *const rmsg0 = "FLASH ";
-char *const rmsg1 = "EEPROM ";
-char *const rmsg2 = "SYS-Mem ";
-char *const rmsg3 = "OPTION ";
-char *const rmsg4 = "SRAM ";
-char *const rmsg5 = "IO ";
-#endif
-
-#include "mon_hw_mem.h"
-#endif // USE_MEM
-
-
-// Show 16bit register contents
-void reg_print(uint16_t size, uint16_t reg)
-{
- uint16_t i, j, k, n;
-
- i = j = k = n = 0;
- switch (size) {
- case SIZE8:
- PRINTF(rgmsg0);
- put_rn();
- i = 8;
- n = 0x80;
- break;
- case SIZE16:
- PRINTF("%s%s", rgmsg1, rgmsg0);
- put_rn();
- i = 16;
- n = 0x8000;
- break;
- case SIZE32:
- PRINTF("0x%08x", reg);
- return;
- default :
- ;
- }
- PUTC(' ');
- for (; i>0; i--) {
- k = n >> (size-i);
- j = reg & k;
- if (j) {
- PUTC('1');
- } else {
- PUTC('0');
- }
- PUTC(' ');
- PUTC(' ');
- }
- PRINTF(" (0x%04x)", reg);
-}
-
-#if USE_I2C
-void i2c_reg( I2C_TypeDef* I2Cx )
-{
- uint16_t reg;
-
- put_rn();
- reg = I2Cx->CR1;
- reg_print( SIZE32, reg );
- PRINTF( rnmsg0 );
- PRINTF( imsg2 );
- put_rn();
- reg = I2Cx->CR2;
- reg_print( SIZE32, reg );
- PRINTF( rnmsg1 );
- PRINTF( imsg2 );
- put_rn();
- reg = I2Cx->SR1;
- reg_print( SIZE32, reg );
- PRINTF( rnmsg5 );
- PRINTF( imsg3 );
- put_rn();
- reg = I2Cx->SR2;
- reg_print( SIZE32, reg );
- PRINTF( rnmsg6 );
- PRINTF( imsg3 );
- put_rn();
- reg = I2Cx->DR;
- reg_print( SIZE32, reg );
- PRINTF( rnmsg2 );
- PRINTF( imsg4 );
- put_rn();
- reg = I2Cx->OAR1;
- reg_print( SIZE32, reg );
- PRINTF( rnmsg7 );
- PRINTF( imsg6 );
- put_rn();
- reg = I2Cx->OAR2;
- reg_print( SIZE32, reg );
- PRINTF( rnmsg8 );
- PRINTF( imsg6 );
- put_rn();
- reg = I2Cx->CCR;
- reg_print( SIZE32, reg );
- PRINTF( rnmsg9 );
- PRINTF( imsg7 );
- put_rn();
- reg = I2Cx->TRISE;
- reg_print( SIZE32, reg );
- PRINTF( rnmsg10 );
- PRINTF( imsg8 );
- put_rn();
-}
-#endif // USE_I2C
-
-#if USE_SPI
-void spi_reg( SPI_TypeDef* SPIx )
-{
- uint16_t reg;
-
- put_rn();
- reg = SPIx->CR1;
- reg_print( SIZE32, reg );
- PRINTF( rnmsg0 );
- PRINTF( imsg2 );
- put_rn();
- reg = SPIx->CR2;
- reg_print( SIZE32, reg );
- PRINTF( rnmsg1 );
- PRINTF( imsg2 );
- put_rn();
- reg = SPIx->SR;
- reg_print( SIZE32, reg );
- PRINTF( rnmsg3 );
- PRINTF( imsg3 );
- put_rn();
- reg = SPIx->DR;
- reg_print( SIZE32, reg );
- PRINTF( rnmsg2 );
- PRINTF( imsg4 );
- put_rn();
-}
-#endif // USE_SPI
-
-#if USE_UART
-void usart_reg( USART_TypeDef* USARTx )
-{
- uint16_t reg;
-
- put_rn();
- reg = USARTx->SR;
- reg_print( SIZE32, reg );
- PRINTF( rnmsg3 );
- PRINTF( imsg3 );
- put_rn();
- reg = USARTx->DR;
- reg_print( SIZE32, reg );
- PRINTF( rnmsg2 );
- PRINTF( imsg4 );
- put_rn();
- reg = USARTx->BRR;
- reg_print( SIZE32, reg );
- PRINTF( rnmsg4 );
- PRINTF( imsg5 );
- put_rn();
- reg = USARTx->CR1;
- reg_print( SIZE32, reg );
- PRINTF( rnmsg0 );
- PRINTF( imsg2 );
- put_rn();
- reg = USARTx->CR2;
- reg_print( SIZE32, reg );
- PRINTF( rnmsg1 );
- PRINTF( imsg2 );
- put_rn();
-}
-#endif // USE_UART
-
-#if USE_PORT
-void rpt_port_one( GPIO_TypeDef* GPIOx )
-{
- uint32_t i;
-
- PRINTF( " " );
- i = GPIOx->MODER;
- PRINTF( "0x%08x",i );
- i = GPIOx->OTYPER;
- PRINTF( " 0x%04x",i );
- i = GPIOx->OSPEEDR;
- PRINTF( " 0x%08x",i );
- i = GPIOx->PUPDR;
- PRINTF( " 0x%08x",i );
- i = GPIOx->IDR;
- PRINTF( " 0x%04x",i );
- i = GPIOx->ODR;
- PRINTF( " 0x%04x",i );
- put_rn();
-}
-
-void rpt_port( void )
-{
- PRINTF( pnmsg0 );
- PRINTF( pnmsg1 );
- put_rn();
- PRINTF( pnmsga );
- rpt_port_one( GPIOA );
- PRINTF( pnmsgb );
- rpt_port_one( GPIOB );
- PRINTF( pnmsgc );
- rpt_port_one( GPIOC );
- PRINTF( pnmsgd );
- rpt_port_one( GPIOD );
- PRINTF( pnmsge );
- rpt_port_one( GPIOE );
- PRINTF( pnmsgh );
- rpt_port_one( GPIOH );
-}
-
-void port_inf_one( char *ptr )
-{
- GPIO_TypeDef* GPIOx;
- uint32_t i,j;
- uint32_t pinpos;
-
- GPIOx = 0;
- PRINTF( pnmsg2 );
- switch ( *ptr ) {
- case 'a':
- GPIOx = GPIOA;
- PUTC( 'A' );
- break;
- case 'b':
- GPIOx = GPIOB;
- PUTC( 'B' );
- break;
- case 'c':
- GPIOx = GPIOC;
- PUTC( 'C' );
- break;
- case 'd':
- GPIOx = GPIOD;
- PUTC( 'D' );
- break;
- case 'e':
- GPIOx = GPIOE;
- PUTC( 'E' );
- break;
- case 'h':
- GPIOx = GPIOH;
- PUTC( 'H' );
- break;
- }
- i = GPIOx->MODER;
- put_rn();
- PRINTF( "-->Mode Reg. (0x%08x)",i );
- put_rn();
- for ( pinpos = 0x00; pinpos < 16; pinpos++ ) {
- j = GPIO_MODER_MODER0 & (i >> (pinpos * 2));
- switch (j) {
- case GPIO_Mode_IN:
- PRINTF( "%2d= in", pinpos );
- break;
- case GPIO_Mode_OUT:
- PRINTF( "%2d=out", pinpos );
- break;
- case GPIO_Mode_AF:
- PRINTF( "%2d=alt", pinpos );
- break;
- case GPIO_Mode_AN:
- PRINTF( "%2d=ana", pinpos );
- break;
- default:
- break;
- }
- if ( (pinpos == 3) && (*ptr == 'h') ) {
- break;
- } else {
- if ( pinpos == 7 ) {
- put_rn();
- } else if ( pinpos == 15 ) {
- ;
- } else {
- PRINTF(", ");
- }
- }
- }
- i = GPIOx->OTYPER;
- put_rn();
- PRINTF( "%s type 1=push-pull, 0= open-drain", pnmsg4 );
- put_rn();
- reg_print( SIZE32,i);
- i = GPIOx->OSPEEDR;
- PRINTF( "%s speed [MHz] (0x%08x)", pnmsg4, i );
- put_rn();
- for ( pinpos = 0x00; pinpos < 16; pinpos++ ) {
- j = GPIO_OSPEEDER_OSPEEDR0 & (i >> (pinpos * 2));
- switch (j) {
- case GPIO_Speed_400KHz:
- PRINTF( "%2d=0.4", pinpos );
- break;
- case GPIO_Speed_2MHz:
- PRINTF( "%2d= 2", pinpos );
- break;
- case GPIO_Speed_10MHz:
- PRINTF( "%2d= 10", pinpos );
- break;
- case GPIO_Speed_40MHz:
- PRINTF( "%2d= 40", pinpos );
- break;
- default:
- break;
- }
- if ( (pinpos == 3) && (*ptr == 'h') ) {
- break;
- } else {
- if ( pinpos == 7 ) {
- put_rn();
- } else if ( pinpos == 15) {
- ;
- } else {
- PRINTF(", ");
- }
- }
- }
- i = GPIOx->PUPDR;
- put_rn();
- PRINTF( "-->Pullup(pup)/down(pdn) none(no)(0x%08x)",i );
- put_rn();
- for ( pinpos = 0x00; pinpos < 16; pinpos++ ) {
- j = GPIO_PUPDR_PUPDR0 & (i >> (pinpos * 2));
- switch (j) {
- case GPIO_PuPd_NOPULL:
- PRINTF( "%2d= no", pinpos );
- break;
- case GPIO_PuPd_UP:
- PRINTF( "%2d=pup", pinpos );
- break;
- case GPIO_PuPd_DOWN:
- PRINTF( "%2d=pdn", pinpos );
- break;
- default:
- break;
- }
- if ( (pinpos == 3) && (*ptr == 'h') ) {
- break;
- } else {
- if ( pinpos == 7 ) {
- put_rn();
- } else if ( pinpos == 15 ) {
- ;
- } else {
- PRINTF(", ");
- }
- }
- }
- put_rn();
- PRINTF( "%s %s", pnmsg5, pnmsg6);
- i = GPIOx->IDR;
- reg_print( SIZE32,i);
- put_rn();
- PRINTF( "%s %s", pnmsg4, pnmsg6);
- i = GPIOx->ODR;
- reg_print( SIZE32,i);
- put_rn();
-}
-#endif // USE_PORT
-
-#if defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE)
-void port_mco1_mco2_set(void)
-{
- GPIO_TypeDef* GPIOx = 0;
- uint32_t temp = 0x00;
-
- // PA8 -> MCO_1
- GPIOx = GPIOA;
- reg_save0 = GPIOx->AFR[8 >> 3];
- reg_save1 = GPIOx->MODER;
- temp = ((uint32_t)(GPIO_AF0_MCO) << (((uint32_t)8 & (uint32_t)0x07) * 4)) ;
- GPIOx->AFR[8 >> 3] &= ~((uint32_t)0xf << ((uint32_t)(8 & (uint32_t)0x07) * 4)) ;
- GPIOx->AFR[8 >> 3] |= temp;
- GPIOx->MODER &= ~(GPIO_MODER_MODER0 << (8 * 2));
- GPIOx->MODER |= (0x2 << (8 * 2));
- // PC9 -> MCO_2
- GPIOx = GPIOC;
- reg_save2 = GPIOx->AFR[9 >> 3];
- reg_save3 = GPIOx->MODER;
- temp = ((uint32_t)(GPIO_AF0_MCO) << (((uint32_t)9 & (uint32_t)0x07) * 4)) ;
- GPIOx->AFR[9 >> 3] &= ~((uint32_t)0xf << ((uint32_t)(9 & (uint32_t)0x07) * 4)) ;
- GPIOx->AFR[9 >> 3] |= temp;
- GPIOx->MODER &= ~(GPIO_MODER_MODER0 << (9 * 2));
- GPIOx->MODER |= (0x2 << (9 * 2));
- reg_save4 = RCC->CFGR;
- // Select output clock source
- RCC->CFGR &= 0x009fffff;
-#if 1
- // MC0_1 output HSE 1/4, MCO_2 output SYSCLK 1/4
- // MCO2 MCO2PRE MCO1PRE MCO1
- RCC->CFGR |= (0x0 << 30) + (0x6 << 27) + (0x6 << 24) + (0x3 << 22);
-#else
- // MC0_1 output HSE 1/1, MCO_2 output SYSCLK 1/2
- // MCO2 MCO2PRE MCO1PRE MCO1
- RCC->CFGR |= (0x0 << 30) + (0x4 << 27) + (0x0 << 24) + (0x3 << 22);
-#endif
-}
-
-void port_mco1_mco2_recover(void)
-{
- GPIO_TypeDef* GPIOx = 0;
-
- // PA8 -> MCO_1
- GPIOx = GPIOA;
- GPIOx->AFR[8 >> 3] = reg_save0;
- GPIOx->MODER = reg_save1;
- // PC9 -> MCO_2
- GPIOx = GPIOC;
- GPIOx->AFR[9 >> 3] = reg_save2;
- GPIOx->MODER = reg_save3;
- // MC0_1 & MCO_2
- RCC->CFGR = reg_save4;
-}
-#endif // defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE)
-
-#if defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE)
-void cpu_inf( char *ptr )
-{
- uint32_t m1 = 0, m2 = 0, m3 = 0, m4 = 0, m5 = 0;
-
- switch (*ptr++) {
- case 'f' : // sc - show system clock frequency
- m1 = RCC->CR;
- PRINTF( "CR = 0x%08x", m1 );
- put_rn();
- m1 = RCC->PLLCFGR;
- PRINTF( "PLLCFGR = 0x%08x", m1 );
- put_rn();
- m1 = RCC->CFGR;
- PRINTF( "CFGR = 0x%08x", m1 );
- put_rn();
- m1 = RCC->CIR;
- PRINTF( "CIR = 0x%08x", m1 );
- put_rn();
- m1 = RCC->AHB1RSTR;
- PRINTF( "AHB1RSTR = 0x%08x", m1 );
- put_rn();
- m1 = RCC->APB2RSTR;
- PRINTF( "APB2RSTR = 0x%08x", m1 );
- put_rn();
- m1 = RCC->APB1RSTR;
- PRINTF( "APB1RSTR = 0x%08x", m1 );
- put_rn();
- m1 = RCC->AHB1ENR;
- PRINTF( "AHB1ENR = 0x%08x", m1 );
- put_rn();
- m1 = RCC->APB2ENR;
- PRINTF( "APB2ENR = 0x%08x", m1 );
- put_rn();
- m1 = RCC->APB2LPENR;
- PRINTF( "APB2LPENR= 0x%08x", m1 );
- put_rn();
- m1 = RCC->APB1LPENR;
- PRINTF( "APB1LPENR= 0x%08x", m1 );
- put_rn();
- m1 = RCC->CSR;
- PRINTF( "CSR = 0x%08x", m1 );
- put_rn();
- PRINTF(cmsg11);
- put_rn();
- m1 = PWR->CR;
- PRINTF( "CR = 0x%08x", m1 );
- put_rn();
- m1 = PWR->CSR;
- PRINTF( "CSR = 0x%08x", m1 );
- put_rn();
- put_rn();
- case 'F' : // sF - show system clock frequency
- m1 = RCC->CFGR & RCC_CFGR_SWS; /* Get SYSCLK source */
- switch (m1) {
- case 0x00: // HSI used as system clock
- PRINTF( "%s, %s%dHz", cmsg2, cmsg1,HSI_VALUE );
- m2 = HSI_VALUE;
- break;
- case 0x04: // HSE used as system clock
- PRINTF( "%s, %s%dHz", cmsg3, cmsg1, HSE_VALUE );
- m2 = HSE_VALUE;
- break;
- case 0x08: // PLL used as system clock
- PRINTF("fVCO = fPLL-in x (PLLN/PLLM), fPLL-out = fVCO/PLLP, fUSB-out = fVCO/PLLQ");
- put_rn();
- m5 = (RCC->PLLCFGR >> 6) & 0x1ff; // PLLN
- m1 = RCC->PLLCFGR & 0x3f; // PLLM
- PRINTF( "%s PLLN=%d, PLLM=%d", cmsg4, m5, m1 );
- put_rn();
- m3 = (RCC->PLLCFGR >> 22) & 0x1; // Clock source
- if (m3 == 0) {
- // HSI oscillator clock selected as PLL clock source
- m2 = (HSI_VALUE * (m5 / m1));
- PRINTF( "%s, RC=%dHz", cmsg2, HSI_VALUE );
- } else {
- // HSE selected
- m2 = (((HSE_VALUE) * m5) / m1);
- if ((RCC->CR >> 18) & 0x01) { // check HSEBYP bit
- // HSE(not Xtal) selected as PLL clock source
- PRINTF( "Use HSE(not Xtal but External Clock)=%dHz", HSE_VALUE );
- } else {
- // HSE(Xtal) selected as PLL clock source
- PRINTF( "%s, Xtal=%dHz", cmsg3, HSE_VALUE );
- }
- }
- put_rn();
- PRINTF("PLL/Base %s%dHz", cmsg1, m2);
- put_rn();
- m3 = (RCC->PLLCFGR >> 16) & 0x03; // PLLP
- switch (m3) {
- case 0:
- m3 = 2;
- break;
- case 1:
- m3 = 4;
- break;
- case 2:
- m3 = 6;
- break;
- case 3:
- m3 = 8;
- break;
- }
- m4 = (RCC->PLLCFGR >> 24) & 0x0f; // PLLQ
- PRINTF("%s PLLP=%d, PLLQ=%d", cmsg4, m3, m4);
- put_rn();
- PRINTF("PLL/System %s%dHz", cmsg1, m2/m3);
- put_rn();
- PRINTF("PLL/USB %s%dHz", cmsg1, m2/m4);
- m2 = m2/m4;
- if ((m2 > USB_FREQ_H) || (m2 <USB_FREQ_L)) {
- PRINTF(" -> USB Freq. is out of range!");
- }
- put_rn();
- break;
- default: // Not come here
- PRINTF( cmsg5 );
- break;
- }
- put_rn();
- PRINTF( "SYSCLK %s%dHz", cmsg6, HAL_RCC_GetSysClockFreq());
- put_rn();
- PRINTF( "HCLK %s%dHz", cmsg6, HAL_RCC_GetHCLKFreq());
- put_rn();
- PRINTF( "PCLK1 %s%dHz", cmsg6, HAL_RCC_GetPCLK1Freq());
- put_rn();
- PRINTF( "PCLK2 %s%dHz", cmsg6, HAL_RCC_GetPCLK2Freq());
- put_rn();
- put_rn();
- // Check RTC Clock
- PRINTF("RTC Clock");
- put_rn();
- m1 = (RCC->BDCR >> 8) & 0x03;
- switch (m1) {
- case 0: // no clock
- PRINTF(cmsg7);
- break;
- case 1: // LSE
- PRINTF(cmsg8);
- break;
- case 2: // LSI
- PRINTF("%s 17 to 47, typ.32KHz", cmsg9);
- break;
- case 3: // HSE
- PRINTF( cmsg10 );
- m2 = (RCC->PLLCFGR >> 16) & 0x1f; // RTCPRE
- m3 = HSE_VALUE / m2;
- PRINTF("%s%dHz", cmsg6, m3);
- put_rn();
- break;
- default: // Not come here
- PRINTF(cmsg5);
- break;
- }
- put_rn();
- put_rn();
- break;
- case 'c' : // sc - show system CPU information
- m1 = SCB->CPUID;
- m2 = ( m1 >> 24 );
- if ( m2 == 0x41 ) {
- PRINTF( "CPU = ARM " );
- } else {
- PRINTF( "CPU = NOT ARM " );
- }
- m2 = ( m1 >> 4 ) & 0xfff;
- if ( m2 == 0xc24 ) {
- PRINTF( "Cortex-M4" );
- } else {
- PRINTF( "NOT Cortex-M4" );
- }
- put_rn();
- m2 = ( m1 >> 20 ) & 0x0f;
- PRINTF( "Variant:%x", m2 );
- put_rn();
- m2 = m1 & 0x7;
- PRINTF( "Revision:%x", m2 );
- put_rn();
- PRINTF( "CPU ID: 0x%08x", m1 );
- put_rn();
- m1 = DBGMCU->IDCODE;
- PRINTF( "DBG ID: 0x%08x", m1 );
- put_rn();
- // unique ID
- // http://waijung.aimagin.com/index.htm?stm32f4_uidread.htm
- m1 = *(__IO uint32_t *)((uint32_t)0x1FFF7A10);
- PRINTF("Unique device ID(94bits):(1) 0x%08x ", m1);
- m1 = *(__IO uint32_t *)((uint32_t)0x1FFF7A14);
- PRINTF("(2) 0x%08x ", m1);
- m1 = *(__IO uint32_t *)((uint32_t)0x1FFF7A18);
- PRINTF( "(3) 0x%08x", m1 );
- put_rn();
- break;
- case '?' :
- default:
- PRINTF( "sc - System CPU information" );
- put_rn();
- PRINTF( "sf - System Clock" );
- put_rn();
- }
-}
-#elif defined(TARGET_NUCLEO_L152RE)
-
-static __I uint8_t PLLMulTable[9] = {3, 4, 6, 8, 12, 16, 24, 32, 48};
-
-void cpu_inf( char *ptr )
-{
- uint32_t m1, m2, m3, m4, m5;
-
- switch (*ptr++) {
- case 'f' : // sc - show system clock frequency
- m1 = RCC->CR;
- PRINTF( "CR = 0x%08x", m1 );
- put_rn();
- m1 = RCC->ICSCR;
- PRINTF( "ICSCR = 0x%08x", m1 );
- put_rn();
- m1 = RCC->CFGR;
- PRINTF( "CFGR = 0x%08x", m1 );
- put_rn();
- m1 = RCC->CIR;
- PRINTF( "CIR = 0x%08x", m1 );
- put_rn();
- m1 = RCC->AHBRSTR;
- PRINTF( "AHBRSTR = 0x%08x", m1 );
- put_rn();
- m1 = RCC->APB2RSTR;
- PRINTF( "APB2RSTR = 0x%08x", m1 );
- put_rn();
- m1 = RCC->APB1RSTR;
- PRINTF( "APB1RSTR = 0x%08x", m1 );
- put_rn();
- m1 = RCC->AHBENR;
- PRINTF( "AHBENR = 0x%08x", m1 );
- put_rn();
- m1 = RCC->APB2ENR;
- PRINTF( "APB2ENR = 0x%08x", m1 );
- put_rn();
- m1 = RCC->APB2LPENR;
- PRINTF( "APB2LPENR= 0x%08x", m1 );
- put_rn();
- m1 = RCC->APB1LPENR;
- PRINTF( "APB1LPENR= 0x%08x", m1 );
- put_rn();
- m1 = RCC->CSR;
- PRINTF( "CSR = 0x%08x", m1 );
- put_rn();
- PRINTF( cmsg11 );
- put_rn();
- m1 = PWR->CR;
- PRINTF( "CR = 0x%08x", m1 );
- put_rn();
- m1 = PWR->CSR;
- PRINTF( "CSR = 0x%08x", m1 );
- put_rn();
- put_rn();
- case 'F' : // sF - show system clock frequency
- m1 = RCC->CFGR & RCC_CFGR_SWS; /* Get SYSCLK source */
- switch (m1) {
- case 0x00: // MSI used as system clock
- m4 = ( RCC->ICSCR & RCC_ICSCR_MSIRANGE ) >> 13;
- m2 = (32768 * (1 << (m4 + 1)));
- PRINTF( "%s, %s%dHz", cmsg0, cmsg1, m2);
- break;
- case 0x04: // HSI used as system clock
- PRINTF( "%s, %s%dHz", cmsg2, cmsg1,HSI_VALUE );
- m2 = HSI_VALUE;
- break;
- case 0x08: // HSE used as system clock
- PRINTF( "%s, %s%dHz", cmsg3, cmsg1, HSE_VALUE );
- m2 = HSE_VALUE;
- break;
- case 0x0C: // PLL used as system clock
- // Get PLL clock source and multiplication factor
- m5 = RCC->CFGR & RCC_CFGR_PLLMUL;
- m1 = RCC->CFGR & RCC_CFGR_PLLDIV;
- m5 = PLLMulTable[(m5 >> 18)];
- m1 = (m1 >> 22) + 1;
- PRINTF( "%s Mul=%d, Div=%d", cmsg4, m5, m1 );
- put_rn();
- m3 = RCC->CFGR & RCC_CFGR_PLLSRC;
- if ( m3 == 0x00 ) {
- // HSI oscillator clock selected as PLL clock source
- m2 = (((HSI_VALUE) * m5) / m1);
- PRINTF( "%s, RC=%dHz", cmsg2, HSI_VALUE );
- } else {
- // HSE selected
- m2 = (((HSE_VALUE) * m5) / m1);
- if ((RCC->CR >> 18) & 0x01) { // check HSEBYP bit
- // HSE(not Xtal) selected as PLL clock source
- PRINTF( "Use HSE(not Xtal but External Clock)=%dHz", HSE_VALUE );
- } else {
- // HSE(Xtal) selected as PLL clock source
- PRINTF( "%s, Xtal=%dHz", cmsg3, HSE_VALUE );
- }
- }
- put_rn();
- PRINTF( "PLL %s%dHz", cmsg1, m2 );
- put_rn();
- break;
- default: // Not come here
- PRINTF( cmsg5 );
- break;
- }
- put_rn();
- PRINTF( "SYSCLK %s%dHz", cmsg6, HAL_RCC_GetSysClockFreq() );
- put_rn();
- PRINTF( "HCLK %s%dHz", cmsg6, HAL_RCC_GetHCLKFreq() );
- put_rn();
- PRINTF( "PCLK1 %s%dHz", cmsg6, HAL_RCC_GetPCLK1Freq() );
- put_rn();
- PRINTF( "PCLK2 %s%dHz", cmsg6, HAL_RCC_GetPCLK2Freq() );
- put_rn();
- put_rn();
- m1 = RCC->CSR & RCC_CSR_RTCSEL;
- // Check RTC & LCD Clock
- PRINTF("RTC/LCD Clock");
- put_rn();
- switch (m1) {
- case RCC_CSR_RTCSEL_NOCLOCK:
- PRINTF( cmsg7 );
- break;
- case RCC_CSR_RTCSEL_LSE:
- PRINTF( cmsg8 );
- break;
- case RCC_CSR_RTCSEL_LSI:
- PRINTF("%s 26 to 56, typ.38KHz", cmsg9);
- break;
- case RCC_CSR_RTCSEL_HSE:
- PRINTF( cmsg10 );
- break;
- default: // Not come here
- PRINTF( cmsg5 );
- break;
- }
- put_rn();
- put_rn();
- break;
- case 'c' : // sc - show system CPU information
- m1 = SCB->CPUID;
- m2 = ( m1 >> 24 );
- if ( m2 == 0x41 ) {
- PRINTF( "CPU = ARM " );
- } else {
- PRINTF( "CPU = NOT ARM " );
- }
- m2 = ( m1 >> 4 ) & 0xfff;
- if ( m2 == 0xc23 ) {
- PRINTF( "Cortex-M3" );
- } else {
- PRINTF( "NOT Cortex-M3" );
- }
- put_rn();
- m2 = ( m1 >> 20 ) & 0x0f;
- PRINTF( "Variant:%x", m2 );
- put_rn();
- m2 = m1 & 0x7;
- PRINTF( "Revision:%x", m2 );
- put_rn();
- PRINTF( "CPU ID: 0x%08x", m1 );
- put_rn();
- m1 = DBGMCU->IDCODE;
- PRINTF( "DBG ID: 0x%08x", m1 );
- put_rn();
- // unique ID
- // http://false.ekta.is/2013/09/stm32-unique-id-register-not-so-unique/
- m1 = *(__IO uint32_t *)((uint32_t)0x1FF80050);
- PRINTF("Unique device ID(94bits):(1) 0x%08x ", m1);
- m1 = *(__IO uint32_t *)((uint32_t)0x1FF80054);
- PRINTF("(2) 0x%08x ", m1);
- m1 = *(__IO uint32_t *)((uint32_t)0x1FF80058);
- PRINTF( "(3) 0x%08x", m1 );
- put_rn();
- break;
- case '?' :
- default:
- PRINTF( "sc - System CPU information" );
- put_rn();
- PRINTF( "sf - System Clock" );
- put_rn();
- }
-}
-#endif // Select CPU
-
-//-------------------------------------------------------------------------------------------------
-// Monitor Main Program
-//-------------------------------------------------------------------------------------------------
-int mon_hw(void)
-{
- char *ptr;
-
- put_r();
- PRINTF("%s [Help:'?' key]", mon_msg);
- put_rn();
- for (;;) {
- put_r();
- PUTC('>');
- ptr = linebuf;
- get_line(ptr, buf_size);
- put_r();
- switch (*ptr++) {
- //-----------------------------------------------------------------------------------------
- // Memory
- //-----------------------------------------------------------------------------------------
- case 'm' :
-#if USE_MEM
- mem_inf(ptr);
- put_rn();
-#else
- not_select();
-#endif // USE_MEM
- break;
- //-----------------------------------------------------------------------------------------
- // Register
- //-----------------------------------------------------------------------------------------
- case 'r' :
- put_r();
- PRINTF(mrmsg0);
- put_rn();
- quitflag = 0;
- for (; quitflag != 0xff;) {
- PRINTF("r>");
- ptr = linebuf;
- get_line(ptr, buf_size);
- put_r();
- switch(*ptr++) {
- case 'u' :
-#if USE_UART
- switch(*ptr++) {
- case '1' :
- PRINTF("%s%s1%s", mrmsg1,mrmsg2,mrmsg1);
- usart_reg(USART1);
- break;
- case '2' :
- PRINTF("%s%s2%s", mrmsg1,mrmsg2,mrmsg1);
- usart_reg(USART2);
- break;
-#if defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE)
- case '6' :
- PRINTF("%s%s6%s", mrmsg1,mrmsg2,mrmsg1);
- usart_reg(USART6);
- break;
-#elif defined(TARGET_NUCLEO_L152RE)
- case '3' :
- PRINTF("%s%s3%s", mrmsg1,mrmsg2,mrmsg1);
- usart_reg(USART3);
- break;
- case '5' :
- PRINTF("%s%s5%s", mrmsg1,mrmsg2,mrmsg1);
- usart_reg(UART5);
- break;
-#endif
- case '*' :
- PRINTF( "%s & UART", mrmsg2 );
- put_rn();
- PRINTF("%s%s1%s", mrmsg1,mrmsg2,mrmsg1);
- usart_reg(USART1);
- PRINTF("%s%s2%s", mrmsg1,mrmsg2,mrmsg1);
- usart_reg(USART2);
-#if defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE)
- PRINTF("%s%s6%s", mrmsg1,mrmsg2,mrmsg1);
- usart_reg(USART6);
-#elif defined(TARGET_NUCLEO_L152RE)
- PRINTF("%s%s3%s", mrmsg1,mrmsg2,mrmsg1);
- usart_reg(USART3);
- PRINTF("%s%s5%s", mrmsg1,mrmsg2,mrmsg1);
- usart_reg(UART5);
-#endif
- break;
- case '?' :
- default:
- PRINTF( mrmsg3 );
- put_rn();
- }
-#else
- not_select();
-#endif // USE_UART
- break;
- case 'i' :
-#if USE_I2C
- switch(*ptr++) {
- case '1' :
- PRINTF("%s%s1%s", mrmsg1,mrmsg4,mrmsg1);
- i2c_reg( I2C1 );
- break;
- case '2' :
- PRINTF("%s%s2%s", mrmsg1,mrmsg4,mrmsg1);;
- i2c_reg( I2C2 );
- break;
-#if defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE)
- case '3' :
- PRINTF("%s%s3%s", mrmsg1,mrmsg4,mrmsg1);;
- i2c_reg( I2C3 );
- break;
-#endif
- case '*' :
- PRINTF(mrmsg4);
- put_rn();
- PRINTF("%s%s1%s", mrmsg1,mrmsg4,mrmsg1);
- i2c_reg( I2C1 );
- PRINTF("%s%s2%s", mrmsg1,mrmsg4,mrmsg1);
- i2c_reg( I2C2 );
-#if defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE)
- PRINTF("%s%s3%s", mrmsg1,mrmsg4,mrmsg1);;
- i2c_reg( I2C3 );
-#endif
- break;
- case '?' :
- default:
- PRINTF(mrmsg5);
- put_rn();
- }
-#else
- not_select();
-#endif // USE_I2C
- break;
- case 's' :
-#if USE_SPI
- switch(*ptr++) {
- case '1' :
- PRINTF("%s%s1%s", mrmsg1,mrmsg6,mrmsg1);
- spi_reg( SPI1 );
- break;
- case '2' :
- PRINTF("%s%s2%s", mrmsg1,mrmsg6,mrmsg1);
- spi_reg( SPI2 );
- break;
- case '3' :
- PRINTF("%s%s3%s", mrmsg1,mrmsg6,mrmsg1);
- spi_reg( SPI3 );
- break;
-#if defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE)
- case '4' :
- PRINTF("%s%s4%s", mrmsg1,mrmsg6,mrmsg1);
- spi_reg( SPI4 );
- break;
-#endif
- case '*' :
- PRINTF(mrmsg6);
- put_rn();
- PRINTF("%s%s1%s", mrmsg1,mrmsg6,mrmsg1);
- spi_reg( SPI1 );
- PRINTF("%s%s2%s", mrmsg1,mrmsg6,mrmsg1);
- spi_reg( SPI2 );
- PRINTF("%s%s3%s", mrmsg1,mrmsg6,mrmsg1);
- spi_reg( SPI3 );
-#if defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE)
- PRINTF("%s%s4%s", mrmsg1,mrmsg6,mrmsg1);
- spi_reg( SPI4 );
-#endif
- break;
- case '?' :
- default:
- PRINTF(mrmsg7);
- put_rn();
- }
-#else
- not_select();
-#endif // USE_SPI
- break;
- case 't' : //
- not_yet_impliment();
- break;
- case 'a' : //
- not_yet_impliment();
- break;
- case 'd' : //
- not_yet_impliment();
- break;
- case 'w' : //
- not_yet_impliment();
- break;
- case 'l' : //
- not_yet_impliment();
- break;
- case 'c' : //
- not_yet_impliment();
- break;
- case 'x' : //
- not_yet_impliment();
- break;
- case 'y' : //
- not_yet_impliment();
- break;
- case '?' :
- PRINTF("u - USART");
- put_rn();
- PRINTF("i - I2C");
- put_rn();
- PRINTF("s - SPI");
- put_rn();
- PRINTF("t - TIMER");
- put_rn();
- PRINTF("a - ADC");
- put_rn();
- PRINTF("d - DAC");
- put_rn();
- PRINTF("l - LDC");
- put_rn();
- PRINTF("w - WWDG");
- put_rn();
- PRINTF("c - COMP");
- put_rn();
- break;
- case 'q' : // quit
- quitflag = 0xff;
- break;
- default:
- PUTC('?');
- put_rn();
- }
- }
- PRINTF(mrmsg8);
- put_rn();
- break;
- //-----------------------------------------------------------------------------------------
- // Port
- //-----------------------------------------------------------------------------------------
- case 'p' :
-#if USE_PORT
- put_r();
- PRINTF("Enter port a,b,c,d,e,h & * ? for help");
- put_rn();
- quitflag = 0;
- for (; quitflag != 0xff;) {
- PRINTF("p>");
- ptr = linebuf;
- get_line(ptr, buf_size);
- put_r();
- switch(*ptr) {
- case 'a' :
- case 'b' :
- case 'c' :
- case 'd' :
- case 'e' :
- case 'h' :
- port_inf_one(ptr);
- break;
- case '*' :
- rpt_port();
- break;
- case '?' :
- PRINTF("port a,b,c,d,e,h & *");
- put_rn();
- break;
- case 'q' : // quit
- quitflag = 0xff;
- break;
- default:
- PUTC('?');
- put_rn();
- }
- }
- PRINTF(mrmsg8);
- put_rn();
-#else
- not_select();
-#endif // USE_PORT
- break;
- //-----------------------------------------------------------------------------------------
- // System
- //-----------------------------------------------------------------------------------------
- case 's' : // System related information
-#if USE_SYS
- cpu_inf(ptr);
-#else
- not_select();
-#endif // USE_SYS
- break;
- //-----------------------------------------------------------------------------------------
- // Help
- //-----------------------------------------------------------------------------------------
- case '?' :
- hw_msg_hlp();
- break;
- //-----------------------------------------------------------------------------------------
- // Return to main routine
- //-----------------------------------------------------------------------------------------
- case 'q' : // Quit
- put_r();
- PRINTF("Return to monitor");
- put_rn();
- return 0;
- //-----------------------------------------------------------------------------------------
- // Special command for DEBUG
- //-----------------------------------------------------------------------------------------
- case 'x' :
- not_yet_impliment();
- break;
- //-----------------------------------------------------------------------------------------
- // no support
- //-----------------------------------------------------------------------------------------
- default:
- PUTC('?');
- put_rn();
- break;
- }
- }
-}
-#endif // defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE) || defined(TARGET_NUCLEO_L152RE)
--- a/debug_tools/mon_hw_STM32.h Sun Dec 14 09:17:01 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,88 +0,0 @@ -/* - * mbed Application program for the ST NUCLEO Board - * - * Copyright (c) 2010-2014 Kenji Arai / JH1PJL - * http://www.page.sannet.ne.jp/kenjia/index.html - * http://mbed.org/users/kenjiArai/ - * Created: July 7th, 2014 - * Revised: Nobember 2nd, 2014 - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE - * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -// ROM / Constant data --------------------------------------------------------------------------- -char *const rgmsg0 = " 7, 6, 5, 4, 3, 2, 1, 0"; -char *const rgmsg1 = "15,14,13,12,11,10, 9, 8,"; - -char *const cmsg0 = "Use MSI(internal RC)"; -char *const cmsg1 = "freq="; -char *const cmsg2 = "Use HSI(internal RC/High speed)"; -char *const cmsg3 = "Use HSE(External Xtal)"; -char *const cmsg4 = "Use PLL with"; -char *const cmsg5 = "??? following infromation is not valid !"; -char *const cmsg6 = "clock freq. ="; -char *const cmsg7 = "No clock"; -char *const cmsg8 = "Use LSE(external Xtal)=32768Hz"; -char *const cmsg9 = "Use LSI(internal RC/Low speed), RC="; -char *const cmsg10= "Use HSE(external Xtal & prescaler)"; -char *const cmsg11= "Power Control"; - -char *const imsg2 = "-->Control Reg."; -char *const imsg3 = "-->Status Reg."; -char *const imsg4 = "-->Data Reg."; -char *const imsg5 = "-->Baud rate Reg."; -char *const imsg6 = "-->Own address Reg."; -char *const imsg7 = "-->Clock control Reg."; -char *const imsg8 = "-->TRISE Reg."; - -char *const rnmsg0 = " CR1--"; -char *const rnmsg1 = " CR2--"; -char *const rnmsg2 = " DR---"; -char *const rnmsg3 = " SR---"; -char *const rnmsg4 = " BRR--"; -char *const rnmsg5 = " SR1--"; -char *const rnmsg6 = " SR2--"; -char *const rnmsg7 = " OAR1-"; -char *const rnmsg8 = " OAR2-"; -char *const rnmsg9 = " CCR--"; -char *const rnmsg10 = " TRISE"; - -char *const pnmsg0 = "Port "; -// 0x00000000 0x0000 0x00000000 0x00000000 0x0000 0x0000 -char *const pnmsg1 = "Mode Out-type Out-speed Pup/dwn Input Output"; -char *const pnmsga = "GPIOA"; -char *const pnmsgb = "GPIOB"; -char *const pnmsgc = "GPIOC"; -char *const pnmsgd = "GPIOD"; -char *const pnmsge = "GPIOE"; -char *const pnmsgh = "GPIOH"; -char *const pnmsg2 = "Select GPIO"; -char *const pnmsg3 = " All"; -char *const pnmsg4 = "-->Output"; -char *const pnmsg5 = "-->Input"; -char *const pnmsg6 = "data"; - -// Here is redefine part (ST Nucleo F401RE needs here definition) -#ifndef GPIO_Mode_IN -#define GPIO_Mode_IN 0 -#define GPIO_Mode_OUT 1 -#define GPIO_Mode_AF 2 -#define GPIO_Mode_AN 3 -#endif - -#ifndef GPIO_Speed_400KHz -#define GPIO_Speed_400KHz 0 -#define GPIO_Speed_2MHz 1 -#define GPIO_Speed_10MHz 2 -#define GPIO_Speed_40MHz 3 -#endif - -#ifndef GPIO_PuPd_NOPULL -#define GPIO_PuPd_NOPULL 0 -#define GPIO_PuPd_UP 1 -#define GPIO_PuPd_DOWN 2 -#endif
--- a/debug_tools/mon_hw_common.h Sun Dec 14 09:17:01 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,63 +0,0 @@
-/*
- * mbed Headder file for Hardware Monitor
- *
- * Copyright (c) 2014 Kenji Arai / JH1PJL
- * http://www.page.sannet.ne.jp/kenjia/index.html
- * http://mbed.org/users/kenjiArai/
- * Created: June 1st, 2014
- * Revised: Nobember 2nd, 2014
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
- * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
- * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
- // Object ----------------------------------------------------------------------------------------
-extern Serial pch(USBTX, USBRX);
-
-// Definition ------------------------------------------------------------------------------------
-#define BAUD_RATE 9600
-
-#define BAUD(x) pch.baud(x)
-#define GETC(x) pch.getc(x)
-#define PUTC(x) pch.putc(x)
-#define PRINTF(...) pch.printf(__VA_ARGS__)
-#define READABLE(x) pch.readable(x)
-
-// Range check status
-#define ERR_NOTHING 0
-#define ERR_MODIFY_SIZ 1
-#define ERR_OUT_OF_RANGE 2
-
-// Reg. Size
-#define SIZE8 8
-#define SIZE16 16
-#define SIZE32 32
-#define SIZE_FULL 32
-#define SIZE_X 32
-
-// RAM -------------------------------------------------------------------------------------------
-extern char linebuf[];
-extern int buf_size;
-
-#if USE_MEM
-typedef struct {
- int32_t mstr;
- int32_t msiz;
- int32_t mtmp;
- int32_t mold;
- uint8_t mflg;
- uint8_t mbhw;
-} MEMO;
-static MEMO mem;
-#endif
-
-// Function prototypes ---------------------------------------------------------------------------
-extern void put_rn ( void );
-extern void put_r ( void );
-extern void put_lin ( void );
-extern void put_spc( uint8_t n);
-extern void get_line (char *buff, int len);
-extern int xatoi (char **str, int32_t *res);
--- a/debug_tools/mon_hw_config.h Sun Dec 14 09:17:01 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -/* - * mbed Headder file for Hardware Monitor - * - * Copyright (c) 2014 Kenji Arai / JH1PJL - * http://www.page.sannet.ne.jp/kenjia/index.html - * http://mbed.org/users/kenjiArai/ - * Created: June 1st, 2014 - * Revised: Nobember 2nd, 2014 - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE - * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -// CPU LPC1768 / mbed LPC1768 -// mon_hw_config.h mon_hw_mem.h mon_hw_LPC1768.cpp - -// CPU LPC1114 / mbed LPC1114FN28 -// mon_hw_config.h mon_hw_mem.h mon_hw_LPC1114.cpp - -// CPU STM32L152RE / mbed ST Nucleo L152RE -// CPU STM32F401RE / mbed ST Nucleo F401RE -// CPU STM32F411RE / mbed ST Nucleo F411RE -// mon_hw_config.h mon_hw_mem.h mon_hw_STM32.h mon_hw_STM32.cpp - - -#ifndef _MON_HW_CONF_H_ -#define _MON_HW_CONF_H_ - -// Definition ------------------------------------------------------------------------------------ -// Please select each function for your purpose (selected = set 1) - -#define USE_MEM 1 -#define USE_PORT 1 -#define USE_UART 1 -#define USE_SPI 1 -#define USE_I2C 1 -#define USE_SYS 1 - -#endif // _MON_HW_CONF_H_
--- a/debug_tools/mon_hw_gr-peach.cpp Sun Dec 14 09:17:01 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1840 +0,0 @@
-/*
- * mbed Application program for the mbed LPC1768 Board
- * Monitor program Ver.3 for only for LPC1768
- *
- * Copyright (c) 2010-2014 Kenji Arai / JH1PJL
- * http://www.page.sannet.ne.jp/kenjia/index.html
- * http://mbed.org/users/kenjiArai/
- * Started: May 9th, 2010
- * Created: May 15th, 2010
- * release as "monitor_01" http://mbed.org/users/kenjiArai/code/monitor_01/
- * restart: September 22nd, 2014
- * Revised: Nobember 2nd, 2014
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
- * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
- * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#if defined(TARGET_RZ_A1H)
-#if 0
-// Include ---------------------------------------------------------------------------------------
-#include "mbed.h"
-#include "mon_hw_config.h"
-#include "mon_hw_common.h"
-
-// Object ----------------------------------------------------------------------------------------
-
-// Definition ------------------------------------------------------------------------------------
-// Define clocks
-#define XTAL (12000000UL) // Oscillator frequency
-#define OSC_CLK ( XTAL) // Main oscillator frequency
-#define RTC_CLK ( 32000UL) // RTC oscillator frequency
-#define IRC_OSC ( 4000000UL) // Internal RC oscillator frequency
-
-// RAM -------------------------------------------------------------------------------------------
-uint32_t SystemFrequency;
-
-// ROM / Constant data ---------------------------------------------------------------------------
-#if USE_MEM
-// Memory range data
-const uint32_t mem_range[][2] = { // Memory access range
- { 0x00000000, 0x0007ffff }, // On-chip non-volatile memory // 512KB Flash memory
- { 0x10000000, 0x10007fff }, // On-chip SRAM // 32KB local RAM
- { 0x1fff0000, 0x1fff1fff }, // Boot ROM // 8KB Boot ROM
- { 0x2007c000, 0x2007ffff }, // On-chip SRAM // 16KB AHB SRAM
- { 0x20080000, 0x20083fff } // On-chip SRAM // 16KB AHB SRAM
-};
-#endif // USE_MEM
-
-char *const mon_msg = "HW monitor only for mbed LPC1768 created on "__DATE__","__TIME__"";
-char *const xmsg0 = "Not implimented yet";
-
-char *const hmsg0 = "m - Entry Memory Mode";
-char *const hmsg1 = "m>? -> Help ";
-char *const hmsg2 = "r - Show PORT,I2C,SPI,UART & other Reg.";
-char *const hmsg3 = "r>? -> Help";
-char *const hmsg4 = "sf - System Clock";
-char *const hmsg5 = "sc - System / CPU information";
-char *const hmsg6 = "x - Special command for Debug";
-char *const hmsg7 = "q - Quit (back to called routine)";
-
-// Function prototypes ---------------------------------------------------------------------------
-
-//-------------------------------------------------------------------------------------------------
-// Control Program
-//-------------------------------------------------------------------------------------------------
-// No function
-static void not_yet_impliment( void )
-{
- PRINTF(xmsg0);
- put_rn();
-}
-
-// No function
-#if (USE_MEM==0)||(USE_PORT==0)||(USE_UART==0)||(USE_SPI==0)||(USE_I2C==0)||(USE_SYS==0)
-static void not_select( void )
-{
- PRINTF("Not select the function (refer mon_hw_config.h)");
- put_rn();
-}
-#endif
-
-// Help Massage
-void msg_hlp_hw (void)
-{
- PRINTF(mon_msg);
- put_rn();
- PRINTF(hmsg0);
- put_rn();
- PRINTF(hmsg1);
- put_rn();
- PRINTF(hmsg2);
- put_rn();
- PRINTF(hmsg3);
- put_rn();
- PRINTF(hmsg4);
- put_rn();
- PRINTF(hmsg5);
- put_rn();
- PRINTF(hmsg6);
- put_rn();
- PRINTF(hmsg7);
- put_rn();
-}
-
-#if USE_MEM
-char *const rmsg0 = "FLASH ";
-char *const rmsg1 = "SRAM ";
-char *const rmsg2 = "Boot ROM ";
-char *const rmsg3 = "AHB SRAM0 ";
-char *const rmsg4 = "AHB SRAM1 ";
-
-#include "mon_hw_mem.h"
-#endif // USE_MEM
-
-#if USE_PORT
-void io_condition(uint32_t reg0, uint32_t reg1, uint8_t shift)
-{
- PRINTF("IO->");
- if (reg0 & (1UL << shift)) {
- PRINTF("Output=");
- } else {
- PRINTF("Input =");
- }
- if (reg1 & (1UL << shift)) {
- PUTC('1');
- } else {
- PUTC('0');
- }
-}
-
-void port_config_left(void)
-{
- uint32_t r0,r1;
-
- // p5(P0.9)
- PRINTF("p 5(P0. 9):");
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 18) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 9);
- break;
- case 1:
- PRINTF("I2STX_SDA");
- break;
- case 2:
- PRINTF("MOSI1");
- break;
- case 3:
- PRINTF("MAT2.3");
- break;
- }
- put_rn();
- // p6(P0.8)
- PRINTF("p 6(P0. 8):");
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 16) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 8);
- break;
- case 1:
- PRINTF("I2STX_WS");
- break;
- case 2:
- PRINTF("MISO1");
- break;
- case 3:
- PRINTF("MAT2.2");
- break;
- }
- put_rn();
- // p7(P0.7)
- PRINTF("p 7(P0. 7):");
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 14) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 7);
- break;
- case 1:
- PRINTF("I2STX_CLK");
- break;
- case 2:
- PRINTF("SCK1");
- break;
- case 3:
- PRINTF("MAT2.1");
- break;
- }
- put_rn();
- // p8(P0.6)
- PRINTF("p 8(P0. 6):");
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 12) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 6);
- break;
- case 1:
- PRINTF("I2SRX_SDA");
- break;
- case 2:
- PRINTF("SSEL1");
- break;
- case 3:
- PRINTF("MAT2.0");
- break;
- }
- put_rn();
- // p9(P0.0)
- PRINTF("p 9(P0. 0):");
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 0) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 0);
- break;
- case 1:
- PRINTF("RD1");
- break;
- case 2:
- PRINTF("TXD3");
- break;
- case 3:
- PRINTF("SDA1");
- break;
- }
- put_rn();
- // p10(P0.1)
- PRINTF("p10(P0. 1):");
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 2) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 1);
- break;
- case 1:
- PRINTF("TD1");
- break;
- case 2:
- PRINTF("RXD3");
- break;
- case 3:
- PRINTF("SCL1");
- break;
- }
- put_rn();
- // p11(P0.18)
- PRINTF("p11(P0.18):");
- r0 = LPC_PINCON->PINSEL1;
- r0 = (r0 >> 4) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 18);
- break;
- case 1:
- PRINTF("DCD1");
- break;
- case 2:
- PRINTF("MOSI0");
- break;
- case 3:
- PRINTF("MOSI");
- break;
- }
- put_rn();
- // p12(P0.17)
- PRINTF("p12(P0.17):");
- r0 = LPC_PINCON->PINSEL1;
- r0 = (r0 >> 2) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 17);
- break;
- case 1:
- PRINTF("CTS1");
- break;
- case 2:
- PRINTF("MISO0");
- break;
- case 3:
- PRINTF("MISO");
- break;
- }
- put_rn();
- // p13(P0.15)
- PRINTF("p13(P0.15):");
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 30) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 15);
- break;
- case 1:
- PRINTF("TXD1");
- break;
- case 2:
- PRINTF("SCK0");
- break;
- case 3:
- PRINTF("SCK");
- break;
- }
- put_rn();
- // p14(P0.16)
- PRINTF("p14(P0.16):");
- r0 = LPC_PINCON->PINSEL1;
- r0 = (r0 >> 0) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 16);
- break;
- case 1:
- PRINTF("RXD1");
- break;
- case 2:
- PRINTF("SSEL0");
- break;
- case 3:
- PRINTF("SSEL");
- break;
- }
- put_rn();
- // p15(P0.23)
- PRINTF("p15(P0.23):");
- r0 = LPC_PINCON->PINSEL1;
- r0 = (r0 >> 14) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 23);
- break;
- case 1:
- PRINTF("AD0.0");
- break;
- case 2:
- PRINTF("I2SRX_CLK");
- break;
- case 3:
- PRINTF("CAP3.0");
- break;
- }
- put_rn();
- // p16(P0.24)
- PRINTF("p16(P0.24):");
- r0 = LPC_PINCON->PINSEL1;
- r0 = (r0 >> 16) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 24);
- break;
- case 1:
- PRINTF("AD0.1");
- break;
- case 2:
- PRINTF("I2SRX_WS");
- break;
- case 3:
- PRINTF("CAP3.1");
- break;
- }
- put_rn();
- // p17(P0.25)
- PRINTF("p17(P0.25):");
- r0 = LPC_PINCON->PINSEL1;
- r0 = (r0 >> 18) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 25);
- break;
- case 1:
- PRINTF("AD0.2");
- break;
- case 2:
- PRINTF("I2SRX_SDA");
- break;
- case 3:
- PRINTF("TXD3");
- break;
- }
- put_rn();
- // p18(P0.26)
- PRINTF("p18(P0.26):");
- r0 = LPC_PINCON->PINSEL1;
- r0 = (r0 >> 20) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 26);
- break;
- case 1:
- PRINTF("AD0.3");
- break;
- case 2:
- PRINTF("AOUT");
- break;
- case 3:
- PRINTF("RXD3");
- break;
- }
- put_rn();
- // p19(P1.30)
- PRINTF("p19(P1.30):");
- r0 = LPC_PINCON->PINSEL3;
- r0 = (r0 >> 28) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO1->FIODIR;
- r1 = LPC_GPIO1->FIOPIN;
- io_condition(r0, r1, 30);
- break;
- case 1:
- PRINTF("Reserved");
- break;
- case 2:
- PRINTF("VBUS");
- break;
- case 3:
- PRINTF("AD0.4");
- break;
- }
- put_rn();
- // p20(P1.31)
- PRINTF("p20(P1.31):");
- r0 = LPC_PINCON->PINSEL3;
- r0 = (r0 >> 30) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO1->FIODIR;
- r1 = LPC_GPIO1->FIOPIN;
- io_condition(r0, r1, 31);
- break;
- case 1:
- PRINTF("Reserved");
- break;
- case 2:
- PRINTF("SCK1");
- break;
- case 3:
- PRINTF("AD0.5");
- break;
- }
- put_rn();
-}
-
-void port_config_right(void)
-{
- uint32_t r0, r1;
-
- // p30(P0.4)
- PRINTF("p30(P0. 4):");
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 8) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 4);
- break;
- case 1:
- PRINTF("I2SRX_CLK");
- break;
- case 2:
- PRINTF("RD2");
- break;
- case 3:
- PRINTF("CAP2.0");
- break;
- }
- put_rn();
- // p29(P0.5)
- PRINTF("p29(P0. 5):");
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 10) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 5);
- break;
- case 1:
- PRINTF("I2SRX_WS");
- break;
- case 2:
- PRINTF("TD2");
- break;
- case 3:
- PRINTF("CAP2.1");
- break;
- }
- put_rn();
- // p28(P0.10)
- PRINTF("p28(P0.10):");
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 20) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 10);
- break;
- case 1:
- PRINTF("TXD2");
- break;
- case 2:
- PRINTF("SDA2");
- break;
- case 3:
- PRINTF("MAT3.0");
- break;
- }
- put_rn();
- // p27(P0.11)
- PRINTF("p27(P0.11):");
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 22) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO0->FIODIR;
- r1 = LPC_GPIO0->FIOPIN;
- io_condition(r0, r1, 11);
- break;
- case 1:
- PRINTF("RXD2");
- break;
- case 2:
- PRINTF("SCL2");
- break;
- case 3:
- PRINTF("MAT3.1");
- break;
- }
- put_rn();
- // p26(P2.0)
- PRINTF("p26(P2. 0):");
- r0 = LPC_PINCON->PINSEL4;
- r0 = (r0 >> 0) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO2->FIODIR;
- r1 = LPC_GPIO2->FIOPIN;
- io_condition(r0, r1, 0);
- break;
- case 1:
- PRINTF("PWM1.1");
- break;
- case 2:
- PRINTF("TXD1");
- break;
- case 3:
- PRINTF("Reserved");
- break;
- }
- put_rn();
- // p25(P2.1)
- PRINTF("p25(P2. 1):");
- r0 = LPC_PINCON->PINSEL4;
- r0 = (r0 >> 2) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO2->FIODIR;
- r1 = LPC_GPIO2->FIOPIN;
- io_condition(r0, r1, 1);
- break;
- case 1:
- PRINTF("PWM1.2");
- break;
- case 2:
- PRINTF("RXD1");
- break;
- case 3:
- PRINTF("Reserved");
- break;
- }
- put_rn();
- // p24(P2.2)
- PRINTF("p24(P2. 2):");
- r0 = LPC_PINCON->PINSEL4;
- r0 = (r0 >> 4) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO2->FIODIR;
- r1 = LPC_GPIO2->FIOPIN;
- io_condition(r0, r1, 2);
- break;
- case 1:
- PRINTF("PWM1.3");
- break;
- case 2:
- PRINTF("CTS1");
- break;
- case 3:
- PRINTF("Reserved");
- break;
- }
- put_rn();
- // p23(P2.3)
- PRINTF("p23(P2. 3):");
- r0 = LPC_PINCON->PINSEL4;
- r0 = (r0 >> 6) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO2->FIODIR;
- r1 = LPC_GPIO2->FIOPIN;
- io_condition(r0, r1, 3);
- break;
- case 1:
- PRINTF("PWM1.4");
- break;
- case 2:
- PRINTF("DCD1");
- break;
- case 3:
- PRINTF("Reserved");
- break;
- }
- put_rn();
- // p22(P2.4)
- PRINTF("p22(P2. 4):");
- r0 = LPC_PINCON->PINSEL4;
- r0 = (r0 >> 8) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO2->FIODIR;
- r1 = LPC_GPIO2->FIOPIN;
- io_condition(r0, r1, 4);
- break;
- case 1:
- PRINTF("PWM1.5");
- break;
- case 2:
- PRINTF("DSR1");
- break;
- case 3:
- PRINTF("Reserved");
- break;
- }
- put_rn();
- // p21(P2.5)
- PRINTF("p21(P2. 5):");
- r0 = LPC_PINCON->PINSEL4;
- r0 = (r0 >> 10) & 0x03;
- switch (r0) {
- case 0:
- r0 = LPC_GPIO2->FIODIR;
- r1 = LPC_GPIO2->FIOPIN;
- io_condition(r0, r1, 5);
- break;
- case 1:
- PRINTF("PWM1.6");
- break;
- case 2:
- PRINTF("DTR1");
- break;
- case 3:
- PRINTF("Reserved");
- break;
- }
- put_rn();
-}
-#endif // USE_PORT
-
-//#if USE_SYS
-void cpu_inf ( void )
-{
- unsigned long m1, m2;
-
- m1 = SCB->CPUID;
- m2 = ( m1 >> 24 );
- if ( m2 == 0x41 ) {
- put_r();
- PRINTF("CPU = ARM ");
- } else {
- put_r();
- PRINTF("CPU = NOT ARM ");
- }
- m2 = ( m1 >> 4 ) & 0xfff;
- if ( m2 == 0xc23 ) {
- PRINTF("Cortex-M3");
- put_rn();
- } else {
- PRINTF("NOT Cortex-M3");
- put_rn();
- }
- m2 = ( m1 >> 20 ) & 0x0f;
- PRINTF("Variant:%x", m2);
- put_rn();
- m2 = m1 & 0x7;
- PRINTF("Revision:%x", m2);
- put_rn();
-}
-//#endif // USE_SYS
-
-// Calculate CPU System Clock Frequency
-void get_freq ( int pr )
-{
- if(pr) {
- put_r();
- PRINTF("System Clock = %dHz",SystemFrequency );
- put_rn();
- }
- if (((LPC_SC->PLL0STAT >> 24) & 3) == 3) {/* If PLL0 enabled and connected */
- if(pr) {
- PRINTF("PLL0 enabled");
- put_rn();
- }
- switch (LPC_SC->CLKSRCSEL & 0x03) {
- case 0: /* Internal RC oscillator => PLL0 */
- case 3: /* Reserved, default to Internal RC */
- if(pr) {
- PRINTF("Internal RC Oscillator");
- put_rn();
- }
- SystemFrequency = (IRC_OSC *
- (((2 * ((LPC_SC->PLL0STAT & 0x7FFF) + 1))) /
- (((LPC_SC->PLL0STAT >> 16) & 0xFF) + 1)) /
- ((LPC_SC->CCLKCFG & 0xFF)+ 1));
- break;
- case 1: /* Main oscillator => PLL0 */
- if(pr) {
- PRINTF("Xtal Osc Clock = %dHz",XTAL );
- put_rn();
- }
- SystemFrequency = (OSC_CLK *
- (((2 * ((LPC_SC->PLL0STAT & 0x7FFF) + 1))) /
- (((LPC_SC->PLL0STAT >> 16) & 0xFF) + 1)) /
- ((LPC_SC->CCLKCFG & 0xFF)+ 1));
- break;
- case 2: /* RTC oscillator => PLL0 */
- if(pr) {
- PRINTF("RTC Xtal Oscillator f = %dHz", RTC_CLK );
- put_rn();
- }
- SystemFrequency = (RTC_CLK *
- (((2 * ((LPC_SC->PLL0STAT & 0x7FFF) + 1))) /
- (((LPC_SC->PLL0STAT >> 16) & 0xFF) + 1)) /
- ((LPC_SC->CCLKCFG & 0xFF)+ 1));
- break;
- }
- } else {
- if(pr) {
- PRINTF("PLL0 disabled");
- }
- switch (LPC_SC->CLKSRCSEL & 0x03) {
- case 0: /* Internal RC oscillator => PLL0 */
- case 3: /* Reserved, default to Internal RC */
- if(pr) {
- PRINTF("Internal RC Oscillator");
- put_rn();
- }
- SystemFrequency = IRC_OSC / ((LPC_SC->CCLKCFG & 0xFF)+ 1);
- break;
- case 1: /* Main oscillator => PLL0 */
- if(pr) {
- PRINTF("Xtal Osc Clock = %dHz",XTAL );
- put_rn();
- }
- SystemFrequency = OSC_CLK / ((LPC_SC->CCLKCFG & 0xFF)+ 1);
- break;
- case 2: /* RTC oscillator => PLL0 */
- if(pr) {
- PRINTF("RTC Xtal Oscillator f = %dHz", RTC_CLK );
- put_rn();
- }
- SystemFrequency = RTC_CLK / ((LPC_SC->CCLKCFG & 0xFF)+ 1);
- break;
- }
- }
-}
-
-#if (USE_UART==1)||(USE_SPI==1)||(USE_I2C==1)
-char *const uismsg0 = "is enable";
-char *const uismsg1 = "is disable";
-char *const uismsg2 = "(mbed pins are not avairable)";
-char *const uismsg3 = "Other";
-#endif
-
-#if USE_UART
-// Show 16bit register contents
-void reg_print(uint16_t size, uint16_t reg)
-{
- uint16_t i, j, k, n;
-
- if (size == 8) {
- PRINTF(" 7, 6, 5, 4, 3, 2, 1, 0");
- put_rn();
- i = 8;
- n = 0x80;
- } else if (size == 16) {
- PRINTF( "15,14,13,12,11,10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0" );
- put_rn();
- i = 16;
- n = 0x8000;
- } else {
- PRINTF("0x%08x", reg);
- return;
- }
- PUTC(' ');
- for (; i>0; i--) {
- k = n >> (size-i);
- j = reg & k;
- if (j) {
- PUTC('1');
- } else {
- PUTC('0');
- }
- PUTC(' ');
- PUTC(' ');
- }
- PRINTF(" (0x%04x)", reg);
-}
-
-void uart_reg(uint8_t uart)
-{
- uint32_t c_lcr,c_fdr,c_dll,c_dlm;
- uint32_t divaddval,mulval,div,baud;
-
- PRINTF("<Show UART%d status>", uart);
- put_rn();
- c_lcr = c_fdr = c_dll = c_dlm = 0;
- divaddval = mulval = div = baud = 0;
- get_freq(0);
- switch (uart) {
- case 0:
- if (LPC_SC->PCONP & (1UL<<3)) {
- c_fdr = LPC_UART0->FDR;
- c_lcr = LPC_UART0->LCR;
- // set LCR[DLAB] to enable writing to divider registers
- LPC_UART0->LCR |= (1 << 7);
- c_dll = LPC_UART0->DLL;
- c_dlm = LPC_UART0->DLM;
- // clear LCR[DLAB]
- LPC_UART0->LCR &= ~(1 << 7);
- div = (LPC_SC->PCLKSEL0 >> 6) & 0x3;
- }
- break;
- case 1:
- if (LPC_SC->PCONP & (1UL<<4)) {
- c_fdr = LPC_UART1->FDR;
- c_lcr = LPC_UART1->LCR;
- // set LCR[DLAB] to enable writing to divider registers
- LPC_UART1->LCR |= (1 << 7);
- c_dll = LPC_UART1->DLL;
- c_dlm = LPC_UART1->DLM;
- // clear LCR[DLAB]
- LPC_UART1->LCR &= ~(1 << 7);
- div = (LPC_SC->PCLKSEL0 >> 8) & 0x3;
- }
- break;
- case 2:
- if (LPC_SC->PCONP & (1UL<<24)) {
- c_fdr = LPC_UART2->FDR;
- c_lcr = LPC_UART2->LCR;
- // set LCR[DLAB] to enable writing to divider registers
- LPC_UART2->LCR |= (1 << 7);
- c_dll = LPC_UART2->DLL;
- c_dlm = LPC_UART2->DLM;
- // clear LCR[DLAB]
- LPC_UART2->LCR &= ~(1 << 7);
- div = (LPC_SC->PCLKSEL1 >> 16) & 0x3;
- }
- break;
- case 3:
- if (LPC_SC->PCONP & (1UL<<25)) {
- c_fdr = LPC_UART3->FDR;
- c_lcr = LPC_UART3->LCR;
- // set LCR[DLAB] to enable writing to divider registers
- LPC_UART3->LCR |= (1 << 7);
- c_dll = LPC_UART3->DLL;
- c_dlm = LPC_UART3->DLM;
- // clear LCR[DLAB]
- LPC_UART3->LCR &= ~(1 << 7);
- div = (LPC_SC->PCLKSEL1 >> 18) & 0x3;
- }
- break;
- default:
- break;
- }
- if ((c_fdr == 0)&&(c_lcr == 0)&&(c_dll == 0)) {
- PRINTF("NOT Avairable (power off the UART module)");
- } else {
- // condition
- PRINTF("Word Length: ");
- switch ((c_lcr >> 0) & 0x03) {
- case 0:
- PUTC('5');
- break;
- case 1:
- PUTC('6');
- break;
- case 2:
- PUTC('7');
- break;
- case 3:
- PUTC('8');
- break;
- }
- PRINTF("-bit");
- put_rn();
- PRINTF("Stop bit: ");
- if (c_lcr & 0x04) {
- PUTC('1');
- } else {
- PUTC('2');
- }
- PRINTF("-bit");
- put_rn();
- PRINTF("Parity: ");
- if (c_lcr & 0x08) {
- switch ((c_lcr >> 4) & 0x03) {
- case 0:
- PRINTF("Odd");
- break;
- case 1:
- PRINTF("Even");
- break;
- case 2:
- PRINTF("Forced '1'");
- break;
- case 3:
- PRINTF("Forced '0'");
- break;
- }
- PRINTF(" parity");
- } else {
- PRINTF("None-Parity");
- }
- put_rn();
- switch (div) {
- case 0:
- div = 4;
- break;
- case 1:
- div = 1;
- break;
- case 2:
- div = 2;
- break;
- case 3:
- div = 8;
- break;
- }
- divaddval = (c_fdr >> 0) & 0x0f;
- mulval = (c_fdr >> 4) & 0x0f;
- baud = (SystemCoreClock/div)/(16 * (256 * c_dlm + c_dll) * (1 + divaddval/mulval));
- PRINTF("Baud rate: %d bps", baud);
- put_rn();
- PRINTF(" = PCLK(=Sys/div)/(16 x (256 x DLM + DLL) x (1 + DivAddVal/MulVal)");
- put_rn();
- PRINTF(" = (%d/%d)/(16 x (256 x %d + %d) x (1 + %d/%d)",
- SystemCoreClock,div,c_dlm,c_dll,divaddval,mulval);
- }
- put_rn();
-}
-
-void uart_io_print (void)
-{
- PRINTF("<Show IO Pin>");
- put_rn();
-}
-
-void uart_io_reg0 (void)
-{
- uint32_t r0;
-
- PRINTF("UART0/USBTX(P0.2),USBRX(P0.3):");
- // P0.2
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 4) & 0x03;
- if (r0 == 1) {
- PRINTF("TXD0 ");
- } else {
- PRINTF(uismsg3);
- }
- // P0.3
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 6) & 0x03;
- if (r0 == 1) {
- PRINTF(",RXD0");
- } else {
- PRINTF(",%s", uismsg3);
- }
- PRINTF("(connected to PC via USB)");
- put_rn();
-}
-
-void uart_io_reg1 (void)
-{
- uint32_t r0;
-
- PRINTF("UART1/ p13(P0.15), p14(P0.16):");
- // P0.15
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 30) & 0x03;
- if (r0 == 1) {
- PRINTF("TXD1 ");
- } else {
- PRINTF(uismsg3);
- }
- // P0.16
- r0 = LPC_PINCON->PINSEL1;
- r0 = (r0 >> 2) & 0x03;
- if (r0 == 1) {
- PRINTF(",RXD1");
- } else {
- PRINTF(",%s", uismsg3);
- }
- put_rn();
-}
-
-void uart_io_reg2 (void)
-{
- uint32_t r0;
-
- PRINTF("UART2/ p28(P0.10), p27(P0.11):");
- // P0.10
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 20) & 0x03;
- if (r0 == 1) {
- PRINTF("TXD2 ");
- } else {
- PRINTF(uismsg3);
- }
- // P0.11
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 22) & 0x03;
- if (r0 == 1) {
- PRINTF(",RXD2");
- } else {
- PRINTF(",%s", uismsg3);
- }
- put_rn();
-}
-
-void uart_io_reg3 (void)
-{
- uint32_t r0;
-
- PRINTF("UART3/ p 9(P0. 0), p10(P0. 1):");
- // P0.0
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 0) & 0x03;
- if (r0 == 2) {
- PRINTF("TXD3 ");
- } else {
- PRINTF(uismsg3);
- }
- // P0.1
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 2) & 0x03;
- if (r0 == 2) {
- PRINTF(",RXD3");
- } else {
- PRINTF(",%s", uismsg3);
- }
- put_rn();
-}
-#endif //USE_UART
-
-#if USE_SPI
-void spi_io_reg (void)
-{
- uint32_t r0;
-
- PRINTF("<Show IO Pin>");
- put_rn();
- //-----------------------------------------------------
- PRINTF("SPI /p11(P0.18),p12(P0.17),p13(P0.15):");
- // p11(P0.18)
- r0 = LPC_PINCON->PINSEL1;
- r0 = (r0 >> 4) & 0x03;
- if (r0 == 3) {
- PRINTF(",MOSI ");
- } else {
- PRINTF("%s", uismsg3);
- }
- // p12(P0.17)
- r0 = LPC_PINCON->PINSEL1;
- r0 = (r0 >> 2) & 0x03;
- if (r0 == 3) {
- PRINTF(",MISO ");
- } else {
- PRINTF(",%s", uismsg3);
- }
- // p13(P0.15)
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 30) & 0x03;
- if (r0 == 3) {
- PRINTF(",SCK ");
- } else {
- PRINTF(",%s", uismsg3);
- }
- put_rn();
- //-----------------------------------------------------
- PRINTF("SSP0/p11(P0.18),p12(P0.17),p13(P0.15):");
- // p11(P0.18)
- r0 = LPC_PINCON->PINSEL1;
- r0 = (r0 >> 4) & 0x03;
- if (r0 == 2) {
- PRINTF(",MOSI0");
- } else {
- PRINTF("%s", uismsg3);
- }
- // p12(P0.17)
- r0 = LPC_PINCON->PINSEL1;
- r0 = (r0 >> 2) & 0x03;
- if (r0 == 2) {
- PRINTF(",MISO0");
- } else {
- PRINTF(",%s", uismsg3);
- }
- // p13(P0.15)
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 30) & 0x03;
- if (r0 == 2) {
- PRINTF(",SCK0 ");
- } else {
- PRINTF(",%s", uismsg3);
- }
- put_rn();
- //-----------------------------------------------------
- PRINTF("SSP1/p 5(P0. 9),p 6(P0. 8),p 7(P0. 7):");
- // p5(P0.9)
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 18) & 0x03;
- if (r0 == 2) {
- PRINTF("MOSI1");
- } else {
- PRINTF(uismsg3);
- }
- // p6(P0.8)
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 16) & 0x03;
- if (r0 == 2) {
- PRINTF(",MISO1");
- } else {
- PRINTF(",%s", uismsg3);
- }
- // p7(P0.7)
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 14) & 0x03;
- if (r0 == 2) {
- PRINTF(",SCK1");
- } else {
- PRINTF(",%s", uismsg3);
- }
- put_rn();
-}
-
-void spi_freq (void)
-{
- uint32_t div, r0, r1;
-
- get_freq(0);
- //-----------------------------------------------------
- // SPI
- PRINTF("<Show SPI status>");
- put_rn();
- if (LPC_SC->PCONP & (1UL<<8)) {
- div = (LPC_SC->PCLKSEL0 >> 16) & 0x3;
- switch (div) {
- case 0:
- div = 4;
- break;
- case 1:
- div = 1;
- break;
- case 2:
- div = 2;
- break;
- case 3:
- div = 8;
- break;
- }
- r0 = LPC_SPI->SPCR;
- PRINTF("Data length: ");
- if (r0 & 0x04) {
- r1 = (r0 >> 8) & 0x0f;
- if (r1 == 0) {
- r1 = 16;
- }
- PRINTF("%d", r1);
- } else {
- PUTC('8');
- }
- PRINTF("bit, ");
- PRINTF("CPHA: ");
- PRINTF("%d", (r0 >> 3) & 0x01);
- PRINTF(", CPOL: ");
- PRINTF("%d", (r0 >> 4) & 0x01);
- put_rn();
- if ((r0 >> 5) & 0x01) {
- PRINTF("Master");
- } else {
- PRINTF("Slave");
- }
- PRINTF(" Mode");
- put_rn();
- if ((r0 >> 6) & 0x01) {
- PRINTF("MSB(bit7)");
- } else {
- PRINTF("LSB(Bit0)");
- }
- PRINTF(" first");
- put_rn();
- r1 = LPC_SPI->SPCCR;
- PRINTF("CLK = %d Hz", SystemCoreClock/div/r1);
- put_rn();
- PRINTF(" = PCLK_SPI(=Sys/div)/SPCCR0");
- put_rn();
- PRINTF(" = (%d/%d)/%d", SystemCoreClock, div, r1, SystemCoreClock/div/r1);
- } else {
- PRINTF("NOT Avairable (power off the module)");
- }
- put_rn();
- //-----------------------------------------------------
- // SSP0
- PRINTF("<Show SSP0 status>");
- put_rn();
- if (LPC_SC->PCONP & (1UL<<21)) {
- r0 = LPC_SSP0->CR1;
- if (r0 & 0x02) {
- div = (LPC_SC->PCLKSEL1 >> 10) & 0x3;
- switch (div) {
- case 0:
- div = 4;
- break;
- case 1:
- div = 1;
- break;
- case 2:
- div = 2;
- break;
- case 3:
- div = 8;
- break;
- }
- r1 = LPC_SSP0->CR0;
- PRINTF("SSP Mode: ");
- r1 = (r1 >> 4) & 0x03;
- switch (r1) {
- case 0:
- PRINTF("SPI");
- break;
- case 1:
- PRINTF("TI");
- break;
- case 2:
- PRINTF("Microwire");
- break;
- case 3:
- PRINTF("Not support");
- break;
- }
- put_rn();
- r1 = LPC_SSP0->CR0;
- PRINTF("Data length: ");
- PRINTF("%d", r1 & 0x0f);
- PRINTF("bit, ");
- PRINTF("CPHA: ");
- PRINTF("%d", (r1 >> 7) & 0x01);
- PRINTF(", CPOL: ");
- PRINTF("%d", (r1 >> 6) & 0x01);
- put_rn();
- if ((r0 >> 2) & 0x01) {
- PRINTF("Slave");
- } else {
- PRINTF("Master");
- }
- PRINTF(" Mode");
- put_rn();
- r1 = LPC_SSP0->CR0;
- r1 = (r1 >> 8) & 0xff;
- r0 = LPC_SSP0->CPSR;
- r0 = (r0 >> 0) & 0x0f;
- PRINTF("CLK = %d Hz", SystemCoreClock/div/(r0 * (r1+1)));
- put_rn();
- PRINTF(" = PCLK_SSP0(=Sys/div)/(CPSDVSR x [SCR+1])");
- put_rn();
- PRINTF(" = (%d/%d)/(%d x [%d + 1])", SystemCoreClock, div, r0, r1);
- } else {
- PRINTF("SSP0 is disabled");
- }
- } else {
- PRINTF("NOT Avairable (power off the module)");
- }
- put_rn();
- //-----------------------------------------------------
- // SSP1
- PRINTF("<Show SSP1 status>");
- put_rn();
- if (LPC_SC->PCONP & (1UL<<10)) {
- r0 = LPC_SSP1->CR1;
- if (r0 & 0x02) {
- div = (LPC_SC->PCLKSEL0 >> 20) & 0x3;
- switch (div) {
- case 0:
- div = 4;
- break;
- case 1:
- div = 1;
- break;
- case 2:
- div = 2;
- break;
- case 3:
- div = 8;
- break;
- }
- r1 = LPC_SSP1->CR0;
- PRINTF("SSP Mode: ");
- r1 = (r1 >> 4) & 0x03;
- switch (r1) {
- case 0:
- PRINTF("SPI");
- break;
- case 1:
- PRINTF("TI");
- break;
- case 2:
- PRINTF("Microwire");
- break;
- case 3:
- PRINTF("Not support");
- break;
- }
- put_rn();
- r1 = LPC_SSP1->CR0;
- PRINTF("Data length: ");
- PRINTF("%d", r1 & 0x0f);
- PRINTF("bit, ");
- PRINTF("CPHA: ");
- PRINTF("%d", (r1 >> 7) & 0x01);
- PRINTF(", CPOL: ");
- PRINTF("%d", (r1 >> 6) & 0x01);
- put_rn();
- if ((r0 >> 2) & 0x01) {
- PRINTF("Slave");
- } else {
- PRINTF("Master");
- }
- PRINTF(" Mode");
- put_rn();
- r1 = LPC_SSP1->CR0;
- r1 = (r1 >> 8) & 0xff;
- r0 = LPC_SSP1->CPSR;
- r0 = (r0 >> 0) & 0x0f;
- PRINTF("CLK = %d Hz", SystemCoreClock/div/(r0 * (r1+1)));
- put_rn();
- PRINTF(" = PCLK_SSP1(=Sys/div)/(CPSDVSR x [SCR+1])");
- put_rn();
- PRINTF(" = (%d/%d)/(%d x [%d + 1])", SystemCoreClock, div, r0, r1);
- } else {
- PRINTF("SSP1 is disabled");
- }
- } else {
- PRINTF("NOT Avairable (power off the module)");
- }
- put_rn();
-}
-#endif
-
-#if USE_I2C
-void i2c_io_reg (void)
-{
- uint32_t r0;
-
- PRINTF("<Show IO Pin>");
- put_rn();
- //-----------------------------------------------------
- PRINTF("I2C0/pxx(P0.27),pxx(P0.28):");
- // P0.27
- r0 = LPC_PINCON->PINSEL1;
- r0 = (r0 >> 22) & 0x03;
- if (r0 == 3) {
- PRINTF("SDA0");
- } else {
- PRINTF(uismsg3);
- }
- // P0.28
- r0 = LPC_PINCON->PINSEL1;
- r0 = (r0 >> 24) & 0x03;
- if (r0 == 3) {
- PRINTF(",SCL0");
- } else {
- PRINTF(",%s", uismsg3);
- }
- PRINTF(uismsg2);
- put_rn();
- //-----------------------------------------------------
- PRINTF("I2C1/p 9(P0. 0),p10(P0. 1):");
- // P0.0
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 0) & 0x03;
- if (r0 == 3) {
- PRINTF("SDA1");
- } else {
- PRINTF(uismsg3);
- }
- // P0.1
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 2) & 0x03;
- if (r0 == 3) {
- PRINTF(",SCL1");
- } else {
- PRINTF(",%s", uismsg3);
- }
- put_rn();
- //-----------------------------------------------------
- PRINTF("I2C1/pxx(P0.19),pxx(P0.20):");
- // P0.19
- r0 = LPC_PINCON->PINSEL1;
- r0 = (r0 >> 6) & 0x03;
- if (r0 == 3) {
- PRINTF("SDA1");
- } else {
- PRINTF(uismsg3);
- }
- // P0.20
- r0 = LPC_PINCON->PINSEL1;
- r0 = (r0 >> 8) & 0x03;
- if (r0 == 3) {
- PRINTF(",SCL1");
- } else {
- PRINTF(",%s", uismsg3);
- }
- PRINTF(uismsg2);
- put_rn();
- //-----------------------------------------------------
- PRINTF("I2C2/p28(P0.10),p27(P0.11):");
- // P0.10
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 20) & 0x03;
- if (r0 == 3) {
- PRINTF("SDA2");
- } else {
- PRINTF(uismsg3);
- }
- // P0.11
- r0 = LPC_PINCON->PINSEL0;
- r0 = (r0 >> 22) & 0x03;
- if (r0 == 3) {
- PRINTF(",SCL2");
- } else {
- PRINTF(",%s", uismsg3);
- }
- put_rn();
-}
-
-char *const msg_cal = " = I2CPCLK(=Sys/div)/(SCLH+SCLL)";
-
-void i2c_freq (void)
-{
- uint32_t r0, r1, r2, r3;
-
- get_freq(0);
- // I2C0
- r0 = LPC_I2C0->I2SCLL;
- r1 = LPC_I2C0->I2SCLH;
- r2 = LPC_I2C0->I2CONSET;
- r3 = (LPC_SC->PCLKSEL0 >> 14) & 0x3;
- switch (r3) {
- case 0:
- r3 = 4;
- break;
- case 1:
- r3 = 1;
- break;
- case 2:
- r3 = 2;
- break;
- case 3:
- r3 = 8;
- break;
- }
- PRINTF("<I2C Status>");
- put_rn();
- //-----------------------------------------------------
- PRINTF("I2C0 ");
- if (r2 & 0x40) {
- PRINTF(uismsg0);
- put_rn();
- PRINTF("CLK = %d Hz", SystemCoreClock/r3/(r0+r1));
- put_rn();
- PRINTF(msg_cal);
- put_rn();
- PRINTF(" = (%d/%d)/(%d+%d)", SystemCoreClock,r3, r0, r1);
- } else {
- PRINTF(uismsg1);
- }
- put_rn();
- //-----------------------------------------------------
- // I2C1
- r0 = LPC_I2C1->I2SCLL;
- r1 = LPC_I2C1->I2SCLH;
- r2 = LPC_I2C1->I2CONSET;
- r3 = (LPC_SC->PCLKSEL1 >> 6) & 0x3;
- switch (r3) {
- case 0:
- r3 = 4;
- break;
- case 1:
- r3 = 1;
- break;
- case 2:
- r3 = 2;
- break;
- case 3:
- r3 = 8;
- break;
- }
- PRINTF("I2C1 ");
- if (r2 & 0x40) {
- PRINTF(uismsg0);
- put_rn();
- PRINTF("CLK = %d Hz", SystemCoreClock/r3/(r0+r1));
- put_rn();
- PRINTF(msg_cal);
- put_rn();
- PRINTF(" = (%d/%d)/(%d+%d)", SystemCoreClock,r3, r0, r1);
- } else {
- PRINTF(uismsg1);
- }
- put_rn();
- //-----------------------------------------------------
- // I2C2
- r0 = LPC_I2C2->I2SCLL;
- r1 = LPC_I2C2->I2SCLH;
- r2 = LPC_I2C2->I2CONSET;
- r3 = (LPC_SC->PCLKSEL1 >> 20) & 0x3;
- switch (r3) {
- case 0:
- r3 = 4;
- break;
- case 1:
- r3 = 1;
- break;
- case 2:
- r3 = 2;
- break;
- case 3:
- r3 = 8;
- break;
- }
- PRINTF("I2C2 ");
- if (r2 & 0x40) {
- PRINTF(uismsg0);
- put_rn();
- PRINTF("CLK = %d Hz", SystemCoreClock/r3/(r0+r1));
- put_rn();
- PRINTF(msg_cal);
- put_rn();
- PRINTF(" = (%d/%d)/(%d+%d)", SystemCoreClock,r3, r0, r1);
- } else {
- PRINTF(uismsg1);
- }
- put_rn();
-}
-#endif
-
-//-----------------------------------------------------------------------------
-// Monitor Main Program
-//-----------------------------------------------------------------------------
-int mon_hw(void)
-{
- char *ptr;
-
- put_r();
- PRINTF("%s [Help:'?' key]", mon_msg);
- put_rn();
- get_freq(0);
- for (;;) {
- put_r();
- PUTC('>');
- ptr = linebuf;
- get_line(ptr, buf_size);
- put_r();
- switch (*ptr++) {
- //---------------------------------------------------------------------------------
- // Memory
- //---------------------------------------------------------------------------------
- case 'm' :
-#if USE_MEM
- mem_inf(ptr);
- put_rn();
-#else
- not_select();
-#endif // USE_MEM
- break;
- //--------------------------------------------------------------------------------------
- // Register
- //--------------------------------------------------------------------------------------
- case 'r' :
- uint8_t r_flg;
- put_r();
- PRINTF("Reg. Mode p,u,i,s,t,a,d,l,w,c & ?");
- put_rn();
- r_flg = 0;
- for (; r_flg != 0xff;) {
- PRINTF("r>");
- ptr = linebuf;
- get_line(ptr, buf_size);
- put_r();
- switch(*ptr++) {
- case 'p' :
-#if USE_PORT
- put_r();
- switch(*ptr++) {
- case 'l' :
- port_config_left();
- break;
- case 'r' :
- port_config_right();
- break;
- case '*' :
- port_config_left();
- port_config_right();
- break;
- case '?' :
- PRINTF("Enter pl,pr and p* for all");
- put_rn();
- break;;
- default:
- PUTC('?');
- put_rn();
- break;
- }
-#else
- not_select();
-#endif // USE_PORT
- break;
- case 'u' :
-#if USE_UART
- put_r();
- switch(*ptr++) {
- case '0' :
- uart_io_print();
- uart_io_reg0();
- uart_reg(0);
- break;
- case '1' :
- uart_io_print();
- uart_io_reg1();
- uart_reg(1);
- break;
- case '2' :
- uart_io_print();
- uart_io_reg2();
- uart_reg(2);
- break;
- case '3' :
- uart_io_print();
- uart_io_reg3();
- uart_reg(3);
- break;
- case '*' :
- uart_io_print();
- uart_io_reg0();
- uart_io_reg1();
- uart_io_reg2();
- uart_io_reg3();
- break;
- case '?' :
- PRINTF("Enter u0,u1,u2,u3 for each UART ");
- PRINTF("or u* for UART port assignment");
- put_rn();
- break;
- default:
- PUTC('?');
- put_rn();
- break;
- }
-#else
- not_select();
-#endif // USE_UART
- break;
- case 'i' :
-#if USE_I2C
- put_r();
- i2c_io_reg();
- i2c_freq();
-#else
- not_select();
-#endif // USE_I2C
- break;
- case 's' :
-#if USE_SPI
- put_r();
- spi_io_reg();
- spi_freq();
-#else
- not_select();
-#endif // USE_SPI
- break;
- case 't' : //
- not_yet_impliment();
- break;
- case 'a' : //
- not_yet_impliment();
- break;
- case 'd' : //
- not_yet_impliment();
- break;
- case 'w' : //
- not_yet_impliment();
- break;
- case 'l' : //
- not_yet_impliment();
- break;
- case 'c' : //
- not_yet_impliment();
- break;
- case 'x' : //
- not_yet_impliment();
- break;
- case 'y' : //
- not_yet_impliment();
- break;
- case 'q' : // quit
- r_flg = 0xff;
- break;
- case '?' :
- PRINTF("p - I/O Pin Config. pl(p5 to p20) & pr(p21 to p30)");
- put_rn();
- PRINTF("u - UART u0,1,2,3 or u* (port assignment)");
- put_rn();
- PRINTF("i - I2C");
- put_rn();
- PRINTF("s - SPI/SSP");
- put_rn();
- PRINTF("t - TIMER");
- put_rn();
- PRINTF("a - ADC");
- put_rn();
- PRINTF("d - DAC");
- put_rn();
- PRINTF("l - LDC");
- put_rn();
- PRINTF("w - WWDG");
- put_rn();
- PRINTF("c - COMP");
- put_rn();
- PRINTF("q - Exit mode");
- put_rn();
- break;
- default:
- PUTC('?');
- put_rn();
- }
- }
- PRINTF("Return to All Mode");
- put_rn();
- break;
- //---------------------------------------------------------------------------------
- // System
- //---------------------------------------------------------------------------------
- case 's' : // System related information
-#if USE_SYS
- switch (*ptr++) {
- case 'f' : // sc - show system clock frequency
- get_freq(1);
- break;
- case 'c' : // sc - show system CPU information
- cpu_inf();
- break;
- case '?' :
- default:
- put_r();
- PRINTF("sc - System CPU information");
- put_rn();
- PRINTF("sf - System Clock");
- put_rn();
- break;
- }
-#else
- not_select();
-#endif // USE_SYS
- break;
- //-----------------------------------------------------------------------------------------
- // Help
- //-----------------------------------------------------------------------------------------
- case '?' :
- msg_hlp_hw();
- break;
- //-----------------------------------------------------------------------------------------
- // Return to main routine
- //-----------------------------------------------------------------------------------------
- case 'q' : // Quit
- put_r();
- PRINTF("Return to monitor");
- put_rn();
- return 0;
- //-----------------------------------------------------------------------------------------
- // Special command for DEBUG
- //-----------------------------------------------------------------------------------------
- case 'x' :
- not_yet_impliment();
- break;
- //-----------------------------------------------------------------------------------------
- // no support
- //-----------------------------------------------------------------------------------------
- default:
- PUTC('?');
- put_rn();
- break;
- }
- }
-}
-#endif
-#endif // defined(TARGET_RZ_A1H)
--- a/debug_tools/mon_hw_mem.h Sun Dec 14 09:17:01 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,231 +0,0 @@
-/*
- * Monitor program / Memory control part
- *
- * Copyright (c) 2010-2014 Kenji Arai / JH1PJL
- * http://www.page.sannet.ne.jp/kenjia/index.html
- * http://mbed.org/users/kenjiArai/
- * Separated: October 13th, 2014 from mon_hw.cpp
- * Revised: Nobember 2nd, 2014
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
- * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
- * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-//-------------------------------------------------------------------------------------------------
-// Control Program
-//-------------------------------------------------------------------------------------------------
-// Range check for Memory dump
-static void check_range( MEMO * mem )
-{
- uint8_t i;
- uint32_t m;
-
- mem->mflg = ERR_NOTHING;
- for ( i = 0 ; i < 5 ; i++ ) {
- if ( mem->mstr >= mem_range[i][0]) {
- if ( mem->mstr < mem_range[i][1] ) {
- m = mem->mstr + mem->msiz;
- if ( m < mem_range[i][1]) {
- return; // no modification
- } else {
- m = mem_range[i][1];
- mem->msiz = m - mem->mstr + 1;
- mem->mflg = ERR_MODIFY_SIZ;
- return; // modified size
- }
- }
- }
- }
- mem->mflg = ERR_OUT_OF_RANGE;
- mem->mstr = 0;
- mem->msiz = 0;
- return ;
-}
-
-// Memory dump error massage
-void error_print ( unsigned char flg )
-{
- switch (flg) {
- case ERR_MODIFY_SIZ :
- put_r();
- PRINTF("Reach to out of range");
- put_rn();
- break;
- case ERR_OUT_OF_RANGE :
- put_r();
- PRINTF("Not in a memory area");
- put_rn();
- break;
- case ERR_NOTHING :
- default :
- ;
- }
-}
-
-// Print memory contents
-void put_dump (const unsigned char *buff, unsigned long ofs, int cnt)
-{
- int n;
-
- PRINTF("%08lX ", ofs);
- for(n = 0; n < cnt; n++) { // show hex
- PRINTF(" %02X", buff[n]);
- }
- for(; n < 16; n++) { // fullfil remained space
- PRINTF(" ");
- }
- PUTC(' ');
- for(n = 0; n < cnt; n++) { // show char
- if ((buff[n] < 0x20)||(buff[n] >= 0x7F)) {
- PUTC('.');
- } else {
- PUTC(buff[n]);
- }
- }
- put_rn();
-}
-
-// dump memory with error check
-void dump_w_err_ckeck ( char **ptr, MEMO * mem )
-{
- check_range (mem);
- for (*ptr=(char*)mem->mstr; mem->msiz >= 16; *ptr += 16, mem->msiz -= 16) {
- put_r();
- put_dump((unsigned char*)*ptr, (unsigned int)*ptr, 16);
- }
- if (mem->msiz) {
- put_dump((unsigned char*)*ptr, (unsigned int)*ptr, mem->msiz);
- }
- error_print(mem->mflg);
-}
-
-static void mem_inf (char *ptr)
-{
- put_r();
- PRINTF("Mem. Mode d <address> [<count>], s, <ret> or f, q, ?");
- put_rn();
- mem.mstr = mem_range[0][0]; // default start address = Flash
- mem.msiz =256;
- mem.mold = 0;
- mem.mtmp = 0;
- mem.mflg = 0;
- for (; mem.mflg != 0xff;) {
- PRINTF("m>");
- ptr = linebuf;
- get_line(ptr, buf_size);
- put_r();
- switch(*ptr++) {
- case 'd' : // d <address> [<count>] - Dump memory
- mem.mtmp = mem.mstr;
- if (!xatoi(&ptr, &mem.mstr)) {
- mem.mstr = mem.mtmp;
- }
- if (!xatoi(&ptr, &mem.msiz)) {
- mem.msiz = 256;
- }
- mem.mtmp = mem.msiz;
- dump_w_err_ckeck(&ptr, &mem);
- mem.mold = mem.mstr;
- mem.mstr += mem.mtmp;
- break;
- case 'f' : // next
- case 'n' :
- case 0x0d :
- mem.msiz = 256;
- mem.mtmp = mem.msiz;
- dump_w_err_ckeck(&ptr, &mem);
- mem.mold = mem.mstr;
- mem.mstr += 256;
- break;
- case 'q' : // quit
- mem.mflg = 0xff;
- break;
- case 'b' : // Back to more
- if (mem.mold == 0) {
- ;
- } else {
- mem.mold -= 256;
- }
- case 'k' : // keep previous address
- mem.mstr = mem.mold;
- mem.msiz = 256;
- mem.mtmp = mem.msiz;
- dump_w_err_ckeck(&ptr, &mem);
- mem.mstr += 256;
- break;
- case 'a' : // start RAM top
-#if defined(TARGET_NUCLEO_L152RE)
- mem.mstr = mem_range[4][0];
-#elif defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE)
- mem.mstr = mem_range[3][0];
-#elif defined(TARGET_LPC1768)
- mem.mstr = mem_range[1][0];
-#elif defined(TARGET_LPC1114)
- mem.mstr = mem_range[1][0];
-#elif defined(TARGET_K64F)
- mem.mstr = mem_range[1][0];
-#else
-#error "target cpu does NOT support"
-#endif
- mem.msiz =256;
- mem.mold = 0;
- mem.mtmp = 0;
- mem.mflg = 0;
- dump_w_err_ckeck(&ptr, &mem);
- mem.mstr += 256;
- break;
- case 'o' : // start ROM top
- mem.mstr = mem_range[0][0];
- mem.msiz =256;
- mem.mold = 0;
- mem.mtmp = 0;
- mem.mflg = 0;
- dump_w_err_ckeck(&ptr, &mem);
- mem.mstr += 256;
- break;
- case 's' :
- PRINTF("Memory Configuration");
- put_rn();
- PRINTF("%s0x%08lx to 0x%08lx ", rmsg0, mem_range[0][0], mem_range[0][1]);
- put_rn();
- PRINTF("%s0x%08lx to 0x%08lx ", rmsg1, mem_range[1][0], mem_range[1][1]);
- put_rn();
- PRINTF("%s0x%08lx to 0x%08lx ", rmsg2, mem_range[2][0], mem_range[2][1]);
- put_rn();
- PRINTF("%s0x%08lx to 0x%08lx ", rmsg3, mem_range[3][0], mem_range[3][1]);
- put_rn();
- PRINTF("%s0x%08lx to 0x%08lx ", rmsg4, mem_range[4][0], mem_range[4][1]);
- put_rn();
-#if defined(TARGET_NUCLEO_L152RE)
- PRINTF("%s0x%08lx to 0x%08lx ", rmsg5, mem_range[5][0], mem_range[5][1]);
- put_rn();
-#endif
- break;
- case '?' :
- PRINTF("d <address> [<count>] - Dump memory");
- put_rn();
- PRINTF("s - Show memory structure ");
- put_rn();
- PRINTF("o - Dump memory / start from ROM top");
- put_rn();
- PRINTF("a - Dump memory / start from RAM top");
- put_rn();
- PRINTF("k - Dump memory / keep same 256bytes");
- put_rn();
- PRINTF("b - Dump memory / before 256bytes");
- put_rn();
- PRINTF("<RET> or f, n - Dump memory / next 256bytes");
- put_rn();
- PRINTF("q - Exit memory mode");
- put_rn();
- break;
- default:
- PUTC('?');
- put_rn();
- }
- }
- PRINTF("Return to All Mode");
-}
--- a/kf.cpp Sun Dec 14 09:17:01 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-/*
- * mbed Application program for the mbed ST NUCLEO F401RE Board
- *
- * Modified by Kenji Arai / JH1PJL
- * http://www.page.sannet.ne.jp/kenjia/index.html
- * http://mbed.org/users/kenjiArai/
- * Revised: August 28th, 2014
- */
-
-// <Original> http://www.x-firm.com/?page_id=191
-
-// Main module K_bot angle angles in Quids, 10 bit ADC ---------------------------------------
-// 7 - Data fusing, Kalman filter
-
-// Installation:
-// Create "Kalman" and "Sensors" tabs
-// Cut and paste the 2 modules in their respective tab
-// Save as "Kas_bot_angle"
-
-// --- Kalman filter module ----------------------------------------------------------------------
-float Q_angle = 0.001; //0.001
-float Q_gyro = 0.003; //0.003
-float R_angle = 0.03; //0.03
-
-float x_angle = 0;
-float x_bias = 0;
-float P_00 = 0, P_01 = 0, P_10 = 0, P_11 = 0;
-float dt, y, S;
-float K_0, K_1;
-
-float kalmanCalculate(float newAngle, float newRate, int looptime) {
- dt = float(looptime)/1000;
- x_angle += dt * (newRate - x_bias);
- P_00 += - dt * (P_10 + P_01) + Q_angle * dt;
- P_01 += - dt * P_11;
- P_10 += - dt * P_11;
- P_11 += + Q_gyro * dt;
-
- y = newAngle - x_angle;
- S = P_00 + R_angle;
- K_0 = P_00 / S;
- K_1 = P_10 / S;
-
- x_angle += K_0 * y;
- x_bias += K_1 * y;
- P_00 -= K_0 * P_00;
- P_01 -= K_0 * P_01;
- P_10 -= K_1 * P_00;
- P_11 -= K_1 * P_01;
-
- return x_angle;
-}
--- a/main.cpp Sun Dec 14 09:17:01 2014 +0000
+++ b/main.cpp Sun Dec 28 11:51:59 2014 +0000
@@ -5,8 +5,8 @@
* Copyright (c) 2014 Kenji Arai / JH1PJL
* http://www.page.sannet.ne.jp/kenjia/index.html
* http://mbed.org/users/kenjiArai/
- * Created: November 29th, 2014
- * Revised: December 14th, 2014
+ * Created: December 27th, 2014
+ * Revised: December 28th, 2014
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
@@ -17,271 +17,70 @@
// Include ---------------------------------------------------------------------------------------
#include "mbed.h"
-#include "rtos.h"
-#include "L3GD20.h"
-#include "LIS3DH.h"
-#include "ST7565_SPI_LCD.h"
-#include "PID.h"
-#include "stepper.h"
+// Object ----------------------------------------------------------------------------------------
+extern Serial pc(USBTX, USBRX);
// Definition ------------------------------------------------------------------------------------
-#define USE_COM // use Communication with PC(UART)
-
-// Com
-#ifdef USE_COM
-#define BAUD(x) pcx.baud(x)
-#define GETC(x) pcx.getc(x)
-#define PUTC(x) pcx.putc(x)
-#define PRINTF(...) pcx.printf(__VA_ARGS__)
-#define READABLE(x) pcx.readable(x)
-#else
-#define BAUD(x) {;}
-#define GETC(x) {;}
-#define PUTC(x) {;}
-#define PRINTF(...) {;}
-#define READABLE(x) {;}
-#endif
+#define BAUD_RATE 9600
-#define TIMEBASE 12000
-#define FIXED_STEPS 100
+#define BAUD(x) pc.baud(x)
+#define GETC(x) pc.getc(x)
+#define PUTC(x) pc.putc(x)
+#define PRINTF(...) pc.printf(__VA_ARGS__)
+#define READABLE(x) pc.readable(x)
-#define PI 3.1415926536
-#define RAD_TO_DEG 57.29578
-#define TIME_BASE_S 0.01
-#define TIME_BASE_MS ( TIME_BASE_S * 1000)
-#define RATE 0.1
+#define BUF_SIZE (128 * 1024) // 128KB
+#define BUF_SIZE_SMALL (40 * 1024)
// Object ----------------------------------------------------------------------------------------
-// LED's
-DigitalOut LEDs[4] = {
- DigitalOut(LED1), DigitalOut(LED2), DigitalOut(LED3), DigitalOut(LED4)
-};
-// Swiches
-DigitalIn USER_SWITCH[2] = {
- #if defined(TARGET_RZ_A1H)
- DigitalIn(P6_0), DigitalIn(P6_1)
- #elif defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F401RE)\
- || defined(TARGET_NUCLEO_L152RE)
- DigitalIn(PC_13), DigitalIn(A0)
- #elif defined(TARGET_LPC1768)
- DigitalIn(A0), DigitalIn(A1)
- #elif defined(TARGET_K64F)
- DigitalIn(PTA4), DigitalIn(PTC6)
- #endif
-};
-// Rotor
-STEPPER rotor(D5, D4, D3, D2);
-// com
-#ifdef USE_COM
-Serial pcx(USBTX, USBRX); // Communication with Host
-#endif
-I2C i2c(D14,D15);
-// Gyro
-L3GX_GYRO gyro(i2c, L3GD20_V_CHIP_ADDR, L3GX_DR_95HZ, L3GX_BW_HI, L3GX_FS_250DPS);
-// Acc
-LIS3DH acc(i2c, LIS3DH_G_CHIP_ADDR, LIS3DH_DR_NR_LP_50HZ, LIS3DH_FS_8G);
-// SPI LCD
-SPI spi_lcd(D11, D12, D13); // mosi, miso, sck
-ST7565 lcd1(spi_lcd, D8, D9, D7, ST7565::AQM1248A); // spi,reset,a0,ncs, LCD(Akizuki AQM1248A)
-// Kc, Ti, Td, interval
-PID controller(1.0, 0.0, 0.0, RATE);
-// Mutex
-Mutex i2c_mutex;
// RAM -------------------------------------------------------------------------------------------
-Queue<uint32_t, 2> queue0;
-Queue<uint32_t, 2> queue1;
-float fa[3]; // Acc 0:X, 1:Y, 2:Z
-float fg[3]; // Gyro 0:X, 1:Y, 2:Z
-float accXangle; // Angle calculate using the accelerometer
-float gyroXangle; // Angle calculate using the gyro
-float kalAngleX; // Calculate the angle using a Kalman filter
-float stp;
-float angle;
-
-uint8_t pls_width[MT_SLOP_STEP] = {5, 4, 3, 2, 1, 1, 1, 1, 1, 1 };
-
-/* Mail */
-typedef struct {
- float voltage; /* AD result of measured voltage */
- float current; /* AD result of measured current */
- uint32_t counter; /* A counter value */
-} mail_t;
-
-Mail<mail_t, 16> mail_box;
-
-uint8_t show_flag;
+uint8_t data_buf0[BUF_SIZE];
+uint8_t data_buf1[BUF_SIZE];
+uint8_t data_buf2[BUF_SIZE];
+uint8_t data_buf3[BUF_SIZE_SMALL];
+//uint8_t data_buf2[BUF_SIZE] __attribute__ ((RW_DATA));
// ROM / Constant data ---------------------------------------------------------------------------
// Function prototypes ---------------------------------------------------------------------------
// Function prototypes ---------------------------------------------------------------------------
-extern int mon( void);
-extern float kalmanCalculate(float newAngle, float newRate, int looptime);
+extern int mon_mem(void);
//-------------------------------------------------------------------------------------------------
// Control Program
//-------------------------------------------------------------------------------------------------
-void send_thread (void const *args) {
- uint32_t i = 0;
- while (true) {
- i++; // fake data update
- mail_t *mail = mail_box.alloc();
- mail->voltage = (i * 0.1) * 33;
- mail->current = (i * 0.1) * 11;
- mail->counter = i;
- mail_box.put(mail);
- Thread::wait(1000);
- }
-}
-
-void blink(void const *n) {
- LEDs[(int)n] = !LEDs[(int)n];
-}
-
-// Read switch status
-int read_sw(uint8_t n){
- if (USER_SWITCH[n] == 0){ return 1;
- } else { return 0;}
-}
-
-// Monitor program
-void monitor(void const *args){
- while (true){
- mon();
- }
-}
-
-// Interrupt routine
-void queue_isr0() {
- queue0.put((uint32_t*)1);
-}
-
-void queue_isr1() {
- queue1.put((uint32_t*)1);
-}
-
-// Update sensor data
-void update_angle(void const *args){
- while (true) {
- osEvent evt = queue0.get();
- // ---->lock
- i2c_mutex.lock();
- // read acceleration data from sensor
- acc.read_data(fa);
- // read gyroscope data from sensor
- gyro.read_data(fg);
- // <----unlock
- i2c_mutex.unlock();
- // Calculate angle (degree)
- accXangle = (atan2(-fa[1],fa[2])+PI)*RAD_TO_DEG;
- // calculate filtered Angle
- kalAngleX = kalmanCalculate(accXangle, fg[0], TIME_BASE_MS) - 180;
- }
+void print_data_address(void)
+{
+ PRINTF("data_buf0 addr top: 0x%8x\r\n", &data_buf0);
+ PRINTF("data_buf1 addr top: 0x%8x\r\n", &data_buf1);
+ PRINTF("data_buf2 addr top: 0x%8x\r\n", &data_buf2);
+ PRINTF("data_buf3 addr top: 0x%8x\r\n", &data_buf3);
}
-// Read angle and control an inertia rotor
-void rotor_control(void const *args){
- // Input angle range
- controller.setInputLimits(-90.0, 90.0);
- // Output motor speed
- controller.setOutputLimits(-50, 50);
- // a bias.
- controller.setBias(0.0);
- controller.setMode(AUTO_MODE);
- // Target
- controller.setSetPoint(0.0);
+int main()
+{
+ uint32_t n;
+
+ PRINTF("\r\nSet data into data_buf0[]\r\n");
+ for (n = 0; n < BUF_SIZE; n++) {
+ data_buf0[n] = n & 0xff;
+ }
+ PRINTF("Set data into data_buf1[]\r\n");
+ for (n = 0; n < BUF_SIZE; n++) {
+ data_buf1[BUF_SIZE - n] = n & 0xff;
+ }
+ PRINTF("Set data into data_buf2[]\r\n");
+ for (n = 0; n < BUF_SIZE; n++) {
+ data_buf2[n] = n & 0xff;
+ }
+ PRINTF("Set data into data_buf3[]\r\n");
+ for (n = 0; n < BUF_SIZE_SMALL; n++) {
+ data_buf3[n] = n & 0xff;
+ }
+ print_data_address();
while (true) {
- osEvent evt = queue1.get();
- // Update the process variable.
- if ((kalAngleX < 0.8) && (kalAngleX > -0.8)){
- angle = 0;
- } else {
- angle = kalAngleX;
- }
- controller.setProcessValue(angle);
- // Set the new output.
- stp = controller.compute() * 5;
- rotor.move((int32_t)stp);
- }
-}
-
-// Update sensor data
-void display(void const *args){
- // SPI LCD
- spi_lcd.frequency(100000);
- lcd1.cls();
- lcd1.set_contrast(0x2a);
- lcd1.printf("test\r\n" );
- lcd1.printf("Kenji Arai / JH1PJL\r\n" );
- lcd1.printf("ABCDEFG 1234567890\r\n" );
- lcd1.rect(5,30,120,62,1);
- lcd1.circle(5,35,5,1);
- lcd1.fillcircle(60,55,5,1);
- lcd1.line(0,30,127,63,1);
- while (true) {
- Thread::wait(500);
+ mon_mem();
}
}
-
-// Thread definition
-osThreadDef(update_angle, osPriorityRealtime, 4096);
-osThreadDef(rotor_control, osPriorityAboveNormal, 4096);
-osThreadDef(monitor, osPriorityNormal, 4096);
-osThreadDef(display, osPriorityNormal, 4096);
-
-int main(void) {
- PRINTF("step1\r\n");
-
- RtosTimer led_1_timer(blink, osTimerPeriodic, (void *)0);
- RtosTimer led_2_timer(blink, osTimerPeriodic, (void *)1);
- RtosTimer led_3_timer(blink, osTimerPeriodic, (void *)2);
- RtosTimer led_4_timer(blink, osTimerPeriodic, (void *)3);
-
- PRINTF("step2\r\n");
- led_1_timer.start(2000);
- led_2_timer.start(1000);
- led_3_timer.start(500);
- led_4_timer.start(250);
-
- PRINTF("step3\r\n");
- Thread thread(send_thread);
-
- PRINTF("step4\r\n");
- // Initialize data
- stp = 0;
- angle = 0.0;
-
- // IRQ
- Ticker ticker0;
- Ticker ticker1;
- ticker0.attach(queue_isr0, TIME_BASE_S);
- ticker1.attach(queue_isr1, RATE);
- rotor.set_max_speed(TIMEBASE);
-
- PRINTF("step5\r\n");
- // Starts 1st thread
- osThreadCreate(osThread(update_angle), NULL);
- // Starts 2nd thread
- osThreadCreate(osThread(rotor_control), NULL);
- // Starts 3rd thread
- osThreadCreate(osThread(monitor), NULL);
- // Starts 4th thread
- osThreadCreate(osThread(display), NULL);
-
- PRINTF("step6\r\n");
- while (true) {
- osEvent evt = mail_box.get();
- if (evt.status == osEventMail) {
- mail_t *mail = (mail_t*)evt.value.p;
- if (show_flag){
- PRINTF("This is dummy!, ");
- PRINTF("Volt: %.2f V, " , mail->voltage);
- PRINTF("Current: %.2f A, " , mail->current);
- PRINTF("# of cycles: %u\r\n", mail->counter);
- }
- mail_box.free(mail);
- }
- }
-}
--- a/mbed-rtos.lib Sun Dec 14 09:17:01 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/mbed-rtos/#f1ef95efa5ad
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-src-v442-pre.lib Sun Dec 28 11:51:59 2014 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/GR-PEACH_producer_meeting/code/mbed-src-v442-pre/#b6950b258d81
--- a/mbed-src.lib Sun Dec 14 09:17:01 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/mbed-src/#cef2a8a56f9e
--- a/mon.cpp Sun Dec 14 09:17:01 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,643 +0,0 @@
-/*
- * mbed Application program
- *
- * Copyright (c) 2010-2014 Kenji Arai / JH1PJL
- * http://www.page.sannet.ne.jp/kenjia/index.html
- * http://mbed.org/users/kenjiArai/
- * Created: May 15th, 2010
- * Spareted: June 25th, 2014 mon() & mon_hw()
- * Ported: July 12th, 2014 from L152RE
- * Revised: December 14th, 2014
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
- * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
- * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#if 0
-// Include ---------------------------------------------------------------------------------------
-#include "mbed.h"
-#include "rtos.h"
-
-// Object ----------------------------------------------------------------------------------------
-Serial pc(USBTX, USBRX);
-
-// Definition ------------------------------------------------------------------------------------
-#define BAUD(x) pc.baud(x)
-#define GETC(x) pc.getc(x)
-#define PUTC(x) pc.putc(x)
-#define PRINTF(...) pc.printf(__VA_ARGS__)
-#define READABLE(x) pc.readable(x)
-
-// RAM -------------------------------------------------------------------------------------------
-char linebuf[64];
-int buf_size = sizeof(linebuf);
-
-extern float fa[3]; // Acc 0:X, 1:Y, 2:Z
-extern float fg[3]; // Gyro 0:X, 1:Y, 2:Z
-extern float stp;
-extern float angle;
-extern uint8_t show_flag;
-
-// ROM / Constant data ---------------------------------------------------------------------------
-static char *const mon_msg = "Monitor for mbed system, created on "__DATE__"";
-
-// Function prototypes ---------------------------------------------------------------------------
-extern void debug_interface(void);
-extern int read_sw(uint8_t n);
-
-//-------------------------------------------------------------------------------------------------
-// Control Program
-//-------------------------------------------------------------------------------------------------
-// Put \r\n
-void put_rn ( void ){
- Thread::yield(); // change thread
- PUTC('\r');
- Thread::yield(); // change thread
- PUTC('\n');
-}
-
-// Put \r
-void put_r ( void ){
- Thread::yield(); // change thread
- PUTC('\r');
-}
-
-// Put ", "
-void put_lin ( void ){
- Thread::yield(); // change thread
- PRINTF(", ");
-}
-
-// Put space n
-void put_spc( uint8_t n){
- for(;n > 0; n--){
- PUTC(' ');
- Thread::yield(); // change thread
- }
-}
-
-// Change string -> integer
-//int xatoi (char **str, unsigned long *res){
-int xatoi (char **str, int32_t *res){
-unsigned long val;
-unsigned char c, radix, s = 0;
-
- while ((c = **str) == ' ') (*str)++;
- if (c == '-') {
- s = 1;
- c = *(++(*str));
- }
- if (c == '0') {
- c = *(++(*str));
- if (c <= ' ') { *res = 0; return 1; }
- if (c == 'x') {
- radix = 16;
- c = *(++(*str));
- } else {
- if (c == 'b') {
- radix = 2;
- c = *(++(*str));
- } else {
- if ((c >= '0')&&(c <= '9')){ radix = 8;
- } else { return 0;}
- }
- }
- } else {
- if ((c < '1')||(c > '9')){ return 0;}
- radix = 10;
- }
- val = 0;
- while (c > ' ') {
- if (c >= 'a') c -= 0x20;
- c -= '0';
- if (c >= 17) {
- c -= 7;
- if (c <= 9) return 0;
- }
- if (c >= radix) return 0;
- val = val * radix + c;
- c = *(++(*str));
- }
- if (s) val = -val;
- *res = val;
- return 1;
-}
-
-//-------------------------------------------------------------------------------------------------
-// Monitor
-//-------------------------------------------------------------------------------------------------
-// Help Massage
-void msg_hlp (void){
- PRINTF(mon_msg); put_rn();
- PRINTF("d - Show control data"); put_rn();
- PRINTF("m - Show mail data"); put_rn();
- PRINTF("s - Show USER Button"); put_rn();
- PRINTF("t - Check and set RTC"); put_rn();
- PRINTF("x - Goto HW monitor"); put_rn();
- PRINTF("q - Return to main"); put_rn();
-}
-
-// Get key input data
-void get_line (char *buff, int len){
-char c;
-int idx = 0;
-
- for (;;) {
- c = GETC();
- // Added by Kenji Arai / JH1PJL May 9th, 2010
- if (c == '\r') {
- buff[idx++] = c;
- break;
- }
- if ((c == '\b') && idx) {
- idx--;
- PUTC(c);
- PUTC(' ');
- PUTC(c);
- }
- if (((uint8_t)c >= ' ') && (idx < len - 1)) {
- buff[idx++] = c;
- PUTC(c);
- }
- Thread::yield(); // change thread
- Thread::wait(10); // Wait 10mS
- }
- buff[idx] = 0;
- PUTC('\n');
-}
-
-// RTC related subroutines
-void chk_and_set_time(char *ptr){
-//unsigned long p1;
-int32_t p1;
-struct tm t;
-time_t seconds;
-char buf[40];
-
- if (xatoi(&ptr, &p1)){
- t.tm_year = (uint8_t)p1 + 100;
- PRINTF("Year:%d ",p1);
- xatoi( &ptr, &p1 );
- t.tm_mon = (uint8_t)p1 - 1;
- PRINTF("Month:%d ",p1);
- xatoi( &ptr, &p1 );
- t.tm_mday = (uint8_t)p1;
- PRINTF("Day:%d ",p1);
- xatoi( &ptr, &p1 );
- t.tm_hour = (uint8_t)p1;
- PRINTF("Hour:%d ",p1);
- xatoi( &ptr, &p1 );
- t.tm_min = (uint8_t)p1;
- PRINTF("Min:%d ",p1);
- xatoi( &ptr, &p1 );
- t.tm_sec = (uint8_t)p1;
- PRINTF("Sec: %d \r\n",p1);
- seconds = mktime(&t);
- set_time(seconds);
- }
- seconds = time(NULL);
- strftime(buf, 40, "%B %d,'%y, %H:%M:%S", localtime(&seconds));
- PRINTF("Date: %s\r\n", buf);
-}
-
-// ---------- Program starts here! ---------------------------------------------------------------
-int mon(void) {
-char *ptr;
-
- BAUD(9600);
- put_rn();
- put_rn();
- PRINTF("%s [Help:'?' key]", mon_msg);
- put_rn();
- for (;;) {
- put_r();
- PUTC('>');
- ptr = linebuf;
- get_line(ptr, sizeof(linebuf));
- switch (*ptr++) {
- //---------------------------------------------------------------------------------------------
- // Check control data
- //---------------------------------------------------------------------------------------------
- case 'd' :
- while(true) {
- put_r();
- PRINTF("Deg:%+6.1f S:%+6.1f ", angle, stp);
- Thread::yield(); // change thread
- PRINTF("G:%+6.1f,%+6.1f,%+6.1f ", fg[0], fg[1], fg[2]);
- Thread::yield(); // change thread
- PRINTF("A:%+6.1f,%+6.1f,%+6.1f ", fa[0], fa[1], fa[2]);
- put_rn();
- if ( READABLE() ) {
- break;
- }
- Thread::wait(200); // Wait 200mS
- }
- break;
- //---------------------------------------------------------------------------------------------
- // Show Mail data
- //---------------------------------------------------------------------------------------------
- case 'm' :
- put_rn();
- while(true) {
- show_flag = 1;
- if ( READABLE() ) {
- break;
- }
- Thread::wait(100); // Wait 100mS
- }
- show_flag = 0;
- break;
- //---------------------------------------------------------------------------------------------
- // Show switch status
- //---------------------------------------------------------------------------------------------
- case 's' :
- put_r();
- PRINTF("Show USER_Button status");
- put_rn();
- PRINTF("every 500mS - hit any key for stop");
- put_rn();
- while (true){
- PRINTF("SW0 = ");
- if (read_sw(0) == 1) { PRINTF("ON ");
- } else { PRINTF("OFF");
- }
- PRINTF(", SW1 = ");
- if (read_sw(1) == 1) { PRINTF("ON");
- } else { PRINTF("OFF");
- }
- put_rn();
- if (READABLE()){ GETC(); break;}
- wait(0.5);
- }
- break;
- //---------------------------------------------------------------------------------------------
- // check and set RTC
- //---------------------------------------------------------------------------------------------
- case 't' :
- put_r();
- chk_and_set_time(ptr);
- break;
- //---------------------------------------------------------------------------------------------
- // help
- //---------------------------------------------------------------------------------------------
- case '?' :
- put_r();
- msg_hlp();
- break;
- //---------------------------------------------------------------------------------------------
- // Go to special command
- //---------------------------------------------------------------------------------------------
- case 'x' :
-#if defined(TARGET_RZ_A1H)
- PRINTF("Not implement yet\r\n");
-#elif defined(TARGET_LPC1114)
- PRINTF("Not implement yet\r\n");
-#elif defined(TARGET_NUCLEO_F411RE) || defined(TARGET_STM32F401RE)
- debug_interface();
-#elif defined(TARGET_LPC1768)
- debug_interface();
-#elif defined(TARGET_K64F)
- PRINTF("Not implement yet\r\n");
-#endif
- PRINTF("->Came back monitor\r\n");
- break;
- //---------------------------------------------------------------------------------------------
- // Go back to main()
- //---------------------------------------------------------------------------------------------
- case 'q' : // Quit
- PRINTF("\rReturn to main\r\n");
- PRINTF("cannot control anymore from here\r\n");
- return 0;
- }
- }
-}
-#endif
-
-#if 1
-
-// Include ---------------------------------------------------------------------------------------
-#include "mbed.h"
-#include "rtos.h"
-
-// Object ----------------------------------------------------------------------------------------
-Serial pc(USBTX, USBRX);
-
-// Definition ------------------------------------------------------------------------------------
-#define BAUD(x) pc.baud(x)
-#define GETC(x) pc.getc(x)
-#define PUTC(x) pc.putc(x)
-#define PRINTF(...) pc.printf(__VA_ARGS__)
-#define READABLE(x) pc.readable(x)
-
-// RAM -------------------------------------------------------------------------------------------
-static char linebuf[64];
-static int buf_size = sizeof(linebuf);
-
-extern float fa[3]; // Acc 0:X, 1:Y, 2:Z
-extern float fg[3]; // Gyro 0:X, 1:Y, 2:Z
-extern float stp;
-extern float angle;
-extern uint8_t show_flag;
-
-// ROM / Constant data ---------------------------------------------------------------------------
-static char *const mon_msg = "Monitor for mbed system, created on "__DATE__"";
-
-// Function prototypes ---------------------------------------------------------------------------
-extern void debug_interface(void);
-extern int read_sw(uint8_t n);
-
-//-------------------------------------------------------------------------------------------------
-// Control Program
-//-------------------------------------------------------------------------------------------------
-#if 0
-// Put \r\n
-extern void put_rn ( void );
-// Put \r
-extern void put_r ( void );
-// Put ", "
-extern void put_lin ( void );
-// Put space n
-extern void put_spc( uint8_t n);
-// Change string -> integer
-//int xatoi (char **str, unsigned long *res){
-extern int xatoi (char **str, int32_t *res);
-
-#else
-// Put \r\n
-static void put_rn ( void ){
- Thread::yield(); // change thread
- PUTC('\r');
- Thread::yield(); // change thread
- PUTC('\n');
-}
-
-// Put \r
-static void put_r ( void ){
- Thread::yield(); // change thread
- PUTC('\r');
-}
-
-// Put ", "
-static void put_lin ( void ){
- Thread::yield(); // change thread
- PRINTF(", ");
-}
-
-// Put space n
-static void put_spc( uint8_t n){
- for(;n > 0; n--){
- PUTC(' ');
- Thread::yield(); // change thread
- }
-}
-
-// Change string -> integer
-//int xatoi (char **str, unsigned long *res){
-static int xatoi (char **str, int32_t *res){
-unsigned long val;
-unsigned char c, radix, s = 0;
-
- while ((c = **str) == ' ') (*str)++;
- if (c == '-') {
- s = 1;
- c = *(++(*str));
- }
- if (c == '0') {
- c = *(++(*str));
- if (c <= ' ') { *res = 0; return 1; }
- if (c == 'x') {
- radix = 16;
- c = *(++(*str));
- } else {
- if (c == 'b') {
- radix = 2;
- c = *(++(*str));
- } else {
- if ((c >= '0')&&(c <= '9')){ radix = 8;
- } else { return 0;}
- }
- }
- } else {
- if ((c < '1')||(c > '9')){ return 0;}
- radix = 10;
- }
- val = 0;
- while (c > ' ') {
- if (c >= 'a') c -= 0x20;
- c -= '0';
- if (c >= 17) {
- c -= 7;
- if (c <= 9) return 0;
- }
- if (c >= radix) return 0;
- val = val * radix + c;
- c = *(++(*str));
- }
- if (s) val = -val;
- *res = val;
- return 1;
-}
-#endif
-
-//-------------------------------------------------------------------------------------------------
-// Monitor
-//-------------------------------------------------------------------------------------------------
-// Help Massage
-static void msg_hlp (void){
- PRINTF(mon_msg); put_rn();
- PRINTF("d - Show control data"); put_rn();
- PRINTF("m - Show mail data"); put_rn();
- PRINTF("s - Show USER Button"); put_rn();
- PRINTF("t - Check and set RTC"); put_rn();
- PRINTF("x - Goto HW monitor"); put_rn();
- PRINTF("q - Return to main"); put_rn();
-}
-
-#if 0
-extern void get_line (char *buff, int len);
-
-// RTC related subroutines
-extern void chk_and_set_time(char *ptr);
-
-#else
-// Get key input data
-static void get_line (char *buff, int len){
-char c;
-int idx = 0;
-
- for (;;) {
- c = GETC();
- // Added by Kenji Arai / JH1PJL May 9th, 2010
- if (c == '\r') {
- buff[idx++] = c;
- break;
- }
- if ((c == '\b') && idx) {
- idx--;
- PUTC(c);
- PUTC(' ');
- PUTC(c);
- }
- if (((uint8_t)c >= ' ') && (idx < len - 1)) {
- buff[idx++] = c;
- PUTC(c);
- }
- Thread::yield(); // change thread
- Thread::wait(10); // Wait 10mS
- }
- buff[idx] = 0;
- PUTC('\n');
-}
-
-// RTC related subroutines
-static void chk_and_set_time(char *ptr){
-//unsigned long p1;
-int32_t p1;
-struct tm t;
-time_t seconds;
-char buf[40];
-
- if (xatoi(&ptr, &p1)){
- t.tm_year = (uint8_t)p1 + 100;
- PRINTF("Year:%d ",p1);
- xatoi( &ptr, &p1 );
- t.tm_mon = (uint8_t)p1 - 1;
- PRINTF("Month:%d ",p1);
- xatoi( &ptr, &p1 );
- t.tm_mday = (uint8_t)p1;
- PRINTF("Day:%d ",p1);
- xatoi( &ptr, &p1 );
- t.tm_hour = (uint8_t)p1;
- PRINTF("Hour:%d ",p1);
- xatoi( &ptr, &p1 );
- t.tm_min = (uint8_t)p1;
- PRINTF("Min:%d ",p1);
- xatoi( &ptr, &p1 );
- t.tm_sec = (uint8_t)p1;
- PRINTF("Sec: %d \r\n",p1);
- seconds = mktime(&t);
- set_time(seconds);
- }
- seconds = time(NULL);
- strftime(buf, 40, "%B %d,'%y, %H:%M:%S", localtime(&seconds));
- PRINTF("Date: %s\r\n", buf);
-}
-#endif
-
-// ---------- Program starts here! ---------------------------------------------------------------
-int mon(void) {
-char *ptr;
-
- BAUD(9600);
- put_rn();
- put_rn();
- PRINTF("%s [Help:'?' key]", mon_msg);
- put_rn();
- for (;;) {
- put_r();
- PUTC('>');
- ptr = linebuf;
- get_line(ptr, sizeof(linebuf));
- switch (*ptr++) {
- //---------------------------------------------------------------------------------------------
- // Check control data
- //---------------------------------------------------------------------------------------------
- case 'd' :
- while(true) {
- put_r();
- PRINTF("Deg:%+6.1f S:%+6.1f ", angle, stp);
- Thread::yield(); // change thread
- PRINTF("G:%+6.1f,%+6.1f,%+6.1f ", fg[0], fg[1], fg[2]);
- Thread::yield(); // change thread
- PRINTF("A:%+6.1f,%+6.1f,%+6.1f ", fa[0], fa[1], fa[2]);
- put_rn();
- if ( READABLE() ) {
- break;
- }
- Thread::wait(200); // Wait 200mS
- }
- break;
- //---------------------------------------------------------------------------------------------
- // Show Mail data
- //---------------------------------------------------------------------------------------------
- case 'm' :
- put_rn();
- while(true) {
- show_flag = 1;
- if ( READABLE() ) {
- break;
- }
- Thread::wait(100); // Wait 100mS
- }
- show_flag = 0;
- break;
- //---------------------------------------------------------------------------------------------
- // Show switch status
- //---------------------------------------------------------------------------------------------
- case 's' :
- put_r();
- PRINTF("Show USER_Button status");
- put_rn();
- PRINTF("every 500mS - hit any key for stop");
- put_rn();
- while (true){
- PRINTF("SW0 = ");
- if (read_sw(0) == 1) { PRINTF("ON ");
- } else { PRINTF("OFF");
- }
- PRINTF(", SW1 = ");
- if (read_sw(1) == 1) { PRINTF("ON");
- } else { PRINTF("OFF");
- }
- put_rn();
- if (READABLE()){ GETC(); break;}
- wait(0.5);
- }
- break;
- //---------------------------------------------------------------------------------------------
- // check and set RTC
- //---------------------------------------------------------------------------------------------
- case 't' :
- put_r();
- chk_and_set_time(ptr);
- break;
- //---------------------------------------------------------------------------------------------
- // help
- //---------------------------------------------------------------------------------------------
- case '?' :
- put_r();
- msg_hlp();
- break;
- //---------------------------------------------------------------------------------------------
- // Go to special command
- //---------------------------------------------------------------------------------------------
- case 'x' :
-#if defined(TARGET_RZ_A1H)
- PRINTF("Not implement yet\r\n");
-#elif defined(TARGET_LPC1114)
- PRINTF("Not implement yet\r\n");
-#elif defined(TARGET_NUCLEO_F411RE) || defined(TARGET_STM32F401RE)
- PRINTF("Not implement yet\r\n");
-#elif defined(TARGET_LPC1768)
- PRINTF("Not implement yet\r\n");
-#elif defined(TARGET_K64F)
- PRINTF("Not implement yet\r\n");
-#endif
- PRINTF("->Came back monitor\r\n");
- break;
- //---------------------------------------------------------------------------------------------
- // Go back to main()
- //---------------------------------------------------------------------------------------------
- case 'q' : // Quit
- PRINTF("\rReturn to main\r\n");
- PRINTF("cannot control anymore from here\r\n");
- return 0;
- }
- }
-}
-
-#endif
-
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mon_RZ_A1H_.cpp Sun Dec 28 11:51:59 2014 +0000
@@ -0,0 +1,834 @@
+/*
+ * mbed Application program for the ST NUCLEO Board
+ * Monitor program Ver.3 for only for Renesas GR-PEACH RZ/A1H
+ *
+ * Copyright (c) 2010-2014 Kenji Arai / JH1PJL
+ * http://www.page.sannet.ne.jp/kenjia/index.html
+ * http://mbed.org/users/kenjiArai/
+ * Started: May 9th, 2010
+ * Created: May 15th, 2010
+ * release as "monitor_01" http://mbed.org/users/kenjiArai/code/monitor_01/
+ * Spareted: June 25th, 2014 mon() & mon_hw()
+ * restart: July 12th, 2014
+ * Revised: December 28th, 2014
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
+ * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#if defined(TARGET_RZ_A1H)
+
+// Include ---------------------------------------------------------------------------------------
+#include "mbed.h"
+
+// Object ----------------------------------------------------------------------------------------
+extern Serial pch(USBTX, USBRX);
+
+// Definition ------------------------------------------------------------------------------------
+#define BAUD_RATE 9600
+
+#define BAUD(x) pch.baud(x)
+#define GETC(x) pch.getc(x)
+#define PUTC(x) pch.putc(x)
+#define PRINTF(...) pch.printf(__VA_ARGS__)
+#define READABLE(x) pch.readable(x)
+
+// Range check status
+#define ERR_NOTHING 0
+#define ERR_MODIFY_SIZ 1
+#define ERR_OUT_OF_RANGE 2
+
+// System CLOCK
+#define EXTERNAL_XTAL (13.333f)
+#define USB_XTAL (48.000f)
+#define VIDEO_XTAL (27.000f)
+
+// RAM -------------------------------------------------------------------------------------------
+char linebuf[128];
+int buf_size = sizeof(linebuf);
+
+typedef struct {
+ int32_t mstr;
+ int32_t msiz;
+ int32_t mtmp;
+ int32_t mold;
+ uint8_t mflg;
+ uint8_t mbhw;
+ uint8_t mmode;
+} MEMO;
+static MEMO mem;
+
+uint8_t quitflag;
+
+// ROM / Constant data ---------------------------------------------------------------------------
+char *const mon_msg =
+ "Monitor only for mbed Renesas GR-PEACH RZ/A1H, created on UTC:"__DATE__"("__TIME__")";
+
+const uint32_t mem_range0[10][2] = { // Memory access range
+ { 0x20000000, 0x200fffff }, // RAM page 0u
+ { 0x20100000, 0x201fffff }, // RAM page 1u
+ { 0x20200000, 0x202fffff }, // RAM page 2u
+ { 0x20300000, 0x203fffff }, // RAM page 3u
+ { 0x20400000, 0x204fffff }, // RAM page 4u
+ { 0x20500000, 0x205fffff }, // RAM page 0l
+ { 0x20600000, 0x206fffff }, // RAM page 1l
+ { 0x20700000, 0x207fffff }, // RAM page 2l
+ { 0x20800000, 0x208fffff }, // RAM page 3l
+ { 0x20900000, 0x209fffff }, // RAM page 4l
+};
+
+const uint32_t mem_range1[5][2] = { // Memory access range
+ { 0x60000000, 0x601fffff }, // RAM page 0
+ { 0x60200000, 0x603fffff }, // RAM page 1
+ { 0x60400000, 0x605fffff }, // RAM page 2
+ { 0x60600000, 0x607fffff }, // RAM page 3
+ { 0x60800000, 0x609fffff }, // RAM page 4
+};
+
+char *const hmsg0 = "Enter Memory Mode d <address> [<count>], s, <ret> or n, q, ?";
+
+char *const rmsg_0 = "RAM page0u:";
+char *const rmsg_1 = "RAM page0l:";
+char *const rmsg_2 = "RAM page1u:";
+char *const rmsg_3 = "RAM page1l:";
+char *const rmsg_4 = "RAM page2u:";
+char *const rmsg_5 = "RAM page2l:";
+char *const rmsg_6 = "RAM page3u:";
+char *const rmsg_7 = "RAM page3l:";
+char *const rmsg_8 = "RAM page4u:";
+char *const rmsg_9 = "RAM page4l:";
+
+char *const rmsg0 = "RAM(Mirror) page0:";
+char *const rmsg1 = "RAM(Mirror) page1:";
+char *const rmsg2 = "RAM(Mirror) page2:";
+char *const rmsg3 = "RAM(Mirror) page3:";
+char *const rmsg4 = "RAM(Mirror) page4:";
+
+char *const fmsg0 = "Unknown setting";
+
+char *const msg0 = "m - Entry Memory Mode";
+char *const msg1 = "m>? -> Aditinal functions can see by ?";
+char *const msg2 = "r - Entry Register Mode";
+char *const msg3 = "r>? -> Aditinal functions can see by ?";
+char *const msg4 = "s - System Clock -> sf, System / CPU information -> sc";
+char *const msg5 = "q - Quit (back to called routine)";
+char *const msg6 = "p - Entry Port Mode";
+char *const msg7 = "p>? -> Aditinal functions can see by ?";
+
+char *const mrmsg0 = "Enter Register Mode u,i,s,t,a,d,l,w,c & ? for help";
+char *const mrmsg8 = "Return to All Mode";
+
+// Function prototypes ---------------------------------------------------------------------------
+extern void put_rn ( void );
+extern void put_r ( void );
+extern void put_lin ( void );
+extern void put_spc( uint8_t n);
+extern void get_line (char *buff, int len);
+extern int xatoi (char **str, int32_t *res);
+
+extern void print_data_address(void);
+
+//-------------------------------------------------------------------------------------------------
+// Control Program
+//-------------------------------------------------------------------------------------------------
+// No function
+static void not_yet_impliment( void )
+{
+ PRINTF("Not implimented yet");
+ put_rn();
+}
+
+void not_select( void )
+{
+ PRINTF("Not select the function");
+ put_rn();
+}
+
+// Put \r\n
+void put_rn ( void )
+{
+ PUTC('\r');
+ PUTC('\n');
+}
+
+// Put \r
+void put_r ( void )
+{
+ PUTC('\r');
+}
+
+// Put ", "
+void put_lin ( void )
+{
+ PRINTF(", ");
+}
+
+// Put space n
+void put_spc( uint8_t n)
+{
+ for(; n > 0; n--) {
+ PUTC(' ');
+ }
+}
+
+// Change string -> integer
+int xatoi (char **str, int32_t *res)
+{
+ unsigned long val;
+ unsigned char c, radix, s = 0;
+
+ while ((c = **str) == ' ') (*str)++;
+ if (c == '-') {
+ s = 1;
+ c = *(++(*str));
+ }
+ if (c == '0') {
+ c = *(++(*str));
+ if (c <= ' ') {
+ *res = 0;
+ return 1;
+ }
+ if (c == 'x') {
+ radix = 16;
+ c = *(++(*str));
+ } else {
+ if (c == 'b') {
+ radix = 2;
+ c = *(++(*str));
+ } else {
+ if ((c >= '0')&&(c <= '9')) {
+ radix = 8;
+ } else {
+ return 0;
+ }
+ }
+ }
+ } else {
+ if ((c < '1')||(c > '9')) {
+ return 0;
+ }
+ radix = 10;
+ }
+ val = 0;
+ while (c > ' ') {
+ if (c >= 'a') c -= 0x20;
+ c -= '0';
+ if (c >= 17) {
+ c -= 7;
+ if (c <= 9) return 0;
+ }
+ if (c >= radix) return 0;
+ val = val * radix + c;
+ c = *(++(*str));
+ }
+ if (s) val = -val;
+ *res = val;
+ return 1;
+}
+
+// Get key input data
+void get_line (char *buff, int len)
+{
+ char c;
+ int idx = 0;
+
+ for (;;) {
+ c = GETC();
+ if (c == '\r') {
+ buff[idx++] = c;
+ break;
+ }
+ if ((c == '\b') && idx) {
+ idx--;
+ PUTC(c);
+ PUTC(' ');
+ PUTC(c);
+ }
+ if (((uint8_t)c >= ' ') && (idx < len - 1)) {
+ buff[idx++] = c;
+ PUTC(c);
+ }
+ }
+ buff[idx] = 0;
+ PUTC('\n');
+}
+
+
+// Range check for Memory dump
+void check_range( MEMO * mem )
+{
+ uint8_t i;
+ uint32_t m;
+
+ mem->mflg = ERR_NOTHING;
+ if (mem->mmode) {
+ for (i = 0 ; i < 5; i++) {
+ if ( mem->mstr >= mem_range1[i][0]) {
+ if ( mem->mstr < mem_range1[i][1] ) {
+ m = mem->mstr + mem->msiz;
+ if ( m < mem_range1[i][1]) {
+ return; // no modification
+ } else {
+ m = mem_range1[i][1];
+ mem->msiz = m - mem->mstr + 1;
+ mem->mflg = ERR_MODIFY_SIZ;
+ return; // modified size
+ }
+ }
+ }
+ }
+ } else {
+ for (i = 0; i < 10; i++) {
+ if ( mem->mstr >= mem_range0[i][0]) {
+ if ( mem->mstr < mem_range0[i][1] ) {
+ m = mem->mstr + mem->msiz;
+ if ( m < mem_range0[i][1]) {
+ return; // no modification
+ } else {
+ m = mem_range0[i][1];
+ mem->msiz = m - mem->mstr + 1;
+ mem->mflg = ERR_MODIFY_SIZ;
+ return; // modified size
+ }
+ }
+ }
+ }
+ }
+ mem->mflg = ERR_OUT_OF_RANGE;
+ mem->mstr = 0;
+ mem->msiz = 0;
+ return ;
+}
+
+// Memory dump error massage
+void error_print ( unsigned char flg )
+{
+ switch (flg) {
+ case ERR_MODIFY_SIZ :
+ put_r();
+ PRINTF("Reach to out of range");
+ put_rn();
+ break;
+ case ERR_OUT_OF_RANGE :
+ put_r();
+ PRINTF("Not in a memory area");
+ put_rn();
+ break;
+ case ERR_NOTHING :
+ default :
+ ;
+ }
+}
+
+// Print memory contents
+void put_dump (const unsigned char *buff, unsigned long ofs, int cnt)
+{
+ int n;
+
+ PRINTF("%08lX ", ofs);
+ for(n = 0; n < cnt; n++) { // show hex
+ PRINTF(" %02X", buff[n]);
+ }
+ for(; n < 16; n++) { // fullfil remained space
+ PRINTF(" ");
+ }
+ PUTC(' ');
+ for(n = 0; n < cnt; n++) { // show char
+ if ((buff[n] < 0x20)||(buff[n] >= 0x7F)) {
+ PUTC('.');
+ } else {
+ PUTC(buff[n]);
+ }
+ }
+ put_rn();
+}
+
+// dump memory with error check
+uint8_t dump_w_err_ckeck ( char **ptr, MEMO * mem )
+{
+ check_range (mem);
+ for (*ptr=(char*)mem->mstr; mem->msiz >= 16; *ptr += 16, mem->msiz -= 16) {
+ put_r();
+ put_dump((unsigned char*)*ptr, (unsigned int)*ptr, 16);
+ if (READABLE()) {
+ mem->mstr = (int32_t)*ptr;
+ PRINTF("Stop");
+ uint8_t c = GETC();
+ put_rn();
+ return 0;
+ }
+ }
+ if (mem->msiz) {
+ put_dump((unsigned char*)*ptr, (unsigned int)*ptr, mem->msiz);
+ }
+ error_print(mem->mflg);
+ return 1;
+}
+
+void set_page(char *ptr, uint8_t n)
+{
+ if (mem.mmode) {
+ mem.mstr = mem_range1[n][0];
+ } else {
+ mem.mstr = mem_range0[n][0]; ;
+ }
+ mem.msiz =512;
+ mem.mold = mem.mstr;
+ mem.mtmp = 0;
+ mem.mflg = 0;
+ if (dump_w_err_ckeck(&ptr, &mem)) {
+ mem.mstr += 512;
+ }
+}
+
+static void mem_inf (char *ptr)
+{
+ PRINTF(hmsg0);
+ put_rn();
+ mem.mstr = mem_range0[0][0]; // default start address = Flash
+ mem.msiz =512;
+ mem.mold = 0;
+ mem.mtmp = 0;
+ mem.mflg = 0;
+ mem.mmode = 0; // base address mode
+ for (; mem.mflg != 0xff;) {
+ PRINTF("m>");
+ ptr = linebuf;
+ get_line(ptr, buf_size);
+ put_r();
+ switch(*ptr++) {
+ case 'c' :
+ mem.mstr = mem.mold;
+ mem.msiz = 0xfffff;
+ mem.mtmp = mem.msiz;
+ dump_w_err_ckeck(&ptr, &mem);
+ mem.mold = mem.mstr;
+ break;
+ case 'd' : // d <address> [<count>] - Dump memory
+ mem.mtmp = mem.mstr;
+ if (!xatoi(&ptr, &mem.mstr)) {
+ mem.mstr = mem.mtmp;
+ }
+ if (!xatoi(&ptr, &mem.msiz)) {
+ mem.msiz = 512;
+ }
+ mem.mtmp = mem.msiz;
+ if (dump_w_err_ckeck(&ptr, &mem)) {
+ mem.mstr += mem.mtmp;
+ }
+ mem.mold = mem.mstr;
+ break;
+ case 'n' :
+ case 0x0d :
+ mem.msiz = 512;
+ mem.mtmp = mem.msiz;
+ if (dump_w_err_ckeck(&ptr, &mem)) {
+ mem.mstr += 512;
+ }
+ mem.mold = mem.mstr;
+ break;
+ case 'b' : // Back to more
+ if (mem.mold == 0) {
+ ;
+ } else {
+ mem.mold -= 512;
+ }
+ case '0' : // start RAM page0 top
+ if (mem.mmode) {
+ set_page(ptr, 0);
+ } else {
+ if (*ptr == 'l') {
+ set_page(ptr, 5);
+ } else {
+ set_page(ptr, 0);
+ }
+ }
+ break;
+ case '1' : // start RAM page1 top
+ if (mem.mmode) {
+ set_page(ptr, 1);
+ } else {
+ if (*ptr == 'l') {
+ set_page(ptr, 6);
+ } else {
+ set_page(ptr, 1);
+ }
+ }
+ break;
+ case '2' : // start RAM page2 top
+ if (mem.mmode) {
+ set_page(ptr, 2);
+ } else {
+ if (*ptr == 'l') {
+ set_page(ptr, 7);
+ } else {
+ set_page(ptr, 2);
+ }
+ }
+ break;
+ case '3' : // start RAM page3 top
+ if (mem.mmode) {
+ set_page(ptr, 3);
+ } else {
+ if (*ptr == 'l') {
+ set_page(ptr, 8);
+ } else {
+ set_page(ptr, 3);
+ }
+ }
+ break;
+ case '4' : // start RAM page top
+ if (mem.mmode) {
+ set_page(ptr, 4);
+ } else {
+ if (*ptr == 'l') {
+ set_page(ptr, 9);
+ } else {
+ set_page(ptr, 4);
+ }
+ }
+ break;
+ case 'm' : // Change RAM address mode (Base or Mirror)
+ PRINTF("Currenr ");
+ if (mem.mmode == 0) {
+ PRINTF("BASE mode");
+ } else {
+ PRINTF("Mirror mode");
+ }
+ put_rn();
+ PRINTF("Do you want to change the mode? y or n");
+ put_rn();
+ if (GETC() == 'y') {
+ if (mem.mmode == 0) {
+ mem.mmode = 1;
+ } else {
+ mem.mmode = 0;
+ }
+ PRINTF("Set ");
+ if (mem.mmode == 0) {
+ PRINTF("BASE mode");
+ } else {
+ PRINTF("Mirror mode");
+ }
+ put_rn();
+ }
+ if (mem.mmode) {
+ mem.mstr = mem_range1[0][0];
+ } else {
+ mem.mstr = mem_range0[0][0]; ;
+ }
+ break;
+ case 's' :
+ PRINTF("Memory Configuration");
+ put_rn();
+ if (mem.mmode) {
+ PRINTF("%s0x%08lx to 0x%08lx ", rmsg0, mem_range1[0][0], mem_range1[0][1]);
+ put_rn();
+ PRINTF("%s0x%08lx to 0x%08lx ", rmsg1, mem_range1[1][0], mem_range1[1][1]);
+ put_rn();
+ PRINTF("%s0x%08lx to 0x%08lx ", rmsg2, mem_range1[2][0], mem_range1[2][1]);
+ put_rn();
+ PRINTF("%s0x%08lx to 0x%08lx ", rmsg3, mem_range1[3][0], mem_range1[3][1]);
+ put_rn();
+ PRINTF("%s0x%08lx to 0x%08lx ", rmsg4, mem_range1[4][0], mem_range1[4][1]);
+ } else {
+ PRINTF("%s0x%08lx to 0x%08lx ", rmsg_0, mem_range0[0][0], mem_range0[0][1]);
+ put_rn();
+ PRINTF("%s0x%08lx to 0x%08lx ", rmsg_1, mem_range0[5][0], mem_range0[5][1]);
+ put_rn();
+ PRINTF("%s0x%08lx to 0x%08lx ", rmsg_2, mem_range0[1][0], mem_range0[1][1]);
+ put_rn();
+ PRINTF("%s0x%08lx to 0x%08lx ", rmsg_3, mem_range0[6][0], mem_range0[6][1]);
+ put_rn();
+ PRINTF("%s0x%08lx to 0x%08lx ", rmsg_4, mem_range0[2][0], mem_range0[2][1]);
+ put_rn();
+ PRINTF("%s0x%08lx to 0x%08lx ", rmsg_5, mem_range0[7][0], mem_range0[7][1]);
+ put_rn();
+ PRINTF("%s0x%08lx to 0x%08lx ", rmsg_6, mem_range0[3][0], mem_range0[3][1]);
+ put_rn();
+ PRINTF("%s0x%08lx to 0x%08lx ", rmsg_7, mem_range0[8][0], mem_range0[8][1]);
+ put_rn();
+ PRINTF("%s0x%08lx to 0x%08lx ", rmsg_8, mem_range0[4][0], mem_range0[4][1]);
+ put_rn();
+ PRINTF("%s0x%08lx to 0x%08lx ", rmsg_9, mem_range0[9][0], mem_range0[9][1]);
+ }
+ put_rn();
+ break;
+ case 'q' : // quit
+ mem.mflg = 0xff;
+ break;
+ case '?' :
+ PRINTF("d <address> [<count>] - Dump memory");
+ put_rn();
+ PRINTF("s - Show RAM structure ");
+ put_rn();
+ PRINTF("0u,0l,1u,1l,... or 0,1,2,3,4 - Dump RAM data");
+ put_rn();
+ PRINTF("b - Dump memory / before 512bytes");
+ put_rn();
+ PRINTF("c - Dump memory until hit any key");
+ put_rn();
+ PRINTF("m - Change RAM address mode (Base or Mirror)");
+ put_rn();
+ PRINTF("<RET> or n - Dump memory / next 512bytes");
+ put_rn();
+ PRINTF("q - return");
+ put_rn();
+ break;
+ default:
+ PUTC('?');
+ put_rn();
+ }
+#if 0
+ PRINTF("mstr:0x%08x, msiz:0x%08x, mtmp:0x%08x\r\n",
+ mem.mstr, mem.msiz, mem.mtmp);
+ PRINTF("mold:0x%08x, mflg:%d, mbhw:%d, mmode:%d\r\n",
+ mem.mold, mem.mflg, mem.mbhw, mem.mmode);
+#endif
+ }
+}
+
+void system_requency(void)
+{
+ uint16_t reg0, reg1;
+
+ // Hardware configration (mbed GR-PEACH)= P0_2/MD_CLK -> LOW
+ reg0 = CPG.FRQCR;
+ reg1 = CPG.FRQCR2;
+ PRINTF("FRQCR:0x%04x", reg0);
+ put_rn();
+ PRINTF("FRQCR:0x%04x", reg1);
+ put_rn();
+ if (reg1 == 1) {
+ PRINTF("EXternal Xtal:%10.6f [MHz]", EXTERNAL_XTAL);
+ put_rn();
+ PRINTF("PLL Clock :%10.6f [MHz]", EXTERNAL_XTAL * 30);
+ put_rn();
+ reg0 &= 0x3ff;
+ if (reg0 == 0x035) {
+ PRINTF("CPU Clock I:%10.6f [MHz]", EXTERNAL_XTAL * 30);
+ } else if (reg0 == 0x135) {
+ PRINTF("CPU Clock I:%10.6f [MHz]", EXTERNAL_XTAL * 20);
+ } else {
+ PRINTF(fmsg0);
+ return;
+ }
+ put_rn();
+ PRINTF("Graphic G:%10.6f [MHz]", EXTERNAL_XTAL * 20);
+ } else if (reg1 == 3) {
+ if (reg0 == 0x035) {
+ PRINTF("CPU Clock I:%10.6f [MHz]", EXTERNAL_XTAL * 30);
+ } else if (reg0 == 0x135) {
+ PRINTF("CPU Clock I:%10.6f [MHz]", EXTERNAL_XTAL * 20);
+ } else if (reg0 == 0x135) {
+ PRINTF("CPU Clock I:%10.6f [MHz]", EXTERNAL_XTAL * 10);
+ } else {
+ PRINTF(fmsg0);
+ return;
+ }
+ put_rn();
+ PRINTF("Graphic G:%10.6f [MHz]", EXTERNAL_XTAL * 10);
+ } else {
+ PRINTF(fmsg0);
+ return;
+ }
+ put_rn();
+ PRINTF("Bus Clock B:%10.6f [MHz]", EXTERNAL_XTAL * 10);
+ put_rn();
+ PRINTF("Peripheral P1:%10.6f [MHz]", EXTERNAL_XTAL * 5);
+ put_rn();
+ PRINTF("Peripheral P0:%10.6f [MHz]", EXTERNAL_XTAL * 5 / 2);
+ put_rn();
+}
+
+//-------------------------------------------------------------------------------------------------
+// Monitor Main Program
+//-------------------------------------------------------------------------------------------------
+// Help Massage
+void mon_msg_hlp ( void )
+{
+ PRINTF(mon_msg);
+ put_rn();
+ PRINTF(msg0);
+ put_rn();
+ PRINTF(msg1);
+ put_rn();
+ PRINTF(msg6);
+ put_rn();
+ PRINTF(msg7);
+ put_rn();
+ PRINTF(msg2);
+ put_rn();
+ PRINTF(msg3);
+ put_rn();
+ PRINTF(msg4);
+ put_rn();
+ PRINTF(msg5);
+ put_rn();
+}
+
+int mon_mem(void)
+{
+ char *ptr;
+
+ put_r();
+ PRINTF("%s [Help:'?' key]", mon_msg);
+ put_rn();
+ for (;;) {
+ put_r();
+ PUTC('>');
+ ptr = linebuf;
+ get_line(ptr, buf_size);
+ put_r();
+ switch (*ptr++) {
+ //-----------------------------------------------------------------------------------------
+ // Memory
+ //-----------------------------------------------------------------------------------------
+ case 'm' :
+ mem_inf(ptr);
+ break;
+ //-----------------------------------------------------------------------------------------
+ // Register
+ //-----------------------------------------------------------------------------------------
+ case 'r' :
+ put_r();
+ PRINTF(mrmsg0);
+ put_rn();
+ quitflag = 0;
+ for (; quitflag != 0xff;) {
+ PRINTF("r>");
+ ptr = linebuf;
+ get_line(ptr, buf_size);
+ put_r();
+ switch(*ptr++) {
+ case 'u' :
+#if USE_UART
+
+#else
+ not_select();
+#endif // USE_UART
+ break;
+ case 'i' :
+#if USE_I2C
+
+#else
+ not_select();
+#endif // USE_I2C
+ break;
+ case 's' :
+#if USE_SPI
+
+#else
+ not_select();
+#endif // USE_SPI
+ break;
+ case 't' : //
+ not_yet_impliment();
+ break;
+ case 'a' : //
+ not_yet_impliment();
+ break;
+ case 'd' : //
+ not_yet_impliment();
+ break;
+ case 'w' : //
+ not_yet_impliment();
+ break;
+ case 'l' : //
+ not_yet_impliment();
+ break;
+ case 'c' : //
+ not_yet_impliment();
+ break;
+ case 'x' : //
+ not_yet_impliment();
+ break;
+ case 'y' : //
+ not_yet_impliment();
+ break;
+ case '?' :
+ PRINTF("u - USART");
+ put_rn();
+ PRINTF("i - I2C");
+ put_rn();
+ PRINTF("s - SPI");
+ put_rn();
+ PRINTF("t - TIMER");
+ put_rn();
+ PRINTF("a - ADC");
+ put_rn();
+ PRINTF("d - DAC");
+ put_rn();
+ PRINTF("l - LDC");
+ put_rn();
+ PRINTF("w - WWDG");
+ put_rn();
+ PRINTF("c - COMP");
+ put_rn();
+ break;
+ case 'q' : // quit
+ quitflag = 0xff;
+ break;
+ default:
+ PUTC('?');
+ put_rn();
+ }
+ }
+ PRINTF(mrmsg8);
+ put_rn();
+ break;
+ //-----------------------------------------------------------------------------------------
+ // Port
+ //-----------------------------------------------------------------------------------------
+ case 'p' :
+#if USE_PORT
+
+#else
+ not_select();
+#endif // USE_PORT
+ break;
+ //-----------------------------------------------------------------------------------------
+ // System
+ //-----------------------------------------------------------------------------------------
+ case 's' : // System related information
+ system_requency();
+ break;
+ //-----------------------------------------------------------------------------------------
+ // Help
+ //-----------------------------------------------------------------------------------------
+ case '?' :
+ mon_msg_hlp();
+ break;
+ //-----------------------------------------------------------------------------------------
+ // Return to main routine
+ //-----------------------------------------------------------------------------------------
+ case 'q' : // Quit
+ put_r();
+ PRINTF("Return to monitor");
+ put_rn();
+ return 0;
+ //-----------------------------------------------------------------------------------------
+ // Special command for DEBUG
+ //-----------------------------------------------------------------------------------------
+ case 'x' :
+#if 1
+ print_data_address();
+#else
+ not_yet_impliment();
+#endif
+ break;
+ //-----------------------------------------------------------------------------------------
+ // no support
+ //-----------------------------------------------------------------------------------------
+ default:
+ PUTC('?');
+ put_rn();
+ break;
+ }
+ }
+}
+
+#endif // defined(TARGET_RZ_A1H)
--- a/stepper.lib Sun Dec 14 09:17:01 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://developer.mbed.org/users/kenjiArai/code/stepper/#94f55ebfe2db