This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"errors" | |
"fmt" | |
"net" | |
"regexp" | |
"strings" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "testing" | |
func TestPrivateIP(t *testing.T) { | |
isPrivate, _ := PrivateIP("192.168.1.6") | |
if !isPrivate { | |
t.Error(isPrivate) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct __FILE{int handle;}; | |
FILE __stdin = {0}; | |
FILE __stdout = {1}; | |
FILE __stderr = {2}; | |
int fgetc(FILE *f){ | |
int c; | |
c = USART2_Read(); | |
if (c == '\r') { | |
USART2_Write(c); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stm32f4xx.h" // Device header | |
#include "stdio.h" | |
void USART2_Init(void); | |
int main() { | |
int n; | |
char str[100]; | |
USART2_Init(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stm32f4xx.h" // Device header | |
int main(){ | |
//GPIO Config | |
RCC->AHB1ENR |=0x8; | |
GPIOD->MODER |= (1<<30); | |
//TIM2 Config @16Mhz | |
RCC->APB1ENR |= 0x1; //Enable TIM2 Clock Bus | |
TIM2->PSC = 1600-1; //16.000.000 dive by 1.600 = 10.000 (Prescaler Register) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stm32f4xx.h" // Device header | |
/* Toggle PA5 at 1Hz using TIM2 Compare Mode */ | |
int main(){ | |
RCC->AHB1ENR |= 0x1; //Enable AHB1 clock bus | |
GPIOA->MODER |= (2<<10); //Set PA5 to Alternate Function Mode | |
GPIOA->AFR[0] |= (1<<20); //SET pin AF1 for TIM2_CH1 | |
RCC->APB1ENR |= 0x1; //Enable TIM2 Clock Bus | |
TIM2->PSC = 1600; //16.000.000 dive by 1.600 = 10.000 (Prescaler Register) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stm32f4xx.h" | |
int period; | |
float freq; | |
int main(){ | |
int last_value = 0; | |
int current_value = 0; | |
//Configure PA5 as alternate function mode | |
RCC->AHB1ENR |= 0x1; //Enable GPIOA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void RCC_init(void){ | |
/* Configure clocks | |
* Max SYSCLK: 168 MHz | |
* Max AHB: 168 Mhz | |
* Max APB1: 42 Mhz | |
* Max APB2: 84 Mhz | |
*/ | |
// Flash settings: 5 CPU cycle wait, enable prefetch, instruction cache enable, data cache enable | |
FLASH->ACR = FLASH_ACR_LATENCY_5WS | FLASH_ACR_PRFTEN | FLASH_ACR_ICEN | FLASH_ACR_DCEN; |