Modification of mbed-src library only for STM32F030F4, very cheap microcontroller in 20-Pin TSSOP package, with 16Kbytes of Flash and 4Kbytes of Ram. **Target for online compilator must be Nucleo 32F030R8.**
Dependents: STM32F031_blink_LED_2
SerialBase.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #include "SerialBase.h" 00017 #include "wait_api.h" 00018 00019 // for 030F4 flow control not implemented (N.S.) 00020 #undef DEVICE_SERIAL_FC 00021 00022 #if DEVICE_SERIAL 00023 00024 namespace mbed { 00025 00026 SerialBase::SerialBase(PinName tx, PinName rx) : _serial(), _baud(9600) { 00027 serial_init(&_serial, tx, rx); 00028 serial_irq_handler(&_serial, SerialBase::_irq_handler, (uint32_t)this); 00029 } 00030 00031 void SerialBase::baud(int baudrate) { 00032 serial_baud(&_serial, baudrate); 00033 _baud = baudrate; 00034 } 00035 00036 void SerialBase::format(int bits, Parity parity, int stop_bits) { 00037 serial_format(&_serial, bits, (SerialParity)parity, stop_bits); 00038 } 00039 00040 int SerialBase::readable() { 00041 return serial_readable(&_serial); 00042 } 00043 00044 00045 int SerialBase::writeable() { 00046 return serial_writable(&_serial); 00047 } 00048 00049 void SerialBase::attach(void (*fptr)(void), IrqType type) { 00050 if (fptr) { 00051 _irq[type].attach(fptr); 00052 serial_irq_set(&_serial, (SerialIrq)type, 1); 00053 } else { 00054 serial_irq_set(&_serial, (SerialIrq)type, 0); 00055 } 00056 } 00057 00058 void SerialBase::_irq_handler(uint32_t id, SerialIrq irq_type) { 00059 SerialBase *handler = (SerialBase*)id; 00060 handler->_irq[irq_type].call(); 00061 } 00062 00063 int SerialBase::_base_getc() { 00064 return serial_getc(&_serial); 00065 } 00066 00067 int SerialBase::_base_putc(int c) { 00068 serial_putc(&_serial, c); 00069 return c; 00070 } 00071 00072 void SerialBase::send_break() { 00073 // Wait for 1.5 frames before clearing the break condition 00074 // This will have different effects on our platforms, but should 00075 // ensure that we keep the break active for at least one frame. 00076 // We consider a full frame (1 start bit + 8 data bits bits + 00077 // 1 parity bit + 2 stop bits = 12 bits) for computation. 00078 // One bit time (in us) = 1000000/_baud 00079 // Twelve bits: 12000000/baud delay 00080 // 1.5 frames: 18000000/baud delay 00081 serial_break_set(&_serial); 00082 wait_us(18000000/_baud); 00083 serial_break_clear(&_serial); 00084 } 00085 00086 #if DEVICE_SERIAL_FC 00087 void SerialBase::set_flow_control(Flow type, PinName flow1, PinName flow2) { 00088 FlowControl flow_type = (FlowControl)type; 00089 switch(type) { 00090 case RTS: 00091 serial_set_flow_control(&_serial, flow_type, flow1, NC); 00092 break; 00093 00094 case CTS: 00095 serial_set_flow_control(&_serial, flow_type, NC, flow1); 00096 break; 00097 00098 case RTSCTS: 00099 case Disabled: 00100 serial_set_flow_control(&_serial, flow_type, flow1, flow2); 00101 break; 00102 00103 default: 00104 break; 00105 } 00106 } 00107 #endif 00108 00109 } // namespace mbed 00110 00111 #endif
Generated on Tue Jul 12 2022 16:41:57 by 1.7.2