uint32_t SRAM_Test(void) { uint32_t adr = 0; uint32_t error = 0; uint16_t *prnd; uint16_t *pmem; uint16_t temp; prnd = malloc(512); RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE); RNG_Cmd(ENABLE); for(adr = 0; adr < 512; adr++) { while(RNG_GetFlagStatus(RNG_FLAG_DRDY) == RESET); *(prnd++) = (uint16_t)RNG_GetRandomNumber(); } RNG_Cmd(DISABLE); RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG,DISABLE); prnd -= 512; pmem = (uint16_t*)sram_bank3; temp = *prnd; for(adr = 0; adr < 524288; adr++) { if((adr & 0x3ff) == 0x3ff) temp = *(prnd++); temp = (temp + 1024) * 5; *(pmem++) = temp; } for(int test_num = 0; test_num < 3; test_num++) { prnd -= 512; pmem = (uint16_t*)sram_bank3; temp = *prnd; for(adr = 0; adr < 524288; adr++) { if((adr & 0x3ff) == 0x3ff) temp = *(prnd++); temp = (temp + 1024) * 5; if(temp != *(pmem++)) error++; } } free(prnd); return error; }
//Main Function int main(void) { //RCC_Configurastatic(); GPIO_Configuration(); USART1_Configuration(); LCD_SetColors(0x1188, 0x0000); LCD_SetFont(&Font8x8); t_queue = xQueueCreate(1, sizeof(int)); if (!t_queue) { ReportError("Failed to create t_queue"); while(1); } t_mutex = xSemaphoreCreateMutex(); if (!t_mutex) { ReportError("Failed to create t_mutex"); while(1); } prvInit(); //LCD_DisplayStringLine(LCD_LINE_1,text); //xTaskCreate(usart_text, (char *) "Draw Graph Task", 256, // NULL, tskIDLE_PRIORITY + 2, NULL); xTaskCreate(r3d, (char *) "Draw Graph Task", 256, NULL, tskIDLE_PRIORITY + 2, NULL); RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE); RNG_Cmd(ENABLE); //Call Scheduler vTaskStartScheduler(); }
/** * @brief Inititialize the target hardware. * @param None * @retval None */ uint32_t BSP_Init (void) { /* Initialize the LEDs */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); CONSOLE_LOG((uint8_t *)"[SYSTEM] Data RAM Init : OK."); /* Initialize the LCD */ GL_LCD_Init(); CONSOLE_LOG((uint8_t *)"[SYSTEM] LCD Init : OK."); /* Initialize the TSC */ GL_TSC_Init(); CONSOLE_LOG((uint8_t *)"[SYSTEM] Touchscreen Init : OK."); /* Initialize the Joystick */ GL_JOY_Init(); CONSOLE_LOG((uint8_t *)"[SYSTEM] Joystick Init : OK."); /* Initialize the PSRAM */ SRAM_Init(); CONSOLE_LOG((uint8_t *)"[SYSTEM] SRAM Init: OK."); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_BKPSRAM, ENABLE); CONSOLE_LOG((uint8_t *)"[SYSTEM] BKPSRAM Init : OK."); SYSCFG_CompensationCellCmd(ENABLE); /* Enable RNG clock source */ RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE); /* RNG Peripheral enable */ RNG_Cmd(ENABLE); return 0; }
// initialize RNG void init_rng() { /* Enable RNG clock source */ RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE); /* RNG Peripheral enable */ RNG_Cmd(ENABLE); }
void initAll () { comm_init(); //RNG Peripheral enable RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE); RNG_Cmd(ENABLE); }
void RNG_Config(void) { /* Enable RNG clock source */ RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE); /* RNG Peripheral enable */ RNG_Cmd(ENABLE); }
int init_rng(void) { u16 retry=0; RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE); //开启 RNG 时钟 RNG_Cmd(ENABLE); //使能 RNG while(RNG_GetFlagStatus(RNG_FLAG_DRDY)==RESET&&retry<10000)//等待就绪 { retry++; delay_ms(1); } if(retry>=10000)return 1;//随机数产生器工作不正常 return 0; }
void RNG_Config(void){ //Enable RNG controller clock RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE); //activate the RNG peripheral RNG_Cmd(ENABLE); // to get a random number, need to continue steps: 3. Wait until the 32 bit Random number Generator //contains a valid random data (using polling/interrupt mode). For more details, //refer to Section 20.2.4: "Interrupt and flag management" module description. //4. Get the 32 bit Random number using RNG_GetRandomNumber() function //5. To get another 32 bit Random number, go to step 3. }
void vTaskTest( void* pvParam ) { u8 t, i; Uart_putstr( "vTaskTest start" ) ; RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG,ENABLE); RNG_Cmd(ENABLE); while( 1 ) { xQueueSend( xqh_Tpframe, (void*)NULL, 0 ) ; while(RNG_GetFlagStatus(RNG_FLAG_DRDY) == RESET); t = RNG_GetRandomNumber(); for( i = 0; i < t; i++ ) vTaskDelay( 100/portTICK_RATE_MS ) ; } }
/** * @Function u8 RNG_Init(void); * @Description Init_RNG * @Return 0:SUCESS * 1:Error */ u8 RNG_Init(void) { u16 retry=0; RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE);//开启RNG时钟,来自PLL48CLK RNG_Cmd(ENABLE); //使能RNG while(RNG_GetFlagStatus(RNG_FLAG_DRDY)==RESET&&retry<10000) //等待随机数就绪 { retry++; delay_us(100); } if(retry>=10000)return 1;//随机数产生器工作不正常 return 0; }
int main(void) { SystemInit(); ////////////////// SPI2 - SD fpu_enable(); delay_init( 168 ); SPI_SD_Init(); ////////////////// RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE); //rng RNG_Cmd(ENABLE); //switch on RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); //button InitEXTIButtonPA0();//accept InitEXTIButtonPA1();//up InitEXTIButtonPA2();//right InitEXTIButtonPA3();//down InitEXTIButtonPA4();//left RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); //timer ConfTim2(); RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //timer ConfTim3(350); //init with start_value game period SetSnakeSpeed(3); PCD8544_Init(0x38); //Initialize LCD with 0x38 software contrast //////////////////////////////////////////// DrawBitMap(SnakeBitMap); PCD8544_Refresh(); WaitForAcceptButton(); PCD8544_Clear(); MainMenu(); while (1) { } }
void rng_init(void) { // enable the clock RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE); // configure the interrupt NVIC_InitTypeDef nvic_cfg = {0}; nvic_cfg.NVIC_IRQChannel = HASH_RNG_IRQn; nvic_cfg.NVIC_IRQChannelPreemptionPriority = 0; nvic_cfg.NVIC_IRQChannelSubPriority = 0; nvic_cfg.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&nvic_cfg); // configure the RNG RNG_Cmd(ENABLE); rng_buffer = xQueueCreate(BUFFER_SIZE, sizeof(uint32_t)); }
int main(void) { char s[] = "1442936700,0,1,4,#2346W,3,#0800O#1900C#0900O#1800C"; // for str_processing test RCC_ClocksTypeDef RCC_Clocks; /* SysTick end of count event each 10ms */ RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency / 100); RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE); RNG_Cmd(ENABLE); /* Initialize the timer for dht11 */ tim_init(TIM2); /* Initialize the SRAM ****************************************************/ PSRAM_Init(); /* Initialize the LCD *****************************************************/ LCD_Init(); LCD_LOG_Init(); LCD_LOG_SetHeader((uint8_t*)" Ethernet test"); LCD_LOG_SetFooter ((uint8_t*)" localtime: "); /* Add your application code here */ /* Configure ethernet (GPIOs, clocks, MAC, DMA) */ ETH_BSP_Config(); /* Initilaize the LwIP stack */ LwIP_Init(); schedule_init(&schedule_got,schedule_string); // schedule string store in schedule_string DNS_Init(); //while(!schedule_got); // wait until string got LCD_DisplayStringLine(Line2, (uint8_t*)schedule_string); LCD_DisplayStringLine(Line3, (uint8_t*)"0"); /* Main Loop */ //process ste str form internet Str_Split(s, Init_time); // s is temp string RTC_Config(); Time_Date_Setting(Init_time->year, Init_time->mon, Init_time->day, Init_time->hour +3, Init_time->min, Init_time->sec); while (1) { uint8_t year, mon, day; uint8_t hour, min, sec; RTC_TimeTypeDef RTC_TimeStruct_main; RTC_DateTypeDef RTC_DateStruct_main; RTC_GetDate(RTC_Format_BIN, &RTC_DateStruct_main); RTC_GetTime(RTC_Format_BIN, &RTC_TimeStruct_main); year = RTC_DateStruct_main.RTC_Year; mon = RTC_DateStruct_main.RTC_Month; day = RTC_DateStruct_main.RTC_Date; hour = RTC_TimeStruct_main.RTC_Hours; min = RTC_TimeStruct_main.RTC_Minutes; sec = RTC_TimeStruct_main.RTC_Seconds; //detect whether it is time to turn on Motor and LED, then execute it. Soak(day, hour, min ); Water(day, hour, min, sec); Light(mon, day, hour, min); //detect over /* check if any packet received */ if (ETH_CheckFrameReceived()) { /* process received ethernet packet */ LwIP_Pkt_Handle(); } /* handle periodic timers for LwIP */ LwIP_Periodic_Handle(LocalTime); } }
void DeInitializeRandom(void) { RNG_Cmd(DISABLE); RNG_DeInit(); RNGInitialized = 0; }
void InitializeRandom(void) { RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE); RNG_Cmd(ENABLE); RNG_ITConfig(DISABLE); RNGInitialized = 1; }
void rng_enable(void) { RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE); RNG_Cmd(ENABLE); }
void rng_disable(void) { RNG_Cmd(DISABLE); RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, DISABLE); }
int main(void) { // TODO disable JTAG // update the SystemCoreClock variable SystemCoreClockUpdate(); // set interrupt priority config to use all 4 bits for pre-empting NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4); // enable the CCM RAM and the GPIO's RCC->AHB1ENR |= RCC_AHB1ENR_CCMDATARAMEN | RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOBEN | RCC_AHB1ENR_GPIOCEN | RCC_AHB1ENR_GPIODEN; #if MICROPY_HW_HAS_SDCARD { // configure SDIO pins to be high to start with (apparently makes it more robust) // FIXME this is not making them high, it just makes them outputs... GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOC, &GPIO_InitStructure); // Configure PD.02 CMD line GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_Init(GPIOD, &GPIO_InitStructure); } #endif #if defined(NETDUINO_PLUS_2) { GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; #if MICROPY_HW_HAS_SDCARD // Turn on the power enable for the sdcard (PB1) GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_WriteBit(GPIOB, GPIO_Pin_1, Bit_SET); #endif // Turn on the power for the 5V on the expansion header (PB2) GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_WriteBit(GPIOB, GPIO_Pin_2, Bit_SET); } #endif // basic sub-system init sys_tick_init(); pendsv_init(); led_init(); #if MICROPY_HW_ENABLE_RTC rtc_init(); #endif // turn on LED to indicate bootup led_state(PYB_LED_G1, 1); // more sub-system init #if MICROPY_HW_HAS_SDCARD sdcard_init(); #endif storage_init(); // uncomment these 2 lines if you want REPL on USART_6 (or another usart) as well as on USB VCP //pyb_usart_global_debug = PYB_USART_YA; //usart_init(pyb_usart_global_debug, 115200); int first_soft_reset = true; soft_reset: // GC init gc_init(&_heap_start, &_heap_end); // Micro Python init qstr_init(); mp_init(); mp_obj_list_init(mp_sys_path, 0); mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_0_colon__slash_)); mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_0_colon__slash_lib)); mp_obj_list_init(mp_sys_argv, 0); exti_init(); #if MICROPY_HW_HAS_SWITCH switch_init(); #endif #if MICROPY_HW_HAS_LCD // LCD init (just creates class, init hardware by calling LCD()) lcd_init(); #endif #if MICROPY_HW_ENABLE_SERVO // servo servo_init(); #endif #if MICROPY_HW_ENABLE_TIMER // timer timer_init(); #endif #if MICROPY_HW_ENABLE_RNG // RNG RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE); RNG_Cmd(ENABLE); #endif pin_map_init(); // add some functions to the builtin Python namespace mp_store_name(MP_QSTR_help, mp_make_function_n(0, pyb_help)); mp_store_name(MP_QSTR_open, mp_make_function_n(2, pyb_io_open)); // load the pyb module mp_module_register(MP_QSTR_pyb, (mp_obj_t)&pyb_module); // check if user switch held (initiates reset of filesystem) bool reset_filesystem = false; #if MICROPY_HW_HAS_SWITCH if (switch_get()) { reset_filesystem = true; for (int i = 0; i < 50; i++) { if (!switch_get()) { reset_filesystem = false; break; } sys_tick_delay_ms(10); } } #endif // local filesystem init { // try to mount the flash FRESULT res = f_mount(&fatfs0, "0:", 1); if (!reset_filesystem && res == FR_OK) { // mount sucessful } else if (reset_filesystem || res == FR_NO_FILESYSTEM) { // no filesystem, so create a fresh one // TODO doesn't seem to work correctly when reset_filesystem is true... // LED on to indicate creation of LFS led_state(PYB_LED_R2, 1); uint32_t stc = sys_tick_counter; res = f_mkfs("0:", 0, 0); if (res == FR_OK) { // success creating fresh LFS } else { __fatal_error("could not create LFS"); } // create src directory res = f_mkdir("0:/src"); // ignore result from mkdir // create empty main.py FIL fp; f_open(&fp, "0:/src/main.py", FA_WRITE | FA_CREATE_ALWAYS); UINT n; f_write(&fp, fresh_main_py, sizeof(fresh_main_py) - 1 /* don't count null terminator */, &n); // TODO check we could write n bytes f_close(&fp); // keep LED on for at least 200ms sys_tick_wait_at_least(stc, 200); led_state(PYB_LED_R2, 0); } else { __fatal_error("could not access LFS"); } } // make sure we have a /boot.py { FILINFO fno; FRESULT res = f_stat("0:/boot.py", &fno); if (res == FR_OK) { if (fno.fattrib & AM_DIR) { // exists as a directory // TODO handle this case // see http://elm-chan.org/fsw/ff/img/app2.c for a "rm -rf" implementation } else { // exists as a file, good! } } else { // doesn't exist, create fresh file // LED on to indicate creation of boot.py led_state(PYB_LED_R2, 1); uint32_t stc = sys_tick_counter; FIL fp; f_open(&fp, "0:/boot.py", FA_WRITE | FA_CREATE_ALWAYS); UINT n; f_write(&fp, fresh_boot_py, sizeof(fresh_boot_py) - 1 /* don't count null terminator */, &n); // TODO check we could write n bytes f_close(&fp); // keep LED on for at least 200ms sys_tick_wait_at_least(stc, 200); led_state(PYB_LED_R2, 0); } } // run /boot.py if (!pyexec_file("0:/boot.py")) { flash_error(4); } if (first_soft_reset) { #if MICROPY_HW_HAS_MMA7660 // MMA accel: init and reset address to zero accel_init(); #endif } // turn boot-up LED off led_state(PYB_LED_G1, 0); #if MICROPY_HW_HAS_SDCARD // if an SD card is present then mount it on 1:/ if (sdcard_is_present()) { FRESULT res = f_mount(&fatfs1, "1:", 1); if (res != FR_OK) { printf("[SD] could not mount SD card\n"); } else { if (first_soft_reset) { // use SD card as medium for the USB MSD usbd_storage_select_medium(USBD_STORAGE_MEDIUM_SDCARD); } } } #endif #ifdef USE_HOST_MODE // USB host pyb_usb_host_init(); #elif defined(USE_DEVICE_MODE) // USB device pyb_usb_dev_init(PYB_USB_DEV_VCP_MSC); #endif // run main script { vstr_t *vstr = vstr_new(); vstr_add_str(vstr, "0:/"); if (pyb_config_source_dir == MP_OBJ_NULL) { vstr_add_str(vstr, "src"); } else { vstr_add_str(vstr, mp_obj_str_get_str(pyb_config_source_dir)); } vstr_add_char(vstr, '/'); if (pyb_config_main == MP_OBJ_NULL) { vstr_add_str(vstr, "main.py"); } else { vstr_add_str(vstr, mp_obj_str_get_str(pyb_config_main)); } if (!pyexec_file(vstr_str(vstr))) { flash_error(3); } vstr_free(vstr); } #if MICROPY_HW_HAS_MMA7660 // HID example if (0) { uint8_t data[4]; data[0] = 0; data[1] = 1; data[2] = -2; data[3] = 0; for (;;) { #if MICROPY_HW_HAS_SWITCH if (switch_get()) { data[0] = 0x01; // 0x04 is middle, 0x02 is right } else { data[0] = 0x00; } #else data[0] = 0x00; #endif accel_start(0x4c /* ACCEL_ADDR */, 1); accel_send_byte(0); accel_restart(0x4c /* ACCEL_ADDR */, 0); for (int i = 0; i <= 1; i++) { int v = accel_read_ack() & 0x3f; if (v & 0x20) { v |= ~0x1f; } data[1 + i] = v; } accel_read_nack(); usb_hid_send_report(data); sys_tick_delay_ms(15); } } #endif #if MICROPY_HW_HAS_WLAN // wifi pyb_wlan_init(); pyb_wlan_start(); #endif pyexec_repl(); printf("PYB: sync filesystems\n"); storage_flush(); printf("PYB: soft reboot\n"); first_soft_reset = false; goto soft_reset; }