2010-10-19 06:14 AM
hi.
i found out that it is possiable to use the flash as eeprom but the example i found was very long and complicated is there asimple way to do that? thanks.2010-10-19 06:49 AM
i tried that code but it does not work why?
#include ''stm32F10x.h'' #define CR_PG_Reset ((uint32_t)0x00001FFE) void setsystemclock(void); void uartfunction(void); uint8_t TxBuffer[] = ''Buffer Send from USART3 to USARTz using Flags''; uint8_t TxCounter = 0, RxCounter = 0; /* EEPROM start address in Flash */ #define EEPROM_START_ADDRESS ((uint32_t)0x08010000) /* EEPROM emulation start address: after 64KByte of used Flash memory */ #define FLASH_KEY1 ((uint32_t)0x45670123) #define FLASH_KEY2 ((uint32_t)0xCDEF89AB) int main(void) { char byte_temp=0; int Address=0; setsystemclock(); //set system clock to 24Mhz RCC->APB2ENR =RCC_APB2RSTR_IOPCRST | RCC_APB2RSTR_AFIORST;//port C clock and alternative clock enable. page 79 RCC->APB1ENR =RCC_APB1ENR_USART3EN ; GPIOC->CRH=GPIO_CRH_MODE10 | GPIO_CRH_CNF10_1 | GPIO_CRH_CNF11_0 ;//PC11 in input floating mode for RX. PC10 Alternative Output TX. AFIO->MAPR=AFIO_MAPR_USART3_REMAP_0 ;//port remap as uart //PC10 TX PC11 RX USART3->CR1 =USART_CR1_RE | USART_CR1_TE; //Receiver enable, Transmitter enable, USART disable USART3->BRR=0x9C4;//9600 at 24Mhz USART3->CR1 |= USART_CR1_UE;; //Uart Enable; //flash configuration FLASH->KEYR = FLASH_KEY1; FLASH->KEYR = FLASH_KEY2; FLASH->CR |= FLASH_CR_PG; //flash programing Address=EEPROM_START_ADDRESS +1; *(__IO uint16_t*)Address = '6'; /* Wait for last operation to be completed */ while((FLASH->SR&FLASH_SR_BSY) >0); /* if the program operation is completed, disable the PG Bit */ FLASH->CR &= CR_PG_Reset; while(1) { if (((USART3->SR)&USART_SR_RXNE)>0) { byte_temp= USART3->DR; if (((USART3->SR)&USART_SR_TXE)>0) USART3->DR = (*(__IO uint16_t*)(Address - 2));; } /* while(TxCounter < 30) { USART3->DR =('5'); while(((USART3->SR)&USART_SR_TXE)==0);// Loop until USARTy DR register is empty TxCounter++; } TxCounter=0;*/ } } void setsystemclock(void) { RCC->CR |= RCC_CR_HSEON; // Wait until it's ready while ((RCC->CR & RCC_CR_HSERDY) == 0) ; // Select PREDIV1 as PLL source and sett PLL mul to 3 (set bit 0) // for 8*3 = 24 MHz RCC->CFGR |= RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL_0; // Start PLL RCC->CR |= RCC_CR_PLLON; // Wait until it's ready while ((RCC->CR & RCC_CR_PLLRDY) == 0) ; // Select PLL as system clock RCC->CFGR |= RCC_CFGR_SW_PLL; // Here we can check if PLL is used, and maybe disable HSI // Disable HSI RCC->CR &= ~RCC_CR_HSION; RCC->CFGR|=RCC_CFGR_MCO_2; //sys clock output } thanks,2010-10-19 07:32 AM
Hi,
Have you already referred tothe AN2594 ''EEPROM emulation in in STM32F10x microcontrollers ''
? Hope this can help you M3allem2010-10-19 07:36 AM
AN2594 and tryied to work accordanly but it is very complicatied with many many function one leading to the other .
i am trying to understand the simple way to write one byte to the flash and read it when nessery thats it. thnaks.2010-10-19 07:50 AM
2010-10-19 08:17 AM
i tried that code but it does not work why?
Address=EEPROM_START_ADDRESS +1;
*(__IO uint16_t*)Address = '6'; You can't write WORDs to ODD addresses
2010-10-19 08:32 AM
i changed the
Address=EEPROM_START_ADDRESS +2; *(__IO uint16_t*)Address = 5; but i still get to the void HardFault_Handler(void) routine. i know it not simple but i still dont know how to do it without endless routines. thanks.2010-10-19 12:21 PM
This seem relatively serviceable using Keil, and writes to the flash, although I don't have a USART3 serial port. I've fixed the PLL code as I've previously suggested. If you want to locate faulting instructions, step through the code, you don't have much of it. Also you will need to work on erasing.
#include ''stm32F10x.h'' #define CR_PG_Reset ((uint32_t)0x00001FFE) void setsystemclock(void); /* EEPROM start address in Flash */ #define EEPROM_START_ADDRESS ((uint32_t)0x08010000) /* EEPROM emulation start address: after 64KByte of used Flash memory */ #define FLASH_KEY1 ((uint32_t)0x45670123) #define FLASH_KEY2 ((uint32_t)0xCDEF89AB) int main(void) { char byte_temp=0; int Address=0; setsystemclock(); //set system clock to 24Mhz RCC->APB2ENR |= RCC_APB2RSTR_IOPCRST | RCC_APB2RSTR_AFIORST;//port C clock and alternative clock enable. page 79 RCC->APB1ENR |= RCC_APB1ENR_USART3EN ; GPIOC->CRH=GPIO_CRH_MODE10 | GPIO_CRH_CNF10_1 | GPIO_CRH_CNF11_0 ;//PC11 in input floating mode for RX. PC10 Alternative Output TX. AFIO->MAPR=AFIO_MAPR_USART3_REMAP_0 ;//port remap as uart //PC10 TX PC11 RX USART3->CR1 =USART_CR1_RE | USART_CR1_TE; //Receiver enable, Transmitter enable, USART disable USART3->BRR = 0x9C4;//9600 at 24Mhz USART3->CR1 |= USART_CR1_UE; //Uart Enable; //flash configuration FLASH->KEYR = FLASH_KEY1; FLASH->KEYR = FLASH_KEY2; FLASH->CR |= FLASH_CR_PG; //flash programing Address = EEPROM_START_ADDRESS + 2; *(__IO uint16_t*)Address = '6'; /* Wait for last operation to be completed */ while((FLASH->SR&FLASH_SR_BSY) >0); /* if the program operation is completed, disable the PG Bit */ FLASH->CR &= CR_PG_Reset; while(1) { if (((USART3->SR) & USART_SR_RXNE)>0) { byte_temp += USART3->DR; if (((USART3->SR) & USART_SR_TXE)>0) USART3->DR = (*(__IO uint16_t*)Address); } } } void setsystemclock(void) { RCC->CR |= RCC_CR_HSEON; // Wait until it's ready while ((RCC->CR & RCC_CR_HSERDY) == 0) ; // Select PREDIV1 as PLL source and sett PLL mul to 3 (set bit 0) // for 8*3 = 24 MHz RCC->CFGR |= RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL_0; // Start PLL RCC->CR |= RCC_CR_PLLON; // Wait until it's ready while ((RCC->CR & RCC_CR_PLLRDY) == 0) ; // Select PLL as system clock RCC->CFGR = (RCC->CFGR & ~RCC_CFGR_SW) | RCC_CFGR_SW_PLL; // Wait until PLL is used as system clock source while ((RCC->CFGR & RCC_CFGR_SWS) != 0x08) ; // Here we can check if PLL is used, and maybe disable HSI // Disable HSI RCC->CR &= ~RCC_CR_HSION; RCC->CFGR|=RCC_CFGR_MCO_2; //sys clock output }2010-10-19 11:05 PM
2010-10-19 11:28 PM