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.
main.cpp
00001 #include "mbed.h" 00002 00003 //WATHDOG ENABLED IN OUR KL25Z_SystemInit.c (overloading library function SystemInit.c) 00004 // It happens in this uC after reset watchdog is enabled with timeout=1024ms (2^10*LPO=1KHz) 00005 // so mbed developers to allow a learning use of this board disable it on SystemInit.c 00006 // **BUT** SIM_COPC register can only be written once after reset and so it can not be enabled later 00007 // I think best solution is to overload SystemInit() using: void $Sub$$SystemInit (void) { 00008 // original SystemInit() does not appear in export, it must be dowloaded from: 00009 // https://developer.mbed.org/users/mbed_official/code/mbed-src/file/a11c0372f0ba/targets/cmsis/TARGET_Freescale/TARGET_KLXX/TARGET_KL25Z/system_MKL25Z4.c 00010 // you can arrive there from: 00011 // https://developer.mbed.org/handbook/mbed-SDK and https://developer.mbed.org/users/mbed_official/code/mbed-src/ 00012 // 00013 // MORE on this on: https://developer.mbed.org/users/chris/notebook/Patching-functions-and-libraries/ 00014 // and searching "ARM Compiler toolchain Using the Linker" "Using $Super$$ and $Sub$$ to patch symbol definitions" 00015 00016 // Kick (feed, reload) our watchdog timer 00017 void wdt_kick(){ 00018 SIM->SRVCOP = (uint32_t)0x55u; 00019 SIM->SRVCOP = (uint32_t)0xAAu; 00020 } 00021 00022 // That set RED LED ON, do that first to evaluate boot time of peripherals 00023 #define LIGHT 0 00024 #define DARK 1 00025 DigitalOut led_red(LED_RED, LIGHT); 00026 DigitalOut led_green(LED_GREEN, DARK); 00027 DigitalOut led_blue(LED_BLUE, DARK); 00028 00029 //Virtual serial port over USB using inboard second USB connector (USBKL25Z port) 00030 #include "USBSerial.h" 00031 //USBSerial pc; 00032 //...( vendor_id, product_id, product_release, connect_blocking ) 00033 USBSerial pc( 0x1f00, 0x2012, 0x0001, false ); 00034 //REMEMBER TO USE: class USBSerial -> connect_blocking = false (default is true) 00035 // to avoid block of program when no USB cable connected in USBKL25Z port 00036 //NOTE: USBSerial still blocks program when closing serial terminal, that is fixed by our watchdog 00037 00038 00039 int main(void) { 00040 //to evaluate boot time I set led RED ON at the beginning of our main.cpp. TODO?: do it in SystemInit? 00041 led_blue = DARK; 00042 led_green = DARK; 00043 led_red = DARK; 00044 while(1) 00045 { 00046 led_blue = LIGHT; 00047 pc.printf("I am a virtual serial port\r\n"); // THAT COULD BLOCK 00048 wdt_kick(); 00049 led_blue = DARK; 00050 wait(0.5); 00051 } 00052 }
Generated on Wed Jul 13 2022 22:59:16 by
1.7.2