test_spi0_flash.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "platform.h"
  2. //void sm_peripheral_setup (void){
  3. //}
  4. //void _HWradio_Go_To_Idle_State_Patch (void){
  5. //}
  6. uint8_t __attribute__((aligned(4))) Wbuff[FLASH_PAGE_SIZE+4];
  7. uint8_t __attribute__((aligned(4))) Rbuff[FLASH_PAGE_SIZE+4];
  8. int main(void)
  9. {
  10. uint16_t i;
  11. Init_spi_master(0, SPIM_CLK_16MHZ);
  12. spi_flash_Release_powerdown();
  13. /****测试flash任意长度任意位置的读写****/
  14. uint8_t testWrite[62]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N',
  15. 'O','P','Q','R','S','T','U','V','W','X','Y','Z',
  16. 'a','b','c','d','e','f','g','h','i','j','k','l','m','n',
  17. 'o','p','q','r','s','t','u','v','w','x','y','z',
  18. '0','1','2','3','4','5','6','7','8','9'};
  19. uint8_t testRead[62]="";
  20. printf("\n############################\n");
  21. spi_flash_write(127*1024,testWrite,62); //最大读写4096个字节
  22. spi_flash_Read(127*1024,testRead,62);
  23. for(i=0; i<62; i++) {
  24. printf(" %c ", testRead[i]);
  25. }
  26. /****读独立的ID序列 该指令可以读取一个芯片已经固化的只读的128位ID****/
  27. printf("\n-----***----\n");
  28. uint8_t ID_buf[16]={0};
  29. spi_flash_Read_128bitsID(ID_buf);
  30. for(i=0; i<16; i++) {
  31. printf(" %#x ", ID_buf[i]);
  32. }
  33. printf("\n-----***----\n");
  34. spi_flash_Enter_powerdown();
  35. while(1);
  36. }